2024-04-03 11:46:17 +00:00
|
|
|
{ self, lib, ... }:
|
2023-12-18 22:37:45 +00:00
|
|
|
{
|
2024-04-03 11:46:17 +00:00
|
|
|
clan.machines.test_install_machine = {
|
|
|
|
clan.networking.targetHost = "test_install_machine";
|
2024-05-29 08:10:10 +00:00
|
|
|
fileSystems."/".device = lib.mkDefault "/dev/vdb";
|
|
|
|
boot.loader.grub.device = lib.mkDefault "/dev/vdb";
|
2024-04-03 11:46:17 +00:00
|
|
|
|
|
|
|
imports = [ self.nixosModules.test_install_machine ];
|
2024-03-17 18:48:49 +00:00
|
|
|
};
|
2023-12-18 22:37:45 +00:00
|
|
|
flake.nixosModules = {
|
2024-03-17 18:48:49 +00:00
|
|
|
test_install_machine =
|
|
|
|
{ lib, modulesPath, ... }:
|
|
|
|
{
|
|
|
|
imports = [
|
2024-05-02 12:34:58 +00:00
|
|
|
self.clanModules.disk-layouts
|
2024-03-17 18:48:49 +00:00
|
|
|
(modulesPath + "/testing/test-instrumentation.nix") # we need these 2 modules always to be able to run the tests
|
|
|
|
(modulesPath + "/profiles/qemu-guest.nix")
|
|
|
|
];
|
2024-05-02 12:34:58 +00:00
|
|
|
clan.disk-layouts.singleDiskExt4.device = "/dev/vdb";
|
2023-12-18 22:37:45 +00:00
|
|
|
|
2024-03-17 18:48:49 +00:00
|
|
|
environment.etc."install-successful".text = "ok";
|
2023-12-18 22:37:45 +00:00
|
|
|
|
2024-03-17 18:48:49 +00:00
|
|
|
boot.consoleLogLevel = lib.mkForce 100;
|
|
|
|
boot.kernelParams = [ "boot.shell_on_fail" ];
|
|
|
|
};
|
2023-12-18 22:37:45 +00:00
|
|
|
};
|
2024-03-17 18:48:49 +00:00
|
|
|
perSystem =
|
|
|
|
{
|
|
|
|
nodes,
|
|
|
|
pkgs,
|
|
|
|
lib,
|
|
|
|
...
|
|
|
|
}:
|
2023-12-18 22:37:45 +00:00
|
|
|
let
|
|
|
|
dependencies = [
|
|
|
|
self
|
2024-04-03 11:46:17 +00:00
|
|
|
self.nixosConfigurations.test_install_machine.config.system.build.toplevel
|
|
|
|
self.nixosConfigurations.test_install_machine.config.system.build.diskoScript
|
|
|
|
self.nixosConfigurations.test_install_machine.config.system.clan.deployment.file
|
2023-12-18 22:37:45 +00:00
|
|
|
pkgs.stdenv.drvPath
|
|
|
|
pkgs.nixos-anywhere
|
|
|
|
] ++ builtins.map (i: i.outPath) (builtins.attrValues self.inputs);
|
|
|
|
closureInfo = pkgs.closureInfo { rootPaths = dependencies; };
|
|
|
|
in
|
|
|
|
{
|
|
|
|
checks = pkgs.lib.mkIf (pkgs.stdenv.isLinux) {
|
2024-03-17 18:48:49 +00:00
|
|
|
test-installation = (import ../lib/test-base.nix) {
|
|
|
|
name = "test-installation";
|
|
|
|
nodes.target = {
|
|
|
|
services.openssh.enable = true;
|
|
|
|
users.users.root.openssh.authorizedKeys.keyFiles = [ ../lib/ssh/pubkey ];
|
|
|
|
system.nixos.variant_id = "installer";
|
|
|
|
virtualisation.emptyDiskImages = [ 4096 ];
|
|
|
|
nix.settings = {
|
|
|
|
substituters = lib.mkForce [ ];
|
|
|
|
hashed-mirrors = null;
|
|
|
|
connect-timeout = lib.mkForce 3;
|
|
|
|
flake-registry = pkgs.writeText "flake-registry" ''{"flakes":[],"version":2}'';
|
|
|
|
experimental-features = [
|
|
|
|
"nix-command"
|
|
|
|
"flakes"
|
|
|
|
];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
nodes.client = {
|
2024-04-19 15:02:02 +00:00
|
|
|
environment.systemPackages = [
|
|
|
|
self.packages.${pkgs.system}.clan-cli
|
|
|
|
] ++ self.packages.${pkgs.system}.clan-cli.runtimeDependencies;
|
2024-03-17 18:48:49 +00:00
|
|
|
environment.etc."install-closure".source = "${closureInfo}/store-paths";
|
|
|
|
virtualisation.memorySize = 2048;
|
|
|
|
nix.settings = {
|
|
|
|
substituters = lib.mkForce [ ];
|
|
|
|
hashed-mirrors = null;
|
|
|
|
connect-timeout = lib.mkForce 3;
|
|
|
|
flake-registry = pkgs.writeText "flake-registry" ''{"flakes":[],"version":2}'';
|
|
|
|
experimental-features = [
|
|
|
|
"nix-command"
|
|
|
|
"flakes"
|
|
|
|
];
|
|
|
|
};
|
|
|
|
system.extraDependencies = dependencies;
|
|
|
|
};
|
2023-12-18 22:37:45 +00:00
|
|
|
|
2024-03-17 18:48:49 +00:00
|
|
|
testScript = ''
|
|
|
|
def create_test_machine(oldmachine=None, args={}): # taken from <nixpkgs/nixos/tests/installer.nix>
|
|
|
|
startCommand = "${pkgs.qemu_test}/bin/qemu-kvm"
|
|
|
|
startCommand += " -cpu max -m 1024 -virtfs local,path=/nix/store,security_model=none,mount_tag=nix-store"
|
|
|
|
startCommand += f' -drive file={oldmachine.state_dir}/empty0.qcow2,id=drive1,if=none,index=1,werror=report'
|
|
|
|
startCommand += ' -device virtio-blk-pci,drive=drive1'
|
|
|
|
machine = create_machine({
|
|
|
|
"startCommand": startCommand,
|
|
|
|
} | args)
|
|
|
|
driver.machines.append(machine)
|
|
|
|
return machine
|
2023-12-18 22:37:45 +00:00
|
|
|
|
2024-03-17 18:48:49 +00:00
|
|
|
start_all()
|
2023-12-18 22:37:45 +00:00
|
|
|
|
2024-03-17 18:48:49 +00:00
|
|
|
client.succeed("${pkgs.coreutils}/bin/install -Dm 600 ${../lib/ssh/privkey} /root/.ssh/id_ed25519")
|
|
|
|
client.wait_until_succeeds("ssh -o StrictHostKeyChecking=accept-new -v root@target hostname")
|
2023-12-18 22:37:45 +00:00
|
|
|
|
2024-05-29 08:10:10 +00:00
|
|
|
client.succeed("clan machines install --debug --flake ${../..} --yes test_install_machine root@target >&2")
|
2024-03-17 18:48:49 +00:00
|
|
|
try:
|
|
|
|
target.shutdown()
|
|
|
|
except BrokenPipeError:
|
|
|
|
# qemu has already exited
|
|
|
|
pass
|
2023-12-18 22:37:45 +00:00
|
|
|
|
2024-03-17 18:48:49 +00:00
|
|
|
new_machine = create_test_machine(oldmachine=target, args={ "name": "new_machine" })
|
|
|
|
assert(new_machine.succeed("cat /etc/install-successful").strip() == "ok")
|
|
|
|
'';
|
|
|
|
} { inherit pkgs self; };
|
2023-12-18 22:37:45 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|