diff --git a/nixos/modules/services/system/nscd.nix b/nixos/modules/services/system/nscd.nix index f357eb4e1fc..1ac82064a1f 100644 --- a/nixos/modules/services/system/nscd.nix +++ b/nixos/modules/services/system/nscd.nix @@ -9,6 +9,8 @@ let inherit (pkgs.lib) singleton; + cfgFile = pkgs.writeText "nscd.conf" cfg.config; + in { @@ -63,7 +65,7 @@ in restartTriggers = [ config.environment.etc.hosts.source ]; serviceConfig = - { ExecStart = "@${pkgs.glibc}/sbin/nscd nscd -f ${pkgs.writeText "nscd.conf" cfg.config}"; + { ExecStart = "@${pkgs.glibc}/sbin/nscd nscd -f ${cfgFile}"; Type = "forking"; PIDFile = "/run/nscd/nscd.pid"; Restart = "always"; @@ -73,6 +75,15 @@ in "${pkgs.glibc}/sbin/nscd --invalidate hosts" ]; }; + + # Urgggggh... Nscd forks before opening its socket and writing + # its pid. So wait until it's ready. + postStart = + '' + while ! ${pkgs.glibc}/sbin/nscd -g -f ${cfgFile} > /dev/null; do + sleep 0.2 + done + ''; }; }; diff --git a/nixos/tests/misc.nix b/nixos/tests/misc.nix index 031fff2de58..24c8b230629 100644 --- a/nixos/tests/misc.nix +++ b/nixos/tests/misc.nix @@ -13,6 +13,8 @@ import ./make-test.nix { testScript = '' + $machine->waitForUnit("default.target"); + subtest "nixos-version", sub { $machine->succeed("[ `nixos-version | wc -w` = 2 ]"); }; @@ -61,8 +63,6 @@ import ./make-test.nix { # Test whether hostname (and by extension nss_myhostname) works. subtest "hostname", sub { - $machine->waitForUnit("dhcpcd.service"); - $machine->waitForUnit("network.target"); $machine->succeed('[ "`hostname`" = machine ]'); $machine->succeed('[ "`hostname -s`" = machine ]'); };