10 cfg = config.systemd.sysupdate;
12 format = pkgs.formats.ini { listToValue = toString; };
14 definitionsDirectory = utils.systemdUtils.lib.definitions "sysupdate.d" format cfg.transfers;
17 options.systemd.sysupdate = {
19 enable = lib.mkEnableOption "systemd-sysupdate" // {
21 Atomically update the host OS, container images, portable service
22 images or other sources.
24 If enabled, updates are triggered in regular intervals via a
28 <https://www.freedesktop.org/software/systemd/man/systemd-sysupdate.html>
33 timerConfig = utils.systemdUtils.unitOptions.timerOptions.options.timerConfig // {
36 The timer configuration for performing the update.
38 By default, the upstream configuration is used:
39 <https://github.com/systemd/systemd/blob/main/units/systemd-sysupdate.timer>
44 enable = lib.mkEnableOption "automatically rebooting after an update" // {
46 Whether to automatically reboot after an update.
48 If set to `true`, the system will automatically reboot via a
49 `systemd.timer` unit but only after a new version was installed.
51 This uses a unit completely separate from the one performing the
52 update because it is typically advisable to download updates
53 regularly while the system is up, but delay reboots until the
54 appropriate time (i.e. typically at night).
56 Set this to `false` if you do not want to reboot after an update. This
57 is useful when you update a container image or another source where
58 rebooting is not necessary in order to finalize the update.
62 timerConfig = utils.systemdUtils.unitOptions.timerOptions.options.timerConfig // {
65 The timer configuration for rebooting after an update.
67 By default, the upstream configuration is used:
68 <https://github.com/systemd/systemd/blob/main/units/systemd-sysupdate-reboot.timer>
73 transfers = lib.mkOption {
74 type = with lib.types; attrsOf format.type;
79 ProtectVersion = "%A";
84 Path = "https://download.example.com/";
93 Type = "regular-file";
95 PathRelativeTo = "boot";
97 nixos_@v+@l-@d.efi"; \
109 Specify transfers as a set of the names of the transfer files as the
110 key and the configuration as its value. The configuration can use all
111 upstream options. See
112 <https://www.freedesktop.org/software/systemd/man/sysupdate.d.html>
113 for all available options.
119 config = lib.mkIf cfg.enable {
121 systemd.additionalUpstreamSystemUnits = [
122 "systemd-sysupdate.service"
123 "systemd-sysupdate.timer"
124 "systemd-sysupdate-reboot.service"
125 "systemd-sysupdate-reboot.timer"
129 "systemd-sysupdate" = {
130 wantedBy = [ "timers.target" ];
131 timerConfig = cfg.timerConfig;
133 "systemd-sysupdate-reboot" = lib.mkIf cfg.reboot.enable {
134 wantedBy = [ "timers.target" ];
135 timerConfig = cfg.reboot.timerConfig;
139 environment.etc."sysupdate.d".source = definitionsDirectory;
142 meta.maintainers = with lib.maintainers; [ nikstur ];