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/flake.nix b/flake.nix index ab15a11..4be9c83 100644 --- a/flake.nix +++ b/flake.nix @@ -58,23 +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; }; - shellcheck = pkgs.runCommand "shellcheck" - { - nativeBuildInputs = [ pkgs.shellcheck ]; - } '' - 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; }; - }; + shellcheck = pkgsUnstable.runCommand "shellcheck" + { + nativeBuildInputs = [ pkgsUnstable.shellcheck ]; + } '' + 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; }; }; 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.* 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"; + }; +} 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 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 ];