mirror of
https://github.com/numtide/nixos-anywhere.git
synced 2024-09-11 13:15:44 +03:00
modularized nixos tests using new nixos test interface
This commit is contained in:
parent
9b29fd7ee0
commit
b0d9b17dc0
13
flake.nix
13
flake.nix
@ -29,15 +29,14 @@
|
||||
checks.x86_64-linux =
|
||||
let
|
||||
pkgs = nixpkgs.legacyPackages.x86_64-linux;
|
||||
inputs = {
|
||||
inherit pkgs;
|
||||
inherit (disko.nixosModules) disko;
|
||||
kexec-installer = "${nixos-images.packages.${pkgs.system}.kexec-installer-nixos-unstable}/nixos-kexec-installer-${pkgs.stdenv.hostPlatform.system}.tar.gz";
|
||||
};
|
||||
in
|
||||
{
|
||||
from-nixos = import ./tests/from-nixos.nix {
|
||||
inherit pkgs;
|
||||
disko = disko.nixosModules.disko;
|
||||
kexec-installer = "${nixos-images.packages.${pkgs.system}.kexec-installer-nixos-unstable}/nixos-kexec-installer-${pkgs.stdenv.hostPlatform.system}.tar.gz";
|
||||
makeTest = import (pkgs.path + "/nixos/tests/make-test-python.nix");
|
||||
eval-config = import (pkgs.path + "/nixos/lib/eval-config.nix");
|
||||
};
|
||||
from-nixos = import ./tests/from-nixos.nix inputs;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
@ -1,97 +1,8 @@
|
||||
{ pkgs ? import <nixpkgs> {}
|
||||
, makeTest ? import <nixpkgs/nixos/tests/make-test-python.nix>
|
||||
, eval-config ? import <nixpkgs/nixos/lib/eval-config.nix>
|
||||
, disko ? "${builtins.fetchTarball "https://github.com/nix-community/disko/archive/master.tar.gz"}/module.nix"
|
||||
, kexec-installer ? builtins.fetchurl "https://github.com/nix-community/nixos-images/releases/download/nixos-unstable/nixos-kexec-installer-${pkgs.stdenv.hostPlatform.system}.tar.gz"
|
||||
, ... }:
|
||||
let
|
||||
systemToInstall = { modulesPath, ... }: {
|
||||
imports = [
|
||||
disko
|
||||
(modulesPath + "/testing/test-instrumentation.nix")
|
||||
(modulesPath + "/profiles/qemu-guest.nix")
|
||||
(modulesPath + "/profiles/minimal.nix")
|
||||
];
|
||||
networking.hostName = "nixos-remote";
|
||||
documentation.enable = false;
|
||||
hardware.enableAllFirmware = false;
|
||||
networking.hostId = "8425e349"; # from profiles/base.nix, needed for zfs
|
||||
boot.zfs.devNodes = "/dev/disk/by-uuid"; # needed because /dev/disk/by-id is empty in qemu-vms
|
||||
boot.loader.grub.devices = [ "/dev/vda" ];
|
||||
disko.devices = {
|
||||
disk = {
|
||||
vda = {
|
||||
device = "/dev/vda";
|
||||
type = "disk";
|
||||
content = {
|
||||
type = "table";
|
||||
format = "gpt";
|
||||
partitions = [
|
||||
{
|
||||
name = "boot";
|
||||
type = "partition";
|
||||
start = "0";
|
||||
end = "1M";
|
||||
part-type = "primary";
|
||||
flags = ["bios_grub"];
|
||||
}
|
||||
{
|
||||
type = "partition";
|
||||
name = "ESP";
|
||||
start = "1MiB";
|
||||
end = "100MiB";
|
||||
bootable = true;
|
||||
content = {
|
||||
type = "filesystem";
|
||||
format = "vfat";
|
||||
mountpoint = "/boot";
|
||||
};
|
||||
}
|
||||
{
|
||||
name = "root";
|
||||
type = "partition";
|
||||
start = "100MiB";
|
||||
end = "100%";
|
||||
part-type = "primary";
|
||||
bootable = true;
|
||||
content = {
|
||||
type = "filesystem";
|
||||
format = "ext4";
|
||||
mountpoint = "/";
|
||||
};
|
||||
}
|
||||
];
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
evaledSystem = eval-config {
|
||||
modules = [ systemToInstall ];
|
||||
system = "x86_64-linux";
|
||||
};
|
||||
in
|
||||
makeTest {
|
||||
(import ./lib/test-base.nix) {
|
||||
name = "nixos-remote";
|
||||
nodes = {
|
||||
installer = {
|
||||
documentation.enable = false;
|
||||
environment.etc.sshKey = {
|
||||
source = ./ssh-keys/ssh;
|
||||
mode = "0600";
|
||||
};
|
||||
programs.ssh.startAgent = true;
|
||||
system.extraDependencies = [
|
||||
evaledSystem.config.system.build.disko
|
||||
evaledSystem.config.system.build.toplevel
|
||||
];
|
||||
};
|
||||
installed = {
|
||||
virtualisation.memorySize = 4096;
|
||||
documentation.enable = false;
|
||||
services.openssh.enable = true;
|
||||
users.users.root.openssh.authorizedKeys.keyFiles = [ ./ssh-keys/ssh.pub ];
|
||||
};
|
||||
installer = ./modules/installer.nix;
|
||||
installed = ./modules/installed.nix;
|
||||
};
|
||||
testScript = ''
|
||||
def create_test_machine(oldmachine=None, args={}): # taken from <nixpkgs/nixos/tests/installer.nix>
|
||||
@ -103,7 +14,6 @@ makeTest {
|
||||
} | args)
|
||||
driver.machines.append(machine)
|
||||
return machine
|
||||
|
||||
start_all()
|
||||
installed.wait_for_unit("sshd.service")
|
||||
installer.succeed("mkdir -p /tmp/extra-files/var/lib/secrets")
|
||||
@ -114,9 +24,9 @@ makeTest {
|
||||
${../nixos-remote} \
|
||||
--no-ssh-copy-id \
|
||||
--debug \
|
||||
--kexec ${kexec-installer} \
|
||||
--kexec /etc/nixos-remote/kexec-installer \
|
||||
--extra-files /tmp/extra-files \
|
||||
--store-paths ${toString evaledSystem.config.system.build.disko} ${toString evaledSystem.config.system.build.toplevel} \
|
||||
--store-paths /etc/nixos-remote/disko /etc/nixos-remote/system-to-install \
|
||||
root@installed >&2
|
||||
""")
|
||||
installed.shutdown()
|
||||
@ -127,7 +37,4 @@ makeTest {
|
||||
content = new_machine.succeed("cat /var/lib/secrets/key").strip()
|
||||
assert "value" == content, f"secret does not have expected value: {content}"
|
||||
'';
|
||||
} {
|
||||
pkgs = pkgs;
|
||||
system = pkgs.system;
|
||||
}
|
||||
|
14
tests/lib/test-base.nix
Normal file
14
tests/lib/test-base.nix
Normal file
@ -0,0 +1,14 @@
|
||||
test:
|
||||
{ pkgs ? import <nixpkgs> {}, ... } @ args:
|
||||
let
|
||||
inherit (pkgs) lib;
|
||||
nixos-lib = import (pkgs.path + "/nixos/lib") {};
|
||||
in
|
||||
(nixos-lib.runTest {
|
||||
hostPkgs = pkgs;
|
||||
# speed-up evaluation
|
||||
defaults.documentation.enable = lib.mkDefault false;
|
||||
# to accept external dependencies such as disko
|
||||
node.specialArgs.inputs = args;
|
||||
imports = [ test ];
|
||||
}).config.result
|
5
tests/modules/installed.nix
Normal file
5
tests/modules/installed.nix
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
virtualisation.memorySize = 4096;
|
||||
services.openssh.enable = true;
|
||||
users.users.root.openssh.authorizedKeys.keyFiles = [ ./ssh-keys/ssh.pub ];
|
||||
}
|
19
tests/modules/installer.nix
Normal file
19
tests/modules/installer.nix
Normal file
@ -0,0 +1,19 @@
|
||||
{ config, lib, pkgs, inputs, ... }:
|
||||
let
|
||||
disko = inputs.disko; #or "${builtins.fetchTarball "https://github.com/nix-community/disko/archive/master.tar.gz"}/module.nix";
|
||||
kexec-installer = inputs.kexec-installer; # or builtins.fetchurl "https://github.com/nix-community/nixos-images/releases/download/nixos-unstable/nixos-kexec-installer-${pkgs.stdenv.hostPlatform.system}.tar.gz";
|
||||
system-to-install = pkgs.nixos [
|
||||
./system-to-install.nix
|
||||
disko
|
||||
];
|
||||
in
|
||||
{
|
||||
programs.ssh.startAgent = true;
|
||||
|
||||
environment.etc = {
|
||||
sshKey = { source = ./ssh-keys/ssh; mode = "0600"; };
|
||||
"nixos-remote/disko".source = system-to-install.config.system.build.disko;
|
||||
"nixos-remote/system-to-install".source = system-to-install.config.system.build.toplevel;
|
||||
"nixos-remote/kexec-installer".source = kexec-installer;
|
||||
};
|
||||
}
|
60
tests/modules/system-to-install.nix
Normal file
60
tests/modules/system-to-install.nix
Normal file
@ -0,0 +1,60 @@
|
||||
{modulesPath, self, ...}: {
|
||||
imports = [
|
||||
(modulesPath + "/testing/test-instrumentation.nix")
|
||||
(modulesPath + "/profiles/qemu-guest.nix")
|
||||
(modulesPath + "/profiles/minimal.nix")
|
||||
];
|
||||
networking.hostName = "nixos-remote";
|
||||
documentation.enable = false;
|
||||
hardware.enableAllFirmware = false;
|
||||
networking.hostId = "8425e349"; # from profiles/base.nix, needed for zfs
|
||||
boot.zfs.devNodes = "/dev/disk/by-uuid"; # needed because /dev/disk/by-id is empty in qemu-vms
|
||||
boot.loader.grub.devices = ["/dev/vda"];
|
||||
disko.devices = {
|
||||
disk = {
|
||||
vda = {
|
||||
device = "/dev/vda";
|
||||
type = "disk";
|
||||
content = {
|
||||
type = "table";
|
||||
format = "gpt";
|
||||
partitions = [
|
||||
{
|
||||
name = "boot";
|
||||
type = "partition";
|
||||
start = "0";
|
||||
end = "1M";
|
||||
part-type = "primary";
|
||||
flags = ["bios_grub"];
|
||||
}
|
||||
{
|
||||
type = "partition";
|
||||
name = "ESP";
|
||||
start = "1MiB";
|
||||
end = "100MiB";
|
||||
bootable = true;
|
||||
content = {
|
||||
type = "filesystem";
|
||||
format = "vfat";
|
||||
mountpoint = "/boot";
|
||||
};
|
||||
}
|
||||
{
|
||||
name = "root";
|
||||
type = "partition";
|
||||
start = "100MiB";
|
||||
end = "100%";
|
||||
part-type = "primary";
|
||||
bootable = true;
|
||||
content = {
|
||||
type = "filesystem";
|
||||
format = "ext4";
|
||||
mountpoint = "/";
|
||||
};
|
||||
}
|
||||
];
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
Loading…
Reference in New Issue
Block a user