lol

nixos/systemd-sysupdate: init

nikstur 9b4d3b84 5750660f

+144
+1
nixos/doc/manual/release-notes/rl-2311.section.md
··· 34 34 35 35 - [ebusd](https://ebusd.eu), a daemon for handling communication with eBUS devices connected to a 2-wire bus system (“energy bus” used by numerous heating systems). Available as [services.ebusd](#opt-services.ebusd.enable). 36 36 37 + - [systemd-sysupdate](https://www.freedesktop.org/software/systemd/man/systemd-sysupdate.html), atomically updates the host OS, container images, portable service images or other sources. Available as [systemd.sysupdate](opt-systemd.sysupdate). 37 38 38 39 ## Backward Incompatibilities {#sec-release-23.11-incompatibilities} 39 40
+1
nixos/modules/module-list.nix
··· 1398 1398 ./system/boot/systemd/oomd.nix 1399 1399 ./system/boot/systemd/repart.nix 1400 1400 ./system/boot/systemd/shutdown.nix 1401 + ./system/boot/systemd/sysupdate.nix 1401 1402 ./system/boot/systemd/tmpfiles.nix 1402 1403 ./system/boot/systemd/user.nix 1403 1404 ./system/boot/systemd/userdbd.nix
+142
nixos/modules/system/boot/systemd/sysupdate.nix
··· 1 + { config, lib, pkgs, utils, ... }: 2 + 3 + let 4 + cfg = config.systemd.sysupdate; 5 + 6 + format = pkgs.formats.ini { }; 7 + 8 + listOfDefinitions = lib.mapAttrsToList 9 + (name: format.generate "${name}.conf") 10 + (lib.filterAttrs (k: _: !(lib.hasPrefix "_" k)) cfg.transfers); 11 + 12 + definitionsDirectory = pkgs.runCommand "sysupdate.d" { } '' 13 + mkdir -p $out 14 + ${(lib.concatStringsSep "\n" 15 + (map (pkg: "cp ${pkg} $out/${pkg.name}") listOfDefinitions) 16 + )} 17 + ''; 18 + in 19 + { 20 + options.systemd.sysupdate = { 21 + 22 + enable = lib.mkEnableOption (lib.mdDoc "systemd-sysupdate") // { 23 + description = lib.mdDoc '' 24 + Atomically update the host OS, container images, portable service 25 + images or other sources. 26 + 27 + If enabled, updates are triggered in regular intervals via a 28 + `systemd.timer` unit. 29 + 30 + Please see 31 + <https://www.freedesktop.org/software/systemd/man/systemd-sysupdate.html> 32 + for more details. 33 + ''; 34 + }; 35 + 36 + timerConfig = utils.systemdUtils.unitOptions.timerOptions.options.timerConfig // { 37 + default = { }; 38 + description = lib.mdDoc '' 39 + The timer configuration for performing the update. 40 + 41 + By default, the upstream configuration is used: 42 + <https://github.com/systemd/systemd/blob/main/units/systemd-sysupdate.timer> 43 + ''; 44 + }; 45 + 46 + reboot = { 47 + enable = lib.mkEnableOption (lib.mdDoc "automatically rebooting after an update") // { 48 + description = lib.mdDoc '' 49 + Whether to automatically reboot after an update. 50 + 51 + If set to `true`, the system will automatically reboot via a 52 + `systemd.timer` unit but only after a new version was installed. 53 + 54 + This uses a unit completely separate from the one performing the 55 + update because it is typically advisable to download updates 56 + regularly while the system is up, but delay reboots until the 57 + appropriate time (i.e. typically at night). 58 + 59 + Set this to `false` if you do not want to reboot after an update. This 60 + is useful when you update a container image or another source where 61 + rebooting is not necessary in order to finalize the update. 62 + ''; 63 + }; 64 + 65 + timerConfig = utils.systemdUtils.unitOptions.timerOptions.options.timerConfig // { 66 + default = { }; 67 + description = lib.mdDoc '' 68 + The timer configuration for rebooting after an update. 69 + 70 + By default, the upstream configuration is used: 71 + <https://github.com/systemd/systemd/blob/main/units/systemd-sysupdate-reboot.timer> 72 + ''; 73 + }; 74 + }; 75 + 76 + transfers = lib.mkOption { 77 + type = with lib.types; attrsOf format.type; 78 + default = { }; 79 + example = { 80 + "10-uki.conf" = { 81 + Transfer = { 82 + ProtectVersion = "%A"; 83 + }; 84 + 85 + Source = { 86 + Type = "url-file"; 87 + Path = "https://download.example.com/"; 88 + MatchPattern = "nixos_@v.efi.xz"; 89 + }; 90 + 91 + Target = { 92 + Type = "regular-file"; 93 + Path = "/EFI/Linux"; 94 + PathRelativeTo = "boot"; 95 + MatchPattern = '' 96 + nixos_@v+@l-@d.efi"; \ 97 + nixos_@v+@l.efi \ 98 + nixos_@v.efi 99 + ''; 100 + Mode = "0444"; 101 + TriesLeft = 3; 102 + TriesDone = 0; 103 + InstancesMax = 2; 104 + }; 105 + }; 106 + }; 107 + description = lib.mdDoc '' 108 + Specify transfers as a set of the names of the transfer files as the 109 + key and the configuration as its value. The configuration can use all 110 + upstream options. See 111 + <https://www.freedesktop.org/software/systemd/man/sysupdate.d.html> 112 + for all available options. 113 + ''; 114 + }; 115 + 116 + }; 117 + 118 + config = lib.mkIf cfg.enable { 119 + 120 + systemd.additionalUpstreamSystemUnits = [ 121 + "systemd-sysupdate.service" 122 + "systemd-sysupdate.timer" 123 + "systemd-sysupdate-reboot.service" 124 + "systemd-sysupdate-reboot.timer" 125 + ]; 126 + 127 + systemd.timers = { 128 + "systemd-sysupdate" = { 129 + wantedBy = [ "timers.target" ]; 130 + timerConfig = cfg.timerConfig; 131 + }; 132 + "systemd-sysupdate-reboot" = lib.mkIf cfg.reboot.enable { 133 + wantedBy = [ "timers.target" ]; 134 + timerConfig = cfg.reboot.timerConfig; 135 + }; 136 + }; 137 + 138 + environment.etc."sysupdate.d".source = definitionsDirectory; 139 + }; 140 + 141 + meta.maintainers = with lib.maintainers; [ nikstur ]; 142 + }