1
0
Fork 0

merge files for postgresdb

This commit is contained in:
ibizaman 2023-01-14 23:36:16 -08:00
parent 5ef3fdba89
commit 8230336cb5
3 changed files with 29 additions and 42 deletions

View file

@ -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;};

View file

@ -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";
}

View file

@ -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";
}