From 56c90fef8bca0f4bc3f0e530f789326643fc2fa7 Mon Sep 17 00:00:00 2001 From: warren2k <846021+warren2k@users.noreply.github.com> Date: Sat, 22 Jun 2024 11:05:03 -0400 Subject: [PATCH] fix: wrapped nix Co-authored-by: Shahar "Dawn" Or --- flake.nix | 25 +++++++++++++++++++++---- src/expression/driver.rs | 2 +- src/repl/driver.rs | 2 +- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/flake.nix b/flake.nix index d6183a7..2690451 100644 --- a/flake.nix +++ b/flake.nix @@ -21,13 +21,30 @@ nixpkgs, treefmt-nix, }: let - inherit (nixpkgs.lib) optional mkForce; + inherit (nixpkgs.lib) getExe optional mkForce; in flake-utils.lib.eachDefaultSystem (system: let pkgs = nixpkgs.legacyPackages.${system}; toolchain = fenix.packages.${system}.stable.completeToolchain; craneLib = crane.lib.${system}.overrideToolchain toolchain; - NIX_BIN_DIR = "${nix.packages.${system}.nix}/bin"; + nixDrv = nix.packages.${system}.nix; + + isolatedNix = postfix: + pkgs.symlinkJoin { + name = "isolated-nix${postfix}"; + paths = [nixDrv]; + nativeBuildInputs = [pkgs.makeWrapper]; + postBuild = '' + wrapProgram $out/bin/nix${postfix} \ + --set NIX_CONF_DIR /dev/null \ + --set NIX_USER_CONF_FILES /dev/null \ + --unset NIX_CONFIG + ''; + meta.mainProgram = "nix${postfix}"; + }; + + NIX_CMD_PATH = getExe (isolatedNix ""); + NIX_INSTANTIATE_CMD_PATH = getExe (isolatedNix "-instantiate"); commonArgs = { src = craneLib.cleanCargoSource (craneLib.path ./.); @@ -46,7 +63,7 @@ packages.default = craneLib.buildPackage ( commonArgs // { - inherit cargoArtifacts NIX_BIN_DIR; + inherit cargoArtifacts NIX_CMD_PATH NIX_INSTANTIATE_CMD_PATH; nativeCheckInputs = [pkgs.nix]; # 1. integration tests execute `nix`, which fails creating `/nix/var` # 2. integration tests require `/dev/ptmx` @@ -55,7 +72,7 @@ ); devShells.default = craneLib.devShell { - inherit NIX_BIN_DIR; + inherit NIX_CMD_PATH NIX_INSTANTIATE_CMD_PATH; inputsFrom = [self.packages.${system}.default]; packages = [ toolchain diff --git a/src/expression/driver.rs b/src/expression/driver.rs index 538fab3..18fe91b 100644 --- a/src/expression/driver.rs +++ b/src/expression/driver.rs @@ -71,7 +71,7 @@ impl ExpressionDriver { } async fn spawn_nix(&mut self, example: ExpressionExample) { - let task = tokio::process::Command::new(concat!(env!("NIX_BIN_DIR"), "/nix-instantiate")) + let task = tokio::process::Command::new(env!("NIX_INSTANTIATE_CMD_PATH")) .args(["--expr", "--eval"]) .arg(example.expression) .output(); diff --git a/src/repl/driver.rs b/src/repl/driver.rs index 4e8b1cb..951a14c 100644 --- a/src/repl/driver.rs +++ b/src/repl/driver.rs @@ -135,7 +135,7 @@ impl ReplDriver { async fn spawn(&mut self, id: ExampleId) { let (read_output, write_output) = nix::unistd::pipe().unwrap(); - let child = tokio::process::Command::new(concat!(env!("NIX_BIN_DIR"), "/nix")) + let child = tokio::process::Command::new(env!("NIX_CMD_PATH")) // even though a single `--quiet` would normally disable the pre-prompt message // (at the time of writing `Nix 2.21.1`), two seem to be necessary here. .args(["repl", "--quiet", "--quiet"])