···3839 pre84 = versionOlder (builtins.parseDrvName postgresql.name).version "8.4";
4041- # NixOS traditionally used `root` as superuser, most other distros use `postgres`. From 17.09
42- # we also try to follow this standard
43- superuser = (if versionAtLeast config.system.stateVersion "17.09" then "postgres" else "root");
4445in
46···151 Contents of the <filename>recovery.conf</filename> file.
152 '';
153 };
0000000000154 };
155156 };
···215 ''
216 # Initialise the database.
217 if ! test -e ${cfg.dataDir}/PG_VERSION; then
218- initdb -U ${superuser}
219 # See postStart!
220 touch "${cfg.dataDir}/.first_startup"
221 fi
···247 # Wait for PostgreSQL to be ready to accept connections.
248 postStart =
249 ''
250- while ! ${pkgs.sudo}/bin/sudo -u ${superuser} psql --port=${toString cfg.port} -d postgres -c "" 2> /dev/null; do
251 if ! kill -0 "$MAINPID"; then exit 1; fi
252 sleep 0.1
253 done
254255 if test -e "${cfg.dataDir}/.first_startup"; then
256 ${optionalString (cfg.initialScript != null) ''
257- ${pkgs.sudo}/bin/sudo -u ${superuser} psql -f "${cfg.initialScript}" --port=${toString cfg.port} -d postgres
258 ''}
259 rm -f "${cfg.dataDir}/.first_startup"
260 fi
···3839 pre84 = versionOlder (builtins.parseDrvName postgresql.name).version "8.4";
400004142in
43···148 Contents of the <filename>recovery.conf</filename> file.
149 '';
150 };
151+ superUser = mkOption {
152+ type = types.str;
153+ default= if versionAtLeast config.system.stateVersion "17.09" then "postgres" else "root";
154+ internal = true;
155+ description = ''
156+ NixOS traditionally used `root` as superuser, most other distros use `postgres`.
157+ From 17.09 we also try to follow this standard. Internal since changing this value
158+ would lead to breakage while setting up databases.
159+ '';
160+ };
161 };
162163 };
···222 ''
223 # Initialise the database.
224 if ! test -e ${cfg.dataDir}/PG_VERSION; then
225+ initdb -U ${cfg.superUser}
226 # See postStart!
227 touch "${cfg.dataDir}/.first_startup"
228 fi
···254 # Wait for PostgreSQL to be ready to accept connections.
255 postStart =
256 ''
257+ while ! ${pkgs.sudo}/bin/sudo -u ${cfg.superUser} psql --port=${toString cfg.port} -d postgres -c "" 2> /dev/null; do
258 if ! kill -0 "$MAINPID"; then exit 1; fi
259 sleep 0.1
260 done
261262 if test -e "${cfg.dataDir}/.first_startup"; then
263 ${optionalString (cfg.initialScript != null) ''
264+ ${pkgs.sudo}/bin/sudo -u ${cfg.superUser} psql -f "${cfg.initialScript}" --port=${toString cfg.port} -d postgres
265 ''}
266 rm -f "${cfg.dataDir}/.first_startup"
267 fi
+32
nixos/tests/hydra.nix
···00000000000000000000000000000000
···1+import ./make-test.nix ({ pkgs, ...} : {
2+ name = "hydra-init-localdb";
3+ meta = with pkgs.stdenv.lib.maintainers; {
4+ maintainers = [ pstn ];
5+ };
6+7+ machine =
8+ { config, pkgs, ... }:
9+10+ {
11+ services.hydra = {
12+ enable = true;
13+14+ #Hydra needs those settings to start up, so we add something not harmfull.
15+ hydraURL = "example.com";
16+ notificationSender = "example@example.com";
17+ };
18+ };
19+20+ testScript =
21+ ''
22+ # let the system boot up
23+ $machine->waitForUnit("multi-user.target");
24+ # test whether the database is running
25+ $machine->succeed("systemctl status postgresql.service");
26+ # test whether the actual hydra daemons are running
27+ $machine->succeed("systemctl status hydra-queue-runner.service");
28+ $machine->succeed("systemctl status hydra-init.service");
29+ $machine->succeed("systemctl status hydra-evaluator.service");
30+ $machine->succeed("systemctl status hydra-send-stats.service");
31+ '';
32+})