Conversation
YorikSar
left a comment
There was a problem hiding this comment.
Thanks a lot for tackling this! I couldn't find all ends where hostPkgs needs to be pulled through.
I've tried running nix build -L .#nixosTests.doas with --system aarch64-darwin and --system x86_64-darwin. It worked fine with aarch64 and expectedly broke on x86_64. I'm on M1 Mac and QEMU command line currently doesn't support running non-native architecture (needs some tweaks, if that's possible). Would it be possible to warn user about this somehow?
I've also tried running boot.uefiUsb, but Nix segfaults on evaluation on my machine for some reason.
Would it be possible to add some of these tests on Hydra, so that we can be sure that this will not get broken in the future?
nixos/lib/testing/run.nix
Outdated
There was a problem hiding this comment.
I don't think we need additional flag for this. hvf is always available on Darwin, I don't think there's any hardware platform left that doesn't support it.
On the other hand, it would be good to allow to run tests even in plain emulation. It will be slow, but will still allow to test locally.
There was a problem hiding this comment.
I know some people virtualize macOS on apple hardware in order to make their build farm setup reproducible.
It seems unlikely that nested virtualization would be available on such VMs.
2c210d3 to
e39a5ef
Compare
| else val; | ||
| handleTest = path: args: | ||
| discoverTests (import path ({ inherit system pkgs; } // args)); | ||
| discoverTests (lazyFunction (import path) ({ inherit system pkgs hostPkgs; } // args)); |
There was a problem hiding this comment.
This silently ignores make-test-python.nix-based runners that don't pass hostPkgs through, which has the effect of running the test on a linux remote builder.
|
I've removed the cross compilation changes, which I wasn't confident about. However I did leave the preliminary support for running NixOS tests using cross-compiled pkgs in place. |
I don't know about what can be tweaked and I have no ambition to research this (sorry). A warning could be added if we're confident that this will never be supported, but until we're confident I don't want to discourage anyone from picking up where I/we left off.
I would think so and this is on the todo list. 👍 EDIT: elaborated that a bit |
|
Is it possible to use { inputs.nixpkgs.url =
"github:NixOS/nixpkgs/e39a5efc4504099194032dfabdf60a0c4c78f181";
outputs = { nixpkgs, ... }: {
checks.aarch64-darwin.default =
nixpkgs.legacyPackages.aarch64-darwin.nixosTest {
name = "test";
nodes.machine.virtualisation.host.pkgs =
nixpkgs.legacyPackages.aarch64-darwin;
testScript = "";
};
};
}… but that fails with: |
| systemArgs = | ||
| if stdenv.hostPlatform.isLinux && (stdenv.buildPlatform.isLinux || stdenv.buildPlatform.isDarwin) | ||
| then { | ||
| hostPkgs = pkgs.buildPackages; | ||
| pkgs = pkgs; | ||
| system = stdenv.hostPlatform.system; | ||
| } | ||
| else if stdenv.hostPlatform.isDarwin && stdenv.buildPlatform.isDarwin | ||
| then | ||
| # In the context of a normal darwin compile, repurpose nixosTests as a | ||
| # non-cross build. This requires a "remote" builder such as a local | ||
| # Linux VM, but all VM hosting happens on darwin. | ||
| let linuxSystem = "${stdenv.buildPlatform.parsed.cpu.name}-linux"; | ||
| in { | ||
| hostPkgs = pkgs; | ||
| pkgs = import ../.. { inherit config overlays; system = linuxSystem; }; | ||
| system = linuxSystem; | ||
| } | ||
| else throw "Don't know how to configure NixOS for VM host ${stdenv.buildPlatform.system} and/or VM guest ${stdenv.hostPlatform.system} built on ${stdenv.buildPlatform.system}"; |
There was a problem hiding this comment.
This logic is useful in other places, so it should be factored or moved to a common location, such as the nixos/lib/testing/pkgs.nix module.
There was a problem hiding this comment.
How about pkgsLinux (in pkgs)
It doesn't have a good reason not to, but the immediate problem is that doesn't let you set anything related to either It should probably the logic I've highlighted in my previous comment in one way or another. In your example, perhaps you might get away with setting |
|
That works! The following modified version built for me: { inputs.nixpkgs.url =
"github:NixOS/nixpkgs/e39a5efc4504099194032dfabdf60a0c4c78f181";
outputs = { nixpkgs, ... }: {
checks.aarch64-darwin.default =
nixpkgs.legacyPackages.aarch64-darwin.nixosTest {
name = "test";
nodes.machine = {
nixpkgs.pkgs = nixpkgs.legacyPackages.aarch64-linux.pkgs;
virtualisation.host.pkgs =
nixpkgs.legacyPackages.aarch64-darwin;
};
testScript = "";
};
};
} |
|
Oh and |
|
@Gabriella439 I tried building your example flake on an M1 but getting the following error: nix build .#checks.aarch64-darwin.default
error: a 'aarch64-darwin' with features {hvf, nixos-test} is required to build '/nix/store/icqc6g8lf1f1lnl1dzipfaw5rlmp4vsx-vm-test-run-test.drv', but I am a 'aarch64-darwin' with features {benchmark, big-parallel, nixos-test}(currently on macOS 12.4) Is there any other setup necessary to get |
|
Oh yeah, I had to also add this to my |
Ah thanks so much! I did try this before, but the option was being ignored when put in |
|
Closes NixOS#193336 Closes NixOS#261694 Related to 108984 This pull request is a composite of the changes from NixOS#193336 and also NixOS#261694, with some changes of my own that I made. The goal here was to get the following flake to build and run on `aarch64-darwin`: ```nix { inputs.nixpkgs.url = <this branch>; outputs = { nixpkgs, ... }: { checks.aarch64-darwin.default = nixpkgs.legacyPackages.aarch64-darwin.nixosTest { name = "test"; nodes.machine = { }; testScript = ""; }; }; } ``` … and after this change it does. There's no longer a need for the user to set `nodes.*.nixpkgs.pkgs` or `nodes.*.virtualisation.host.pkgs` as the correct values are inferred from the host system. This change is spiritually much closer to the approach in NixOS#261694 than the approach in NixOS#193336. However, I still made a few changes compared to NixOS#261694: - I didn't include the change to increase `ulimit` I think this change was questionable because I feel like a script provided by Nixpkgs shouldn't be tinkering with the user's ambient `ulimit` settings. - I named the required system feature `hvf` instead of `apple-virt` I preferred the `hvf` system feature name chosen by NixOS#193336. - I didn't use the `node.pkgs` setting to set `nodes.*.nixpkgs.pkgs` That does not work, based on my testing, but setting the same thing in `nixos/lib/testing/nodes.nix` does work. - I created a `pkgsLocal` helper This is based on the feedback from @roberth here: https://github.com/NixOS/nixpkgs/pull/261694/files#r1365443955 … and is similar in spirit to `pkgsCross`.
Description of changes
Towards #108984
I had to add
lazyFunctionin order to half-supportmake-test-python.nixcalls which don't passhostPkgsalong.All tests should be migrated to use the simpler
runTestIMO.Draft because this needs testing and validation, but I don't have much time to spend on this. Figured I'd dump my knowledge in the form of a draft PR (and because I've changed things #191540).
TODO
nixos.tests.simpleand test-framework testing tests?)nixosTests.nixos-test-runnersuite (categorize tests withrecurseIntoAttrs)nixos/lib/testing. ThenixosTestssystem logic is also useful there.Things done
sandbox = trueset innix.conf? (See Nix manual)nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/)nixos/doc/manual/md-to-db.shto update generated release notes