diff options
author | Sandro <sandro.jaeckel@gmail.com> | 2024-02-27 23:01:22 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-27 23:01:22 +0100 |
commit | f9477e3a752d1b4b129b3adcb4fc2fa430627c11 (patch) | |
tree | 90a008e21190f9f6a87c306fb8e40354a3559331 /nixos/modules/services/networking | |
parent | 3beaece283ae37b855f92ccc4f42e1e3ab40c8fd (diff) | |
parent | 1293f046b500a2cd60ddf195639fae6419163931 (diff) | |
download | nixlib-f9477e3a752d1b4b129b3adcb4fc2fa430627c11.tar nixlib-f9477e3a752d1b4b129b3adcb4fc2fa430627c11.tar.gz nixlib-f9477e3a752d1b4b129b3adcb4fc2fa430627c11.tar.bz2 nixlib-f9477e3a752d1b4b129b3adcb4fc2fa430627c11.tar.lz nixlib-f9477e3a752d1b4b129b3adcb4fc2fa430627c11.tar.xz nixlib-f9477e3a752d1b4b129b3adcb4fc2fa430627c11.tar.zst nixlib-f9477e3a752d1b4b129b3adcb4fc2fa430627c11.zip |
Merge pull request #209506 from Izorkin/update-dhcpcd-exit-hook
nixos/dhcpcd: optimize exitHook
Diffstat (limited to 'nixos/modules/services/networking')
-rw-r--r-- | nixos/modules/services/networking/dhcpcd.nix | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/nixos/modules/services/networking/dhcpcd.nix b/nixos/modules/services/networking/dhcpcd.nix index 266a7ea1435e..8d5ac02ba88b 100644 --- a/nixos/modules/services/networking/dhcpcd.nix +++ b/nixos/modules/services/networking/dhcpcd.nix @@ -13,6 +13,8 @@ let enableDHCP = config.networking.dhcpcd.enable && (config.networking.useDHCP || any (i: i.useDHCP == true) interfaces); + enableNTPService = (config.services.ntp.enable || config.services.ntpd-rs.enable || config.services.openntpd.enable || config.services.chrony.enable); + # Don't start dhcpcd on explicitly configured interfaces or on # interfaces that are part of a bridge, bond or sit device. ignoredInterfaces = @@ -89,20 +91,22 @@ let ${cfg.extraConfig} ''; - exitHook = pkgs.writeText "dhcpcd.exit-hook" - '' + exitHook = pkgs.writeText "dhcpcd.exit-hook" '' + ${optionalString enableNTPService '' if [ "$reason" = BOUND -o "$reason" = REBOOT ]; then - # Restart ntpd. We need to restart it to make sure that it - # will actually do something: if ntpd cannot resolve the - # server hostnames in its config file, then it will never do - # anything ever again ("couldn't resolve ..., giving up on - # it"), so we silently lose time synchronisation. This also - # applies to openntpd. - /run/current-system/systemd/bin/systemctl try-reload-or-restart ntpd.service openntpd.service chronyd.service ntpd-rs.service || true + # Restart ntpd. We need to restart it to make sure that it will actually do something: + # if ntpd cannot resolve the server hostnames in its config file, then it will never do + # anything ever again ("couldn't resolve ..., giving up on it"), so we silently lose + # time synchronisation. This also applies to openntpd. + ${optionalString config.services.ntp.enable "/run/current-system/systemd/bin/systemctl try-reload-or-restart ntpd.service || true"} + ${optionalString config.services.ntpd-rs.enable "/run/current-system/systemd/bin/systemctl try-reload-or-restart ntpd-rs.service || true"} + ${optionalString config.services.openntpd.enable "/run/current-system/systemd/bin/systemctl try-reload-or-restart openntpd.service || true"} + ${optionalString config.services.chrony.enable "/run/current-system/systemd/bin/systemctl try-reload-or-restart chronyd.service || true"} fi + ''} - ${cfg.runHook} - ''; + ${cfg.runHook} + ''; in @@ -232,7 +236,7 @@ in wants = [ "network.target" ]; before = [ "network-online.target" ]; - restartTriggers = [ exitHook ]; + restartTriggers = optional (enableNTPService || cfg.runHook != "") [ exitHook ]; # Stopping dhcpcd during a reconfiguration is undesirable # because it brings down the network interfaces configured by @@ -261,7 +265,9 @@ in environment.systemPackages = [ dhcpcd ]; - environment.etc."dhcpcd.exit-hook".source = exitHook; + environment.etc."dhcpcd.exit-hook" = mkIf (enableNTPService || cfg.runHook != "") { + source = exitHook; + }; powerManagement.resumeCommands = mkIf config.systemd.services.dhcpcd.enable '' |