Skip to content

Commit

Permalink
Merge pull request #114 from mobusoperandi/nix-no-read-config
Browse files Browse the repository at this point in the history
fix: wrapped nix
  • Loading branch information
warren2k authored Jun 22, 2024
2 parents 629b24a + 56c90fe commit 18109d5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
25 changes: 21 additions & 4 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 ./.);
Expand All @@ -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`
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/expression/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/repl/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand Down

0 comments on commit 18109d5

Please sign in to comment.