merge files for postgresdb
This commit is contained in:
parent
5ef3fdba89
commit
8230336cb5
3 changed files with 29 additions and 42 deletions
|
@ -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;};
|
||||||
|
|
||||||
|
|
|
@ -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}";
|
|
||||||
'';
|
|
||||||
|
|
||||||
buildCommand = ''
|
src = pkgs.writeTextDir "${database}.sql" ''
|
||||||
mkdir -p $out/postgresql-databases
|
CREATE USER "${username}" WITH PASSWORD '${password}';
|
||||||
cp $src/*.sql $out/postgresql-databases
|
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";
|
||||||
}
|
}
|
||||||
|
|
|
@ -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";
|
|
||||||
}
|
|
Loading…
Reference in a new issue