diff options
Diffstat (limited to 'nixpkgs/nixos/modules/tasks/auto-upgrade.nix')
-rw-r--r-- | nixpkgs/nixos/modules/tasks/auto-upgrade.nix | 94 |
1 files changed, 64 insertions, 30 deletions
diff --git a/nixpkgs/nixos/modules/tasks/auto-upgrade.nix b/nixpkgs/nixos/modules/tasks/auto-upgrade.nix index 1404dcbaf7c0..bfc5265518d2 100644 --- a/nixpkgs/nixos/modules/tasks/auto-upgrade.nix +++ b/nixpkgs/nixos/modules/tasks/auto-upgrade.nix @@ -13,21 +13,32 @@ in { enable = mkOption { type = types.bool; default = false; - description = '' + description = lib.mdDoc '' Whether to periodically upgrade NixOS to the latest version. If enabled, a systemd timer will run - <literal>nixos-rebuild switch --upgrade</literal> once a + `nixos-rebuild switch --upgrade` once a day. ''; }; + operation = mkOption { + type = types.enum ["switch" "boot"]; + default = "switch"; + example = "boot"; + description = lib.mdDoc '' + Whether to run + `nixos-rebuild switch --upgrade` or run + `nixos-rebuild boot --upgrade` + ''; + }; + flake = mkOption { type = types.nullOr types.str; default = null; example = "github:kloenk/nix"; - description = '' + description = lib.mdDoc '' The Flake URI of the NixOS configuration to build. - Disables the option <option>system.autoUpgrade.channel</option>. + Disables the option {option}`system.autoUpgrade.channel`. ''; }; @@ -53,34 +64,36 @@ in { "extra-binary-caches" "http://my-cache.example.org/" ]; - description = '' - Any additional flags passed to <command>nixos-rebuild</command>. + description = lib.mdDoc '' + Any additional flags passed to {command}`nixos-rebuild`. If you are using flakes and use a local repo you can add - <command>[ "--update-input" "nixpkgs" "--commit-lock-file" ]</command> + {command}`[ "--update-input" "nixpkgs" "--commit-lock-file" ]` to update nixpkgs. ''; }; dates = mkOption { - default = "04:40"; type = types.str; - description = '' - Specification (in the format described by - <citerefentry><refentrytitle>systemd.time</refentrytitle> - <manvolnum>7</manvolnum></citerefentry>) of the time at - which the update will occur. + default = "04:40"; + example = "daily"; + description = lib.mdDoc '' + How often or when upgrade occurs. For most desktop and server systems + a sufficient upgrade frequency is once a day. + + The format is described in + {manpage}`systemd.time(7)`. ''; }; allowReboot = mkOption { default = false; type = types.bool; - description = '' + description = lib.mdDoc '' Reboot the system into the new generation instead of a switch if the new generation uses a different kernel, kernel modules or initrd than the booted system. - See <option>rebootWindow</option> for configuring the times at which a reboot is allowed. + See {option}`rebootWindow` for configuring the times at which a reboot is allowed. ''; }; @@ -88,34 +101,33 @@ in { default = "0"; type = types.str; example = "45min"; - description = '' + description = lib.mdDoc '' Add a randomized delay before each automatic upgrade. - The delay will be chozen between zero and this value. + The delay will be chosen between zero and this value. This value must be a time span in the format specified by - <citerefentry><refentrytitle>systemd.time</refentrytitle> - <manvolnum>7</manvolnum></citerefentry> + {manpage}`systemd.time(7)` ''; }; rebootWindow = mkOption { - description = '' + description = lib.mdDoc '' Define a lower and upper time value (in HH:MM format) which constitute a time window during which reboots are allowed after an upgrade. - This option only has an effect when <option>allowReboot</option> is enabled. - The default value of <literal>null</literal> means that reboots are allowed at any time. + This option only has an effect when {option}`allowReboot` is enabled. + The default value of `null` means that reboots are allowed at any time. ''; default = null; example = { lower = "01:00"; upper = "05:00"; }; type = with types; nullOr (submodule { options = { lower = mkOption { - description = "Lower limit of the reboot window"; + description = lib.mdDoc "Lower limit of the reboot window"; type = types.strMatching "[[:digit:]]{2}:[[:digit:]]{2}"; example = "01:00"; }; upper = mkOption { - description = "Upper limit of the reboot window"; + description = lib.mdDoc "Upper limit of the reboot window"; type = types.strMatching "[[:digit:]]{2}:[[:digit:]]{2}"; example = "05:00"; }; @@ -123,6 +135,22 @@ in { }); }; + persistent = mkOption { + default = true; + type = types.bool; + example = false; + description = lib.mdDoc '' + Takes a boolean argument. If true, the time when the service + unit was last triggered is stored on disk. When the timer is + activated, the service unit is triggered immediately if it + would have been triggered at least once during the time when + the timer was inactive. Such triggering is nonetheless + subject to the delay imposed by RandomizedDelaySec=. This is + useful to catch up on missed runs of the service when the + system was powered down. + ''; + }; + }; }; @@ -171,7 +199,7 @@ in { nixos-rebuild = "${config.system.build.nixos-rebuild}/bin/nixos-rebuild"; date = "${pkgs.coreutils}/bin/date"; readlink = "${pkgs.coreutils}/bin/readlink"; - shutdown = "${pkgs.systemd}/bin/shutdown"; + shutdown = "${config.systemd.package}/bin/shutdown"; upgradeFlag = optional (cfg.channel == null) "--upgrade"; in if cfg.allowReboot then '' ${nixos-rebuild} boot ${toString (cfg.flags ++ upgradeFlag)} @@ -204,7 +232,7 @@ in { ''} if [ "''${booted}" = "''${built}" ]; then - ${nixos-rebuild} switch ${toString cfg.flags} + ${nixos-rebuild} ${cfg.operation} ${toString cfg.flags} ${optionalString (cfg.rebootWindow != null) '' elif [ "''${do_reboot}" != true ]; then echo "Outside of configured reboot window, skipping." @@ -213,15 +241,21 @@ in { ${shutdown} -r +1 fi '' else '' - ${nixos-rebuild} switch ${toString (cfg.flags ++ upgradeFlag)} + ${nixos-rebuild} ${cfg.operation} ${toString (cfg.flags ++ upgradeFlag)} ''; startAt = cfg.dates; - }; - systemd.timers.nixos-upgrade.timerConfig.RandomizedDelaySec = - cfg.randomizedDelaySec; + after = [ "network-online.target" ]; + wants = [ "network-online.target" ]; + }; + systemd.timers.nixos-upgrade = { + timerConfig = { + RandomizedDelaySec = cfg.randomizedDelaySec; + Persistent = cfg.persistent; + }; + }; }; } |