add diskco pkg
This commit is contained in:
23
pkgs/disko/tests/disko-install/configuration.nix
Normal file
23
pkgs/disko/tests/disko-install/configuration.nix
Normal file
@@ -0,0 +1,23 @@
|
||||
{ lib, pkgs, modulesPath, ... }: {
|
||||
imports = [
|
||||
(modulesPath + "/testing/test-instrumentation.nix")
|
||||
(modulesPath + "/profiles/qemu-guest.nix")
|
||||
(modulesPath + "/profiles/minimal.nix")
|
||||
];
|
||||
|
||||
networking.hostName = "disko-machine";
|
||||
|
||||
# do not try to fetch stuff from the internet
|
||||
nix.settings = {
|
||||
substituters = lib.mkForce [ ];
|
||||
hashed-mirrors = null;
|
||||
connect-timeout = 3;
|
||||
flake-registry = pkgs.writeText "flake-registry" ''{"flakes":[],"version":2}'';
|
||||
experimental-features = [ "nix-command" "flakes" ];
|
||||
};
|
||||
services.openssh.enable = true;
|
||||
boot.kernelParams = [ "console=tty0" ] ++
|
||||
(lib.optional (pkgs.stdenv.hostPlatform.isAarch) "ttyAMA0,115200") ++
|
||||
(lib.optional (pkgs.stdenv.hostPlatform.isRiscV64) "ttySIF0,115200") ++
|
||||
[ "console=ttyS0,115200" ];
|
||||
}
|
||||
66
pkgs/disko/tests/disko-install/default.nix
Normal file
66
pkgs/disko/tests/disko-install/default.nix
Normal file
@@ -0,0 +1,66 @@
|
||||
{ pkgs ? import <nixpkgs> { }, self, diskoVersion }:
|
||||
let
|
||||
disko = pkgs.callPackage ../../package.nix { inherit diskoVersion; };
|
||||
|
||||
dependencies = [
|
||||
self.nixosConfigurations.testmachine.pkgs.stdenv.drvPath
|
||||
(self.nixosConfigurations.testmachine.pkgs.closureInfo { rootPaths = [ ]; }).drvPath
|
||||
|
||||
# https://github.com/NixOS/nixpkgs/blob/f2fd33a198a58c4f3d53213f01432e4d88474956/nixos/modules/system/activation/top-level.nix#L342
|
||||
self.nixosConfigurations.testmachine.pkgs.perlPackages.ConfigIniFiles
|
||||
self.nixosConfigurations.testmachine.pkgs.perlPackages.FileSlurp
|
||||
|
||||
self.nixosConfigurations.testmachine.config.system.build.toplevel
|
||||
self.nixosConfigurations.testmachine.config.system.build.diskoScript
|
||||
] ++ builtins.map (i: i.outPath) (builtins.attrValues self.inputs);
|
||||
|
||||
closureInfo = pkgs.closureInfo { rootPaths = dependencies; };
|
||||
in
|
||||
pkgs.nixosTest {
|
||||
name = "disko-test";
|
||||
nodes.machine = {
|
||||
virtualisation.emptyDiskImages = [ 4096 ];
|
||||
virtualisation.memorySize = 3000;
|
||||
environment.etc."install-closure".source = "${closureInfo}/store-paths";
|
||||
};
|
||||
|
||||
testScript = ''
|
||||
def create_test_machine(
|
||||
oldmachine=None, **kwargs
|
||||
): # taken from <nixpkgs/nixos/tests/installer.nix>
|
||||
start_command = [
|
||||
"${pkgs.qemu_test}/bin/qemu-kvm",
|
||||
"-cpu",
|
||||
"max",
|
||||
"-m",
|
||||
"1024",
|
||||
"-virtfs",
|
||||
"local,path=/nix/store,security_model=none,mount_tag=nix-store",
|
||||
"-drive",
|
||||
f"file={oldmachine.state_dir}/empty0.qcow2,id=drive1,if=none,index=1,werror=report",
|
||||
"-device",
|
||||
"virtio-blk-pci,drive=drive1",
|
||||
]
|
||||
machine = create_machine(start_command=" ".join(start_command), **kwargs)
|
||||
driver.machines.append(machine)
|
||||
return machine
|
||||
machine.succeed("lsblk >&2")
|
||||
|
||||
print(machine.succeed("tty"))
|
||||
machine.succeed("umask 066; echo > /tmp/age.key")
|
||||
permission = machine.succeed("stat -c %a /tmp/age.key").strip()
|
||||
assert permission == "600", f"expected permission 600 on /tmp/age.key, got {permission}"
|
||||
|
||||
machine.succeed("${disko}/bin/disko-install --disk main /dev/vdb --extra-files /tmp/age.key /var/lib/secrets/age.key --flake ${../..}#testmachine")
|
||||
# test idempotency
|
||||
machine.succeed("${disko}/bin/disko-install --mode mount --disk main /dev/vdb --flake ${../..}#testmachine")
|
||||
machine.shutdown()
|
||||
|
||||
new_machine = create_test_machine(oldmachine=machine, name="after_install")
|
||||
new_machine.start()
|
||||
name = new_machine.succeed("hostname").strip()
|
||||
assert name == "disko-machine", f"expected hostname 'disko-machine', got {name}"
|
||||
permission = new_machine.succeed("stat -c %a /var/lib/secrets/age.key").strip()
|
||||
assert permission == "600", f"expected permission 600 on /var/lib/secrets/age.key, got {permission}"
|
||||
'';
|
||||
}
|
||||
Reference in New Issue
Block a user