From 398d06603e16516d4ea353ddca491b0068e7d765 Mon Sep 17 00:00:00 2001 From: eveeifyeve <88671402+Eveeifyeve@users.noreply.github.com> Date: Sun, 28 Sep 2025 22:04:24 +1000 Subject: [PATCH] Add Darwin support to nixos-compose NOTE: This requires you to enable a nix linux builder but this should work the same on mac as linux fixup: issues --- flake.nix | 2 +- src/NixVms.hs | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index 93eddba..594b0e9 100644 --- a/flake.nix +++ b/flake.nix @@ -40,7 +40,7 @@ ]; }); runtimeDeps = [ - pkgs.iproute2 + (if pkgs.stdenv.isLinux then pkgs.iproute2 else pkgs.iproute2mac) pkgs.nix pkgs.openssh pkgs.vde2 diff --git a/src/NixVms.hs b/src/NixVms.hs index 73fcd2c..8a5884d 100644 --- a/src/NixVms.hs +++ b/src/NixVms.hs @@ -14,6 +14,7 @@ import Network.Socket.Free (getFreePort) import Options (VmName (..)) import State import StdLib +import System.Info (os) import System.Directory (createDirectoryIfMissing, listDirectory) import System.Environment (getEnvironment) import System.FilePath (takeDirectory) @@ -52,6 +53,9 @@ listVmsImpl ctx = do Left err -> impossible ctx $ cs err Right (parsed :: [Text]) -> pure $ map VmName parsed +darwinBuilderArgs :: [Text] +darwinBuilderArgs = if os == "darwin" then ["--builders", "/etc/nix/builder_ed25519"] else [""] + buildVmScriptImpl :: Context -> Maybe Handle -> VmName -> IPv4 -> IO (FilePath, Port) buildVmScriptImpl ctx handle vmName ip = do port <- getFreePort @@ -84,6 +88,7 @@ buildVmScriptImpl ctx handle vmName ip = do "--no-link", drvPath <> "^*" ] + <> darwinBuilderArgs ) & Cradle.setWorkingDir (workingDir ctx) & maybe id addStderrHandle handle