diff --git a/PostgresDB/default.nix b/PostgresDB/default.nix new file mode 100644 index 0000000..b7678a0 --- /dev/null +++ b/PostgresDB/default.nix @@ -0,0 +1,26 @@ +{ stdenv, pkgs }: +{ postgresUsername +, postgresPassword +, postgresDatabase +}: + +# From https://github.com/svanderburg/dysnomia/blob/master/dysnomia-modules/postgresql-database.in +# and https://github.com/svanderburg/dysnomia/blob/master/tests/deployment/postgresql-database.nix +# +# On activation, an initial dump can be restored. If the mutable component +# contains a sub folder named postgresql-databases/, then the dump files stored +# inside get imported. + +stdenv.mkDerivation { + name = postgresDatabase; + + src = pkgs.writeTextDir "${postgresDatabase}.sql" '' + CREATE USER "${postgresUsername}" WITH PASSWORD '${postgresPassword}'; + GRANT ALL PRIVILEGES ON DATABASE "${postgresUsername}" TO "${postgresDatabase}"; + ''; + + buildCommand = '' + mkdir -p $out/postgresql-databases + cp $src/*.sql $out/postgresql-databases + ''; +} diff --git a/all-packages.nix b/all-packages.nix new file mode 100644 index 0000000..6715e83 --- /dev/null +++ b/all-packages.nix @@ -0,0 +1,14 @@ +{ distribution ? null +, services ? null +, system ? builtins.currentSystem +, pkgs ? import { inherit system; } +}: + +let + callPackage = pkgs.lib.callPackageWith (pkgs // self); + + self = { + PostgresDB = callPackage ./PostgresDB {}; + }; +in +self