From e6bc1576ca045f13b2133e4164237d1c2c647b41 Mon Sep 17 00:00:00 2001 From: Ajeet D'Souza <98ajeet@gmail.com> Date: Mon, 11 Apr 2022 03:58:35 +0530 Subject: [PATCH] Use `target_nix` when running xtasks in Nix --- .gitignore | 1 + xtask/src/main.rs | 12 +++++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 89b1201..887d2ae 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ # Compiled files and executables debug/ target/ +target_nix/ # Backup files generated by rustfmt **/*.rs.bk diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 63df538..69df33d 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -8,11 +8,10 @@ use std::path::PathBuf; use std::process::{self, Command}; fn main() -> Result<()> { - let nix_enabled = enable_nix(); - let dir = PathBuf::from(env!("CARGO_MANIFEST_DIR")); let dir = dir.parent().with_context(|| format!("could not find workspace root: {}", dir.display()))?; env::set_current_dir(dir).with_context(|| format!("could not set current directory: {}", dir.display()))?; + let nix_enabled = enable_nix(); let app = App::parse(); match app { @@ -147,8 +146,11 @@ fn enable_nix() -> bool { println!("Detected Nix in environment, re-running in Nix."); let args = env::args(); let cmd = shell_words::join(args); - let mut nix_path = PathBuf::from(env!("CARGO_MANIFEST_DIR")); - nix_path.push("../shell.nix"); - let status = Command::new("nix-shell").args(&["--pure", "--run", &cmd, "--"]).arg(nix_path).status().unwrap(); + + let status = Command::new("nix-shell") + .args(&["--pure", "--run", &cmd, "--", "shell.nix"]) + .env("CARGO_TARGET_DIR", "target_nix") + .status() + .unwrap(); process::exit(status.code().unwrap_or(1)); }