diff options
Diffstat (limited to 'nixos/modules/services/databases')
-rw-r--r-- | nixos/modules/services/databases/postgresql.nix | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/nixos/modules/services/databases/postgresql.nix b/nixos/modules/services/databases/postgresql.nix index 73447e3cf0d8..a1ab1c92b8f9 100644 --- a/nixos/modules/services/databases/postgresql.nix +++ b/nixos/modules/services/databases/postgresql.nix @@ -181,8 +181,13 @@ in # Initialise the database. if ! test -e ${cfg.dataDir}; then mkdir -m 0700 -p ${cfg.dataDir} - chown -R postgres ${cfg.dataDir} - su -s ${pkgs.stdenv.shell} postgres -c 'initdb -U root' + if [ "$(id -u)" = 0 ]; then + chown -R postgres ${cfg.dataDir} + su -s ${pkgs.stdenv.shell} postgres -c 'initdb -U root' + else + # For non-root operation. + initdb + fi rm -f ${cfg.dataDir}/*.conf touch "${cfg.dataDir}/.first_startup" fi |