From 8230336cb5e232926f6360ab6672c4dc9363ff66 Mon Sep 17 00:00:00 2001 From: ibizaman Date: Sat, 14 Jan 2023 23:36:16 -0800 Subject: [PATCH] merge files for postgresdb --- all-packages.nix | 3 +-- postgresdb/default.nix | 44 +++++++++++++++++++++++++--------------- postgresdb/mkdefault.nix | 24 ---------------------- 3 files changed, 29 insertions(+), 42 deletions(-) delete mode 100644 postgresdb/mkdefault.nix diff --git a/all-packages.nix b/all-packages.nix index 1525398..9d11476 100644 --- a/all-packages.nix +++ b/all-packages.nix @@ -9,8 +9,7 @@ let callPackage = pkgs.lib.callPackageWith (pkgs // customPkgs); customPkgs = rec { - PostgresDB = callPackage ./postgresdb {}; - mkPostgresDB = callPackage ./postgresdb/mkdefault.nix {inherit PostgresDB;}; + mkPostgresDB = callPackage ./postgresdb {}; mkHaproxyService = callPackage ./haproxy/unit.nix {inherit utils;}; diff --git a/postgresdb/default.nix b/postgresdb/default.nix index 2f1f9d3..dabce49 100644 --- a/postgresdb/default.nix +++ b/postgresdb/default.nix @@ -2,15 +2,19 @@ , pkgs , lib }: -{ postgresDatabase -, postgresUsername -, postgresPassword ? null -, postgresPasswordFile ? null +{ name + +, database +, username +, password ? null +, passwordFile ? null + +, dependsOn ? {} }: assert lib.assertMsg ( - (postgresPassword == null && postgresPasswordFile != null) - || (postgresPassword != null && postgresPasswordFile == null) + (password == null && passwordFile != null) + || (password != null && passwordFile == null) ) "set either postgresPassword or postgresPasswordFile"; # From https://github.com/svanderburg/dysnomia/blob/master/dysnomia-modules/postgresql-database.in @@ -21,16 +25,24 @@ assert lib.assertMsg ( # inside get imported. # TODO: https://stackoverflow.com/a/69480184/1013628 -stdenv.mkDerivation { - name = postgresDatabase; +{ + inherit name; + inherit database username password passwordFile; - src = pkgs.writeTextDir "${postgresDatabase}.sql" '' - CREATE USER "${postgresUsername}" WITH PASSWORD '${postgresPassword}'; - GRANT ALL PRIVILEGES ON DATABASE "${postgresUsername}" TO "${postgresDatabase}"; - ''; + pkg = stdenv.mkDerivation { + name = database; - buildCommand = '' - mkdir -p $out/postgresql-databases - cp $src/*.sql $out/postgresql-databases - ''; + src = pkgs.writeTextDir "${database}.sql" '' + CREATE USER "${username}" WITH PASSWORD '${password}'; + GRANT ALL PRIVILEGES ON DATABASE "${username}" TO "${database}"; + ''; + + buildCommand = '' + mkdir -p $out/postgresql-databases + cp $src/*.sql $out/postgresql-databases + ''; + }; + + inherit dependsOn; + type = "postgresql-database"; } diff --git a/postgresdb/mkdefault.nix b/postgresdb/mkdefault.nix deleted file mode 100644 index e2d7a08..0000000 --- a/postgresdb/mkdefault.nix +++ /dev/null @@ -1,24 +0,0 @@ -{ PostgresDB -}: -{ name -, database -, username -, password ? null -, passwordFile ? null -, dependsOn ? {} -}: - -{ - inherit name; - inherit database username password passwordFile; - - pkg = PostgresDB { - postgresDatabase = database; - postgresUsername = username; - postgresPassword = password; - postgresPasswordFile = passwordFile; - }; - - inherit dependsOn; - type = "postgresql-database"; -}