2023-07-17 17:20:32 +02:00
|
|
|
# Tests downloading a signed update aritfact 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.
|
|
|
|
|
|
|
|
{ lib, pkgs, ... }:
|
|
|
|
|
|
|
|
let
|
|
|
|
gpgKeyring = import ./common/gpg-keyring.nix { inherit pkgs; };
|
|
|
|
in
|
|
|
|
{
|
|
|
|
name = "systemd-sysupdate";
|
|
|
|
|
|
|
|
meta.maintainers = with lib.maintainers; [ nikstur ];
|
|
|
|
|
|
|
|
nodes = {
|
|
|
|
server = { pkgs, ... }: {
|
|
|
|
networking.firewall.enable = false;
|
|
|
|
services.nginx = {
|
|
|
|
enable = true;
|
|
|
|
virtualHosts."server" = {
|
|
|
|
root = pkgs.runCommand "sysupdate-artifacts" { buildInputs = [ pkgs.gnupg ]; } ''
|
|
|
|
mkdir -p $out
|
|
|
|
cd $out
|
|
|
|
|
2024-01-31 18:16:04 +01:00
|
|
|
echo "nixos" > nixos_1.txt
|
|
|
|
sha256sum nixos_1.txt > SHA256SUMS
|
2023-07-17 17:20:32 +02:00
|
|
|
|
|
|
|
export GNUPGHOME="$(mktemp -d)"
|
|
|
|
cp -R ${gpgKeyring}/* $GNUPGHOME
|
|
|
|
|
|
|
|
gpg --batch --sign --detach-sign --output SHA256SUMS.gpg SHA256SUMS
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
target = {
|
|
|
|
systemd.sysupdate = {
|
|
|
|
enable = true;
|
|
|
|
transfers = {
|
2024-01-31 18:16:04 +01:00
|
|
|
"text-file" = {
|
2023-07-17 17:20:32 +02:00
|
|
|
Source = {
|
|
|
|
Type = "url-file";
|
|
|
|
Path = "http://server/";
|
2024-01-31 18:16:04 +01:00
|
|
|
MatchPattern = "nixos_@v.txt";
|
2023-07-17 17:20:32 +02:00
|
|
|
};
|
|
|
|
Target = {
|
2024-01-31 18:16:04 +01:00
|
|
|
Path = "/";
|
|
|
|
MatchPattern = [ "nixos_@v.txt" ];
|
2023-07-17 17:20:32 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
environment.etc."systemd/import-pubring.gpg".source = "${gpgKeyring}/pubkey.gpg";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
testScript = ''
|
|
|
|
server.wait_for_unit("nginx.service")
|
|
|
|
|
|
|
|
target.succeed("systemctl start systemd-sysupdate")
|
2024-01-31 18:16:04 +01:00
|
|
|
assert "nixos" in target.wait_until_succeeds("cat /nixos_1.txt", timeout=5)
|
2023-07-17 17:20:32 +02:00
|
|
|
'';
|
|
|
|
}
|