You can now run NixOS tests on macOS using the pkgs.nixosTest
utility.
CAREFULLY NOTE: You still need to build the VM on a Linux machine (e.g.
aarch64-linux
) using something likepkgs.darwin.linux-builder
, but the actual NixOS test will run on locally on your macOS machine (e.g.aarch64-darwin
). So if you get an error message like:error: a 'aarch64-linux' with features {} is required to build '/nix/store/….drv', but I am a 'aarch64-darwin' with features {…}
… then that means you still need a Linux builder
This means that if you have access to a Linux builder you can now run a NixOS test like this one even on macOS:
{ inputs = {
flake-utils.url = "github:numtide/flake-utils/v1.0.0";
nixpkgs.url = "github:NixOS/nixpkgs/master";
};
outputs = { flake-utils, nixpkgs, ... }:
flake-utils.lib.eachDefaultSystem (system: {
checks.default =
nixpkgs.legacyPackages."${system}".nixosTest {
name = "test";
nodes.machine = { };
testScript = ''
print(machine.succeed('echo hello'));
'';
};
});
}
… using nix flake check
.
Thank you to both @roberth and @tfc, who both contributed a lot to getting this working. Also, thank you to my employer, Mercury, for letting me work on taking this across the line.