From 493f1339b026de47fdaca57f37d881530795935d Mon Sep 17 00:00:00 2001 From: Grimmauld Date: Sun, 20 Jul 2025 16:57:49 +0200 Subject: [PATCH] nixos/systemd: move systemd.watchdog.* to systemd.settings.Manager --- nixos/modules/system/boot/systemd.nix | 136 +++++++++++++------------- nixos/tests/systemd.nix | 11 +-- 2 files changed, 74 insertions(+), 73 deletions(-) diff --git a/nixos/modules/system/boot/systemd.nix b/nixos/modules/system/boot/systemd.nix index a27a86bf834e..b5e22b07dce6 100644 --- a/nixos/modules/system/boot/systemd.nix +++ b/nixos/modules/system/boot/systemd.nix @@ -424,6 +424,60 @@ in ''; type = lib.types.submodule { freeformType = types.attrsOf unitOption; + options = { + WatchdogDevice = mkOption { + type = types.nullOr types.path; + default = null; + example = "/dev/watchdog"; + description = '' + The path to a hardware watchdog device which will be managed by systemd. + If not specified, systemd will default to `/dev/watchdog`. + ''; + }; + + RuntimeWatchdogSec = mkOption { + type = types.nullOr types.str; + default = null; + example = "30s"; + description = '' + The amount of time which can elapse before a watchdog hardware device + will automatically reboot the system. + + Valid time units include "ms", "s", "min", "h", "d", and "w"; + see {manpage}`systemd.time(7)`. + ''; + }; + + RebootWatchdogSec = mkOption { + type = types.nullOr types.str; + default = null; + example = "10m"; + description = '' + The amount of time which can elapse after a reboot has been triggered + before a watchdog hardware device will automatically reboot the system. + If left `null`, systemd will use its default of 10 minutes; + see {manpage}`systemd-system.conf(5)`. + + Valid time units include "ms", "s", "min", "h", "d", and "w"; + see also {manpage}`systemd.time(7)`. + ''; + }; + + KExecWatchdogSec = mkOption { + type = types.nullOr types.str; + default = null; + example = "10m"; + description = '' + The amount of time which can elapse when `kexec` is being executed before + a watchdog hardware device will automatically reboot the system. This + option should only be enabled if `reloadTime` is also enabled; + see {manpage}`kexec(8)`. + + Valid time units include "ms", "s", "min", "h", "d", and "w"; + see also {manpage}`systemd.time(7)`. + ''; + }; + }; }; example = { WatchdogDevice = "/dev/watchdog"; @@ -471,59 +525,6 @@ in by other NixOS modules. ''; }; - - watchdog.device = mkOption { - type = types.nullOr types.path; - default = null; - example = "/dev/watchdog"; - description = '' - The path to a hardware watchdog device which will be managed by systemd. - If not specified, systemd will default to `/dev/watchdog`. - ''; - }; - - watchdog.runtimeTime = mkOption { - type = types.nullOr types.str; - default = null; - example = "30s"; - description = '' - The amount of time which can elapse before a watchdog hardware device - will automatically reboot the system. - - Valid time units include "ms", "s", "min", "h", "d", and "w"; - see {manpage}`systemd.time(7)`. - ''; - }; - - watchdog.rebootTime = mkOption { - type = types.nullOr types.str; - default = null; - example = "10m"; - description = '' - The amount of time which can elapse after a reboot has been triggered - before a watchdog hardware device will automatically reboot the system. - If left `null`, systemd will use its default of 10 minutes; - see {manpage}`systemd-system.conf(5)`. - - Valid time units include "ms", "s", "min", "h", "d", and "w"; - see also {manpage}`systemd.time(7)`. - ''; - }; - - watchdog.kexecTime = mkOption { - type = types.nullOr types.str; - default = null; - example = "10m"; - description = '' - The amount of time which can elapse when `kexec` is being executed before - a watchdog hardware device will automatically reboot the system. This - option should only be enabled if `reloadTime` is also enabled; - see {manpage}`kexec(8)`. - - Valid time units include "ms", "s", "min", "h", "d", and "w"; - see also {manpage}`systemd.time(7)`. - ''; - }; }; ###### implementation @@ -659,19 +660,6 @@ in DefaultIPAccounting=yes ''} DefaultLimitCORE=infinity - ${optionalString (cfg.watchdog.device != null) '' - WatchdogDevice=${cfg.watchdog.device} - ''} - ${optionalString (cfg.watchdog.runtimeTime != null) '' - RuntimeWatchdogSec=${cfg.watchdog.runtimeTime} - ''} - ${optionalString (cfg.watchdog.rebootTime != null) '' - RebootWatchdogSec=${cfg.watchdog.rebootTime} - ''} - ${optionalString (cfg.watchdog.kexecTime != null) '' - KExecWatchdogSec=${cfg.watchdog.kexecTime} - ''} - ${attrsToSection cfg.settings.Manager} ''; @@ -871,5 +859,21 @@ in NixOS does not officially support this configuration and might cause your system to be unbootable in future versions. You are on your own. '') (mkRemovedOptionModule [ "systemd" "extraConfig" ] "Use systemd.settings.Manager instead.") + (lib.mkRenamedOptionModule + [ "systemd" "watchdog" "device" ] + [ "systemd" "settings" "Manager" "WatchdogDevice" ] + ) + (lib.mkRenamedOptionModule + [ "systemd" "watchdog" "runtimeTime" ] + [ "systemd" "settings" "Manager" "RuntimeWatchdogSec" ] + ) + (lib.mkRenamedOptionModule + [ "systemd" "watchdog" "rebootTime" ] + [ "systemd" "settings" "Manager" "RebootWatchdogSec" ] + ) + (lib.mkRenamedOptionModule + [ "systemd" "watchdog" "kexecTime" ] + [ "systemd" "settings" "Manager" "KExecWatchdogSec" ] + ) ]; } diff --git a/nixos/tests/systemd.nix b/nixos/tests/systemd.nix index a39d9d9545a1..1209a90cbc43 100644 --- a/nixos/tests/systemd.nix +++ b/nixos/tests/systemd.nix @@ -29,6 +29,10 @@ systemd.settings.Manager = { DefaultEnvironment = "XXX_SYSTEM=foo"; + WatchdogDevice = "/dev/watchdog"; + RuntimeWatchdogSec = "30s"; + RebootWatchdogSec = "10min"; + KExecWatchdogSec = "5min"; }; systemd.user.extraConfig = "DefaultEnvironment=\"XXX_USER=bar\""; services.journald.extraConfig = "Storage=volatile"; @@ -88,13 +92,6 @@ ''; }; - systemd.watchdog = { - device = "/dev/watchdog"; - runtimeTime = "30s"; - rebootTime = "10min"; - kexecTime = "5min"; - }; - environment.etc."systemd/system-preset/10-testservice.preset".text = '' disable ${config.systemd.services.testservice1.name} '';