Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: wrapped nix #114

Merged
merged 1 commit into from
Jun 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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