diff --git a/NixSupport/nixosModules/services/loadSchema.nix b/NixSupport/nixosModules/services/loadSchema.nix new file mode 100644 index 000000000..eda65d7ee --- /dev/null +++ b/NixSupport/nixosModules/services/loadSchema.nix @@ -0,0 +1,18 @@ +{ self, config, pkgs, ihp, ... }: +let cfg = config.services.ihp; +in +{ + systemd.services.loadSchema = { + serviceConfig = { + Type = "oneshot"; + }; + script = '' + DB_URL=''${DATABASE_URL:-''${DEFAULT_DATABASE_URL}} + psql "$DB_URL" < ${self.packages.x86_64-linux.ihp-schema}/IHPSchema.sql + psql "$DB_URL" < ${self.packages.x86_64-linux.schema}/Schema.sql + ''; + environment = { + DEFAULT_DATABASE_URL = cfg.databaseUrl; + }; + }; +} \ No newline at end of file diff --git a/flake-module.nix b/flake-module.nix index 38062ef25..338894378 100644 --- a/flake-module.nix +++ b/flake-module.nix @@ -158,6 +158,17 @@ ihpFlake: cp ${ihp}/lib/IHP/IHPSchema.sql $out/ ''; }; + + + schema = pkgs.stdenv.mkDerivation { + name = "schema"; + src = cfg.projectPath; + phases = [ "unpackPhase" "installPhase" ]; + installPhase = '' + mkdir $out + cp Application/Schema.sql $out/ + ''; + }; }; devenv.shells.default = lib.mkIf cfg.enable { diff --git a/flake.nix b/flake.nix index 6a1a3a0e0..bed7dd964 100644 --- a/flake.nix +++ b/flake.nix @@ -46,6 +46,7 @@ services_app = ./NixSupport/nixosModules/services/app.nix; services_worker = ./NixSupport/nixosModules/services/worker.nix; services_migrate = ./NixSupport/nixosModules/services/migrate.nix; + services_loadSchema = ./NixSupport/nixosModules/services/loadSchema.nix; options = ./NixSupport/nixosModules/options.nix; binaryCache = ./NixSupport/nixosModules/binaryCache.nix; };