2022-05-03 12:24:13 +02:00
|
|
|
import ./make-test-python.nix ({ pkgs, lib, ... } :
|
2021-10-20 23:39:53 +02:00
|
|
|
|
|
|
|
let
|
2022-05-03 12:24:13 +02:00
|
|
|
lxd-image = import ../release.nix {
|
|
|
|
configuration = {
|
|
|
|
# Building documentation makes the test unnecessarily take a longer time:
|
|
|
|
documentation.enable = lib.mkForce false;
|
|
|
|
};
|
2021-10-20 23:39:53 +02:00
|
|
|
};
|
|
|
|
|
2023-10-06 23:07:50 +02:00
|
|
|
lxd-image-metadata = lxd-image.lxdContainerMeta.${pkgs.stdenv.hostPlatform.system};
|
|
|
|
lxd-image-rootfs = lxd-image.lxdContainerImage.${pkgs.stdenv.hostPlatform.system};
|
2021-10-20 23:39:53 +02:00
|
|
|
|
|
|
|
in {
|
|
|
|
name = "lxd-image-server";
|
|
|
|
|
|
|
|
meta = with pkgs.lib.maintainers; {
|
2022-05-03 12:24:13 +02:00
|
|
|
maintainers = [ mkg20001 patryk27 ];
|
2021-10-20 23:39:53 +02:00
|
|
|
};
|
|
|
|
|
2022-03-21 00:15:30 +01:00
|
|
|
nodes.machine = { lib, ... }: {
|
2021-10-20 23:39:53 +02:00
|
|
|
virtualisation = {
|
|
|
|
cores = 2;
|
|
|
|
|
|
|
|
memorySize = 2048;
|
|
|
|
diskSize = 4096;
|
|
|
|
|
|
|
|
lxc.lxcfs.enable = true;
|
|
|
|
lxd.enable = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
security.pki.certificates = [
|
|
|
|
(builtins.readFile ./common/acme/server/ca.cert.pem)
|
|
|
|
];
|
|
|
|
|
|
|
|
services.nginx = {
|
|
|
|
enable = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
services.lxd-image-server = {
|
|
|
|
enable = true;
|
|
|
|
nginx = {
|
|
|
|
enable = true;
|
|
|
|
domain = "acme.test";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
services.nginx.virtualHosts."acme.test" = {
|
|
|
|
enableACME = false;
|
|
|
|
sslCertificate = ./common/acme/server/acme.test.cert.pem;
|
|
|
|
sslCertificateKey = ./common/acme/server/acme.test.key.pem;
|
|
|
|
};
|
|
|
|
|
|
|
|
networking.hosts = {
|
|
|
|
"::1" = [ "acme.test" ];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
testScript = ''
|
|
|
|
machine.wait_for_unit("sockets.target")
|
|
|
|
machine.wait_for_unit("lxd.service")
|
|
|
|
machine.wait_for_file("/var/lib/lxd/unix.socket")
|
|
|
|
|
2023-08-10 20:07:42 +02:00
|
|
|
# Wait for lxd to settle
|
|
|
|
machine.succeed("lxd waitready")
|
2021-10-20 23:39:53 +02:00
|
|
|
|
|
|
|
# lxd expects the pool's directory to already exist
|
|
|
|
machine.succeed("mkdir /var/lxd-pool")
|
|
|
|
|
|
|
|
machine.succeed(
|
2023-08-10 20:07:42 +02:00
|
|
|
"lxd init --minimal"
|
2021-10-20 23:39:53 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
machine.succeed(
|
2022-05-03 12:24:13 +02:00
|
|
|
"lxc image import ${lxd-image-metadata}/*/*.tar.xz ${lxd-image-rootfs}/*/*.tar.xz --alias nixos"
|
2021-10-20 23:39:53 +02:00
|
|
|
)
|
|
|
|
|
2022-05-03 12:24:13 +02:00
|
|
|
loc = "/var/www/simplestreams/images/iats/nixos/amd64/default/v1"
|
2021-10-20 23:39:53 +02:00
|
|
|
|
|
|
|
with subtest("push image to server"):
|
2022-05-03 12:24:13 +02:00
|
|
|
machine.succeed("lxc launch nixos test")
|
|
|
|
machine.sleep(5)
|
|
|
|
machine.succeed("lxc stop -f test")
|
2021-10-20 23:39:53 +02:00
|
|
|
machine.succeed("lxc publish --public test --alias=testimg")
|
|
|
|
machine.succeed("lxc image export testimg")
|
|
|
|
machine.succeed("ls >&2")
|
|
|
|
machine.succeed("mkdir -p " + loc)
|
|
|
|
machine.succeed("mv *.tar.gz " + loc)
|
|
|
|
|
|
|
|
with subtest("pull image from server"):
|
|
|
|
machine.succeed("lxc remote add img https://acme.test --protocol=simplestreams")
|
|
|
|
machine.succeed("lxc image list img: >&2")
|
|
|
|
'';
|
|
|
|
})
|