From 857f58472f52263a810f3e07a86a6a5e70d32581 Mon Sep 17 00:00:00 2001 From: ThetaSinner Date: Thu, 16 Nov 2023 12:25:40 +0000 Subject: [PATCH] Detect Nix failure due to Git conflict --- src/scaffold/app/nix.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/scaffold/app/nix.rs b/src/scaffold/app/nix.rs index ab6e116fa..0843543c7 100644 --- a/src/scaffold/app/nix.rs +++ b/src/scaffold/app/nix.rs @@ -59,6 +59,23 @@ pub fn setup_nix_developer_environment(dir: &PathBuf) -> ScaffoldResult<()> { )); } + // This is here to catch the issue from this thread https://discourse.nixos.org/t/nix-flakes-nix-store-source-no-such-file-or-directory/17836 + // If you run Scaffolding inside a Git repository when the `nix flake update` will fail. At some point Nix should report this so we don't need + // to worry about it but for now this helps solve a strange error message. + match Command::new("git") + .stdout(Stdio::piped()) + .stderr(Stdio::null()) + .current_dir(dir) + .args(["rev-parse", "--is-inside-work-tree"]) + .output() { + Ok(output) => { + if output.status.success() && output.stdout == b"true\n" { + return Err(ScaffoldError::NixSetupError("- detected that Scaffolding is running inside an existing Git repository, please choose a different location to scaffold".to_string())); + } + }, + Err(_) => {} // Ignore errors, Git isn't necessarily available. + } + println!("Setting up nix development environment..."); add_extra_experimental_features()?;