···1414 types
1515 ;
16161717+ inherit (hostPkgs) hostPlatform;
1818+1919+ guestSystem =
2020+ if hostPlatform.isLinux
2121+ then hostPlatform.system
2222+ else
2323+ let
2424+ hostToGuest = {
2525+ "x86_64-darwin" = "x86_64-linux";
2626+ "aarch64-darwin" = "aarch64-linux";
2727+ };
2828+2929+ supportedHosts = lib.concatStringsSep ", " (lib.attrNames hostToGuest);
3030+3131+ message =
3232+ "NixOS Test: don't know which VM guest system to pair with VM host system: ${hostPlatform.system}. Perhaps you intended to run the tests on a Linux host, or one of the following systems that may run NixOS tests: ${supportedHosts}";
3333+ in
3434+ hostToGuest.${hostPlatform.system} or (throw message);
3535+1736 baseOS =
1837 import ../eval-config.nix {
1938 inherit lib;
···2746 ({ config, ... }:
2847 {
2948 virtualisation.qemu.package = testModuleArgs.config.qemu.package;
4949+ virtualisation.host.pkgs = hostPkgs;
3050 })
3151 ({ options, ... }: {
3252 key = "nodes.nix-pkgs";
3353 config = optionalAttrs (!config.node.pkgsReadOnly) (
3454 mkIf (!options.nixpkgs.pkgs.isDefined) {
3555 # TODO: switch to nixpkgs.hostPlatform and make sure containers-imperative test still evaluates.
3636- nixpkgs.system = hostPkgs.stdenv.hostPlatform.system;
5656+ nixpkgs.system = guestSystem;
3757 }
3858 );
3959 })
+5-1
nixos/lib/testing/pkgs.nix
···22{
33 config = {
44 # default pkgs for use in VMs
55- _module.args.pkgs = hostPkgs;
55+ _module.args.pkgs =
66+ # TODO: deprecate it everywhere; not just on darwin. Throw on darwin?
77+ lib.warnIf hostPkgs.stdenv.hostPlatform.isDarwin
88+ "Do not use the `pkgs` module argument in tests you want to run on darwin. It is ambiguous, and many tests are broken because of it. If you need to use a package on the VM host, use `hostPkgs`. Otherwise, use `config.node.pkgs`, or `config.nodes.<name>.nixpkgs.pkgs`."
99+ hostPkgs;
610711 defaults = {
812 # TODO: a module to set a shared pkgs, if options.nixpkgs.* is untouched by user (highestPrio) */
···243243 };
244244 } else throw "x86_64 Darwin package set can only be used on Darwin systems.";
245245246246+ # If already linux: the same package set unaltered
247247+ # Otherwise, return a natively built linux package set for the current cpu architecture string.
248248+ # (ABI and other details will be set to the default for the cpu/os pair)
249249+ pkgsLinux =
250250+ if stdenv.hostPlatform.isLinux
251251+ then self
252252+ else nixpkgsFun {
253253+ localSystem = lib.systems.elaborate "${stdenv.hostPlatform.parsed.cpu.name}-linux";
254254+ };
255255+246256 # Extend the package set with zero or more overlays. This preserves
247257 # preexisting overlays. Prefer to initialize with the right overlays
248258 # in one go when calling Nixpkgs, for performance and simplicity.