about summary refs log tree commit diff
path: root/nixos/modules/services/databases
diff options
context:
space:
mode:
authordanbst <abcz2.uprola@gmail.com>2019-07-23 21:53:59 +0300
committerdanbst <abcz2.uprola@gmail.com>2019-07-23 21:56:26 +0300
commit7e4e37fff4cd97cc7fed26c9e1060761ed1379a7 (patch)
tree5d4f16d1b8ee6e2a74c166409401d5b45513a9b3 /nixos/modules/services/databases
parent92a015d35d0450708438f68466027707b18188bd (diff)
downloadnixlib-7e4e37fff4cd97cc7fed26c9e1060761ed1379a7.tar
nixlib-7e4e37fff4cd97cc7fed26c9e1060761ed1379a7.tar.gz
nixlib-7e4e37fff4cd97cc7fed26c9e1060761ed1379a7.tar.bz2
nixlib-7e4e37fff4cd97cc7fed26c9e1060761ed1379a7.tar.lz
nixlib-7e4e37fff4cd97cc7fed26c9e1060761ed1379a7.tar.xz
nixlib-7e4e37fff4cd97cc7fed26c9e1060761ed1379a7.tar.zst
nixlib-7e4e37fff4cd97cc7fed26c9e1060761ed1379a7.zip
postgresql: allow changing initidb arguments via module system
Closes https://github.com/NixOS/nixpkgs/issues/18829

+ some cleanups
Diffstat (limited to 'nixos/modules/services/databases')
-rw-r--r--nixos/modules/services/databases/postgresql.nix25
1 files changed, 18 insertions, 7 deletions
diff --git a/nixos/modules/services/databases/postgresql.nix b/nixos/modules/services/databases/postgresql.nix
index 7dddebfc28dd..b89f4a57253a 100644
--- a/nixos/modules/services/databases/postgresql.nix
+++ b/nixos/modules/services/databases/postgresql.nix
@@ -119,6 +119,15 @@ in
         '';
       };
 
+      initdbFlags = mkOption {
+        type = with types; listOf str;
+        default = [];
+        description = ''
+          Additional flags passed to <literal>initdb<literal> during data dir
+          initialisation.
+        '';
+      };
+
       initialScript = mkOption {
         type = types.nullOr types.path;
         default = null;
@@ -257,10 +266,10 @@ in
 
   ###### implementation
 
-  config = mkIf config.services.postgresql.enable {
+  config = mkIf cfg.enable {
 
     assertions = [
-      { assertion = cfg.groupAccess -> builtins.compareVersions cfg.package.version "11.0" >= 0;
+      { assertion = cfg.groupAccess -> versionAtLeast cfg.package.version "11.0";
         message = ''
           'groupAccess' is not available for PostgreSQL < 11.
         '';
@@ -276,8 +285,12 @@ in
             else pkgs.postgresql_9_4);
 
     services.postgresql.dataDir =
-      mkDefault (if versionAtLeast config.system.stateVersion "17.09" then "/var/lib/postgresql/${config.services.postgresql.package.psqlSchema}"
-                 else "/var/db/postgresql");
+      mkDefault (if versionAtLeast config.system.stateVersion "17.09"
+                  then "/var/lib/postgresql/${cfg.package.psqlSchema}"
+                  else "/var/db/postgresql");
+
+    services.postgresql.initdbFlags =
+      mkDefault (lib.optional cfg.groupAccess "--allow-group-access");
 
     services.postgresql.authentication = mkAfter
       ''
@@ -324,9 +337,7 @@ in
           ''
             # Initialise the database.
             if ! test -e ${cfg.dataDir}/PG_VERSION; then
-              initdb -U ${cfg.superUser} ${
-                lib.optionalString cfg.groupAccess "--allow-group-access"
-              }
+              initdb -U ${cfg.superUser} ${lib.concatStringsSep " " cfg.initdbFlags}
               # See postStart!
               touch "${cfg.dataDir}/.first_startup"
             fi