From 0bd625f4ebe6e2d08fe12b8f51d91d62d49906a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Wed, 18 Sep 2024 16:31:09 +0200 Subject: [PATCH 1/5] add nixos-facter to installer --- flake.lock | 6 +++--- nix/installer.nix | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/flake.lock b/flake.lock index d463e7a..6a48a27 100644 --- a/flake.lock +++ b/flake.lock @@ -18,11 +18,11 @@ }, "nixos-unstable": { "locked": { - "lastModified": 1725448034, - "narHash": "sha256-YWbVeDERbIHAEQCtDtUunHYUNH31ReIdJIP8juXfdpM=", + "lastModified": 1726590405, + "narHash": "sha256-mDxHh5vQyBTjNKkp+l1/WL6cEDOjxyEQxv2c+dnw8Fg=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "9b40840066f93767bb528810ea7dc9caacd8997f", + "rev": "513193ba87b70f4d4e4d892f43fac30af286861b", "type": "github" }, "original": { diff --git a/nix/installer.nix b/nix/installer.nix index 9e2e325..740567a 100644 --- a/nix/installer.nix +++ b/nix/installer.nix @@ -30,7 +30,8 @@ pkgs.jq # for copying extra files of nixos-anywhere pkgs.rsync - ]; + # alternative to nixos-generate-config + ] ++ lib.optional (pkgs.lib.versionAtLeast lib.version "24.11") pkgs.nixos-facter; imports = [ ./nix-settings.nix From 41eb99f3cc96e7c3761ffcfcbeaa5fad8311c014 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Wed, 18 Sep 2024 16:40:21 +0200 Subject: [PATCH 2/5] remove obsolete garnix.yaml --- garnix.yaml | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 garnix.yaml diff --git a/garnix.yaml b/garnix.yaml deleted file mode 100644 index 0c8008a..0000000 --- a/garnix.yaml +++ /dev/null @@ -1,5 +0,0 @@ -builds: - include: - - '*.x86_64-linux.*' - - '*.aarch64-linux.*' - - nixosConfigurations.* From 8e077ae20b642460fba5bd91e4f7196293c06c8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Wed, 18 Sep 2024 16:41:57 +0200 Subject: [PATCH 3/5] kexec-installer: use pkgs.testers to define test --- nix/kexec-installer/test.nix | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/nix/kexec-installer/test.nix b/nix/kexec-installer/test.nix index 6abac33..72360aa 100644 --- a/nix/kexec-installer/test.nix +++ b/nix/kexec-installer/test.nix @@ -3,14 +3,7 @@ , kexecTarball }: -let - makeTest = import (pkgs.path + "/nixos/tests/make-test-python.nix"); - makeTest' = args: makeTest args { - inherit pkgs; - inherit (pkgs) system; - }; -in -makeTest' { +pkgs.testers.runNixOSTest { name = "kexec-installer"; meta = with pkgs.lib.maintainers; { maintainers = [ mic92 ]; From 28d4a57b3aa668046773a41bd01860e9a0aec833 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Wed, 18 Sep 2024 17:21:05 +0200 Subject: [PATCH 4/5] add boot tests for iso image --- flake.nix | 10 +++- nix/image-installer/tests.nix | 105 ++++++++++++++++++++++++++++++++++ 2 files changed, 112 insertions(+), 3 deletions(-) create mode 100644 nix/image-installer/tests.nix diff --git a/flake.nix b/flake.nix index ab15a11..26f729f 100644 --- a/flake.nix +++ b/flake.nix @@ -64,6 +64,13 @@ kexec-installer-unstable = pkgs.callPackage ./nix/kexec-installer/test.nix { kexecTarball = self.packages.x86_64-linux.kexec-installer-nixos-unstable-noninteractive; }; + inherit (pkgs.callPackages ./nix/image-installer/tests.nix { + nixpkgs = nixos-unstable; + nixosModules = self.nixosModules; + }) uefi-cdrom uefi-usb bios-cdrom bios-usb; + kexec-installer-stable = nixos-stable.legacyPackages.x86_64-linux.callPackage ./nix/kexec-installer/test.nix { + kexecTarball = self.packages.x86_64-linux.kexec-installer-nixos-stable-noninteractive; + }; shellcheck = pkgs.runCommand "shellcheck" { nativeBuildInputs = [ pkgs.shellcheck ]; @@ -71,9 +78,6 @@ shellcheck ${(pkgs.nixos [self.nixosModules.kexec-installer]).config.system.build.kexecRun} touch $out ''; - kexec-installer-stable = nixos-stable.legacyPackages.x86_64-linux.callPackage ./nix/kexec-installer/test.nix { - kexecTarball = self.packages.x86_64-linux.kexec-installer-nixos-stable-noninteractive; - }; }; in nixos-unstable.lib.recursiveUpdate packages { x86_64-linux = checks; }; diff --git a/nix/image-installer/tests.nix b/nix/image-installer/tests.nix new file mode 100644 index 0000000..031c3e1 --- /dev/null +++ b/nix/image-installer/tests.nix @@ -0,0 +1,105 @@ +{ + pkgs, + lib, + nixpkgs, + nixos, + nixosModules, +}: + +let + testConfig = ( + nixos [ + ( + { modulesPath, ... }: + { + imports = [ + nixosModules.image-installer + "${modulesPath}/testing/test-instrumentation.nix" + ]; + } + ) + ] + ); + iso = testConfig.config.system.build.isoImage; + mkStartCommand = + { + memory ? 2048, + cdrom ? null, + usb ? null, + uefi ? false, + extraFlags ? [ ], + }: + let + qemu-common = import (nixpkgs + "/nixos/lib/qemu-common.nix") { inherit lib pkgs; }; + qemu = qemu-common.qemuBinary pkgs.qemu_test; + + flags = + [ + "-m" + (toString memory) + "-netdev" + "user,id=net0" + "-device" + "virtio-net-pci,netdev=net0" + ] + ++ lib.optionals (cdrom != null) [ + "-cdrom" + cdrom + ] + ++ lib.optionals (usb != null) [ + "-device" + "usb-ehci" + "-drive" + "id=usbdisk,file=${usb},if=none,readonly" + "-device" + "usb-storage,drive=usbdisk" + ] + ++ lib.optionals uefi [ + "-drive" + "if=pflash,format=raw,unit=0,readonly=on,file=${pkgs.OVMF.firmware}" + "-drive" + "if=pflash,format=raw,unit=1,readonly=on,file=${pkgs.OVMF.variables}" + ] + ++ extraFlags; + + flagsStr = lib.concatStringsSep " " flags; + in + "${qemu} ${flagsStr}"; + + makeBootTest = + name: config: + let + startCommand = mkStartCommand config; + in + pkgs.testers.runNixOSTest { + name = "boot-${name}"; + nodes = { }; + testScript = '' + machine = create_machine("${startCommand}") + machine.start() + machine.wait_for_unit("multi-user.target") + machine.succeed("nix store verify --no-trust -r --option experimental-features nix-command /run/current-system") + + machine.shutdown() + ''; + }; +in +{ + uefi-cdrom = makeBootTest "uefi-cdrom" { + uefi = true; + cdrom = "${iso}/iso/nixos-installer-${pkgs.hostPlatform.system}.iso"; + }; + + uefi-usb = makeBootTest "uefi-usb" { + uefi = true; + usb = "${iso}/iso/nixos-installer-${pkgs.hostPlatform.system}.iso"; + }; + + bios-cdrom = makeBootTest "bios-cdrom" { + cdrom = "${iso}/iso/nixos-installer-${pkgs.hostPlatform.system}.iso"; + }; + + bios-usb = makeBootTest "bios-usb" { + usb = "${iso}/iso/nixos-installer-${pkgs.hostPlatform.system}.iso"; + }; +} From dd5f75eec332a774bcebad727eba5d20abace42d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Wed, 18 Sep 2024 17:28:56 +0200 Subject: [PATCH 5/5] add boot tests for iso --- flake.nix | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/flake.nix b/flake.nix index 26f729f..4be9c83 100644 --- a/flake.nix +++ b/flake.nix @@ -58,27 +58,31 @@ packages = forAllSystems (system: nixos-unstable.lib.mapAttrs' (n: nixos-unstable.lib.nameValuePair "package-${n}") self.packages.${system}); checks = let - pkgs = nixos-unstable.legacyPackages.x86_64-linux; + pkgsUnstable = nixos-unstable.legacyPackages.x86_64-linux; + pkgsStable = nixos-stable.legacyPackages.x86_64-linux; + + bootTests = pkgs: channel: suffix: pkgs.lib.mapAttrs' (name: pkgs.lib.nameValuePair "${name}${suffix}") (pkgs.callPackages ./nix/image-installer/tests.nix { + nixpkgs = channel; + nixosModules = self.nixosModules; + }); in { - kexec-installer-unstable = pkgs.callPackage ./nix/kexec-installer/test.nix { + kexec-installer-unstable = pkgsUnstable.callPackage ./nix/kexec-installer/test.nix { kexecTarball = self.packages.x86_64-linux.kexec-installer-nixos-unstable-noninteractive; }; - inherit (pkgs.callPackages ./nix/image-installer/tests.nix { - nixpkgs = nixos-unstable; - nixosModules = self.nixosModules; - }) uefi-cdrom uefi-usb bios-cdrom bios-usb; + kexec-installer-stable = nixos-stable.legacyPackages.x86_64-linux.callPackage ./nix/kexec-installer/test.nix { kexecTarball = self.packages.x86_64-linux.kexec-installer-nixos-stable-noninteractive; }; - shellcheck = pkgs.runCommand "shellcheck" + shellcheck = pkgsUnstable.runCommand "shellcheck" { - nativeBuildInputs = [ pkgs.shellcheck ]; + nativeBuildInputs = [ pkgsUnstable.shellcheck ]; } '' - shellcheck ${(pkgs.nixos [self.nixosModules.kexec-installer]).config.system.build.kexecRun} + shellcheck ${(pkgsUnstable.nixos [self.nixosModules.kexec-installer]).config.system.build.kexecRun} touch $out ''; - }; + } // (bootTests pkgsUnstable nixos-unstable "-nixos-unstable") + // (bootTests pkgsStable nixos-stable "-nixos-stable"); in nixos-unstable.lib.recursiveUpdate packages { x86_64-linux = checks; }; };