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); callPackage = pkgs.lib.callPackageWith (pkgs // customPkgs);
customPkgs = rec { customPkgs = rec {
PostgresDB = callPackage ./postgresdb {}; mkPostgresDB = callPackage ./postgresdb {};
mkPostgresDB = callPackage ./postgresdb/mkdefault.nix {inherit PostgresDB;};
mkHaproxyService = callPackage ./haproxy/unit.nix {inherit utils;}; mkHaproxyService = callPackage ./haproxy/unit.nix {inherit utils;};

View file

@ -2,15 +2,19 @@
, pkgs , pkgs
, lib , lib
}: }:
{ postgresDatabase { name
, postgresUsername
, postgresPassword ? null , database
, postgresPasswordFile ? null , username
, password ? null
, passwordFile ? null
, dependsOn ? {}
}: }:
assert lib.assertMsg ( assert lib.assertMsg (
(postgresPassword == null && postgresPasswordFile != null) (password == null && passwordFile != null)
|| (postgresPassword != null && postgresPasswordFile == null) || (password != null && passwordFile == null)
) "set either postgresPassword or postgresPasswordFile"; ) "set either postgresPassword or postgresPasswordFile";
# From https://github.com/svanderburg/dysnomia/blob/master/dysnomia-modules/postgresql-database.in # From https://github.com/svanderburg/dysnomia/blob/master/dysnomia-modules/postgresql-database.in
@ -21,16 +25,24 @@ assert lib.assertMsg (
# inside get imported. # inside get imported.
# TODO: https://stackoverflow.com/a/69480184/1013628 # TODO: https://stackoverflow.com/a/69480184/1013628
stdenv.mkDerivation { {
name = postgresDatabase; inherit name;
inherit database username password passwordFile;
src = pkgs.writeTextDir "${postgresDatabase}.sql" '' pkg = stdenv.mkDerivation {
CREATE USER "${postgresUsername}" WITH PASSWORD '${postgresPassword}'; name = database;
GRANT ALL PRIVILEGES ON DATABASE "${postgresUsername}" TO "${postgresDatabase}";
src = pkgs.writeTextDir "${database}.sql" ''
CREATE USER "${username}" WITH PASSWORD '${password}';
GRANT ALL PRIVILEGES ON DATABASE "${username}" TO "${database}";
''; '';
buildCommand = '' buildCommand = ''
mkdir -p $out/postgresql-databases mkdir -p $out/postgresql-databases
cp $src/*.sql $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";
}