macOS support for running NixOS tests

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 like pkgs.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.

15 Likes

Thank you! Is there an issue to follow for being able to build NixOS tests on darwin, please?

That’s darwin.linux-builder:

I’m not sure if there’s a better solution than that. I’m not aware of anything else in the works.

1 Like

Something that’s worked great for me is: https://orbstack.dev/

It can spin up a lightweight and fast NixOS VM on macOS with really good integration between the systems and the dev spent a lot of time making it performant.

2 Likes

Worth noting that, like Docker Desktop that it claims to replace, it’s not actually free to use when you need it for commercial purposes. You’re expected to use a paid license then, and so it’s not very apples-to-apples in this thread, however much polish and ergonomics it may seem to offer. “Will they actually enforce that” is not a particularly stable foundation to move forward with and many employers would forbid it on that basis.

1 Like

Can we use runInLinuxVM to build it?

1 Like