diff --git a/nixos/modules/system/boot/systemd/sysupdate.nix b/nixos/modules/system/boot/systemd/sysupdate.nix index 4c71b1714954..0f8bc2dd966b 100644 --- a/nixos/modules/system/boot/systemd/sysupdate.nix +++ b/nixos/modules/system/boot/systemd/sysupdate.nix @@ -11,7 +11,14 @@ let format = pkgs.formats.ini { listToValue = toString; }; - definitionsDirectory = utils.systemdUtils.lib.definitions "sysupdate.d" format cfg.transfers; + # TODO: Switch back to using utils.systemdUtils.lib.definitions once + # https://github.com/systemd/systemd/pull/38187 is resolved. Also ensure + # utils.systemdUtils.lib.definitions is capable of setting a custom file + # suffix. + sysupdateTransfers = lib.mapAttrs' (name: value: { + name = "sysupdate.d/${name}.transfer"; + value.source = format.generate "${name}.transfer" value; + }) cfg.transfers; in { options.systemd.sysupdate = { @@ -114,14 +121,23 @@ in }; config = lib.mkIf cfg.enable { + assertions = [ + { + assertion = config.systemd.package.withSysupdate; + message = "Cannot enable systemd-sysupdate with systemd package not built with sysupdate support"; + } + ]; systemd.additionalUpstreamSystemUnits = [ "systemd-sysupdate.service" "systemd-sysupdate.timer" "systemd-sysupdate-reboot.service" "systemd-sysupdate-reboot.timer" + "systemd-sysupdated.service" ]; + systemd.services.systemd-sysupdated.aliases = [ "dbus-org.freedesktop.sysupdate1.service" ]; + systemd.timers = { "systemd-sysupdate" = { wantedBy = [ "timers.target" ]; @@ -133,8 +149,11 @@ in }; }; - environment.etc."sysupdate.d".source = definitionsDirectory; + environment.etc = sysupdateTransfers; }; - meta.maintainers = with lib.maintainers; [ nikstur ]; + meta.maintainers = with lib.maintainers; [ + nikstur + jmbaur + ]; } diff --git a/nixos/tests/systemd-sysupdate.nix b/nixos/tests/systemd-sysupdate.nix index 059f2db5df41..5ab5da738171 100644 --- a/nixos/tests/systemd-sysupdate.nix +++ b/nixos/tests/systemd-sysupdate.nix @@ -1,7 +1,7 @@ # Tests downloading a signed update artifact from a server to a target machine. # This test does not rely on the `systemd.timer` units provided by the -# `systemd-sysupdate` module but triggers the `systemd-sysupdate` service -# manually to make the test more robust. +# `systemd-sysupdate` module but triggers the `updatectl` tool directly to +# demonstrate how to initiate updates manually. { lib, pkgs, ... }: @@ -62,7 +62,8 @@ in testScript = '' server.wait_for_unit("nginx.service") - target.succeed("systemctl start systemd-sysupdate") + print(target.succeed("updatectl list")) + target.succeed("updatectl update") assert "nixos" in target.wait_until_succeeds("cat /nixos_1.txt", timeout=5) ''; } diff --git a/pkgs/os-specific/linux/systemd/default.nix b/pkgs/os-specific/linux/systemd/default.nix index 80a9ae1bb550..d6af487a9692 100644 --- a/pkgs/os-specific/linux/systemd/default.nix +++ b/pkgs/os-specific/linux/systemd/default.nix @@ -559,6 +559,7 @@ stdenv.mkDerivation (finalAttrs: { (lib.mesonEnable "libiptc" withIptables) (lib.mesonEnable "repart" withRepart) (lib.mesonEnable "sysupdate" withSysupdate) + (lib.mesonEnable "sysupdated" withSysupdate) (lib.mesonEnable "seccomp" withLibseccomp) (lib.mesonEnable "selinux" withSelinux) (lib.mesonEnable "tpm2" withTpm2Tss) @@ -905,6 +906,7 @@ stdenv.mkDerivation (finalAttrs: { withMachined withNetworkd withPortabled + withSysupdate withTimedated withTpm2Tss withUtmp