Fix Nix build by not using Git in Cargo build scripts #3551
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description of Changes
When building under Nix, Git metadata is not available within the sandbox, as we use
lib.cleanSourceon our source directory. This is important because it avoids spurious rebuilds and/or determinism hazards.The build was broken due to our new
spacetime inittemplate system accessing Git metadata in the CLI's build.rsto filter out non-git-tracked files from the templates. The Flake sandbox does this automatically (even without
lib.cleanSource!), so when building under Nix it's unnecessary to do twice. (I remain unconvinced that it's necessary to do in non-Nix builds either, as CI builds should have a clean checkout and local dev builds don't need clean templates, but the behavior was already in master and I didn't feel comfortable removing it.)As an enhancement, I've also found a Nix-ey way to embed our Git commit hash in builds. Previously, builds under Nix had the empty string instead of a commit hash, because we included the
gitCLI tool but scrubbed the necessary metadata. Now, we inject an environment variable from the Nix flake, and don't make thegitCLI tool available at all. This has the convenient upside of allowing Nix builds to referencedirtyRevin builds with a dirty worktree, which should reduce confusion.API and ABI breaking changes
N/a
Expected complexity level and risk
3? I didn't have a strong understanding of what the CLI build script was doing, and to what extent it was doing things intentionally versus for convenience. As such, it's possible that I've inadvertently damaged something load-bearing.
Testing
nix build, ranspacetime init, chose thebasic-rusttemplate, and got a reasonable-looking template instantiation.