Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

macOS support for NixOS tests #282401

Merged
merged 21 commits into from
Mar 2, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions nixos/lib/testing/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ let
./legacy.nix
./meta.nix
./name.nix
./macos-host.nix
./network.nix
./nodes.nix
./pkgs.nix
Expand Down
18 changes: 18 additions & 0 deletions nixos/lib/testing/macos-host.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{ config, lib, hostPkgs, ... }:

{
config = lib.mkIf hostPkgs.stdenv.hostPlatform.isDarwin {
defaults = {
# On non-darwin, mounting the whole nix store from the host is the default because
# this generally makes rebuilds of the VMs faster and the VMs smaller, while reducing
# disk I/O.
# However, on macOS it currently leads to many crashing guest processes.
virtualisation.useNixStoreImage = true;
Gabriella439 marked this conversation as resolved.
Show resolved Hide resolved

# Without this, the store image uses "raw" instead of "qcow2" and
# that throws some errors on macOS on startup of the VM
# TODO: remove when `raw` errors are fixed.
Gabriella439 marked this conversation as resolved.
Show resolved Hide resolved
virtualisation.writableStore = true;
};
};
}
23 changes: 22 additions & 1 deletion nixos/lib/testing/nodes.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,25 @@ let
types
;

inherit (hostPkgs) hostPlatform pkgsNative;

guestPkgs =
if hostPlatform.isLinux
then hostPkgs
else
let
hostToGuest = {
"x86_64-darwin" = pkgsNative.gnu64;
"aarch64-darwin" = pkgsNative.aarch64-multiplatform;
};

supportedHosts = lib.concatStringsSep ", " (lib.attrNames hostToGuest);

message =
"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}";
in
hostToGuest.${hostPlatform.system} or (throw message);

baseOS =
import ../eval-config.nix {
inherit lib;
Expand All @@ -27,13 +46,15 @@ let
({ config, ... }:
{
virtualisation.qemu.package = testModuleArgs.config.qemu.package;
virtualisation.host.pkgs = hostPkgs;
Gabriella439 marked this conversation as resolved.
Show resolved Hide resolved
nixpkgs.pkgs = guestPkgs;
Gabriella439 marked this conversation as resolved.
Show resolved Hide resolved
})
({ options, ... }: {
key = "nodes.nix-pkgs";
config = optionalAttrs (!config.node.pkgsReadOnly) (
mkIf (!options.nixpkgs.pkgs.isDefined) {
# TODO: switch to nixpkgs.hostPlatform and make sure containers-imperative test still evaluates.
nixpkgs.system = hostPkgs.stdenv.hostPlatform.system;
nixpkgs.system = hostPlatform.system;
Gabriella439 marked this conversation as resolved.
Show resolved Hide resolved
}
);
})
Expand Down
4 changes: 3 additions & 1 deletion nixos/lib/testing/run.nix
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ in
rawTestDerivation = hostPkgs.stdenv.mkDerivation {
name = "vm-test-run-${config.name}";

requiredSystemFeatures = [ "kvm" "nixos-test" ];
requiredSystemFeatures = [ "nixos-test" ]
++ lib.optionals hostPkgs.stdenv.hostPlatform.isLinux [ "kvm" ]
++ lib.optionals hostPkgs.stdenv.hostPlatform.isDarwin [ "apple-virt" ];

buildCommand = ''
mkdir -p $out
Expand Down
1 change: 1 addition & 0 deletions pkgs/top-level/release-attrpaths-superset.nix
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ let
pkgsMusl = true;
pkgsStatic = true;
pkgsCross = true;
pkgsNative = true;
pkgsi686Linux = true;
};

Expand Down
15 changes: 15 additions & 0 deletions pkgs/top-level/stage.nix
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,25 @@ let
# that target system. For instance, pkgsCross.raspberryPi.hello,
# will refer to the "hello" package built for the ARM6-based
# Raspberry Pi.
#
# This is essentially the same thing as pkgsNative except for crossSystem
# instead of localSystem.
pkgsCross = lib.mapAttrs (n: crossSystem:
nixpkgsFun { inherit crossSystem; })
lib.systems.examples;

# This maps each entry in lib.systems.examples to its own package set where
# packages are built and run on that system. For example,
# pkgsNative.x86_64-linux.hello will refer to the "hello" package bult for
Gabriella439 marked this conversation as resolved.
Show resolved Hide resolved
# x86_64-linux.
#
# This is essentially the same thing as pkgsCross except for localSystem
# instead of crossSystem.
pkgsNative =
lib.mapAttrs
(n: localSystem: nixpkgsFun { inherit localSystem; })
lib.systems.examples;

pkgsLLVM = nixpkgsFun {
overlays = [
(self': super': {
Expand Down
Loading