Including .git directory in build environment

Hi all!

I’m trying to create a package for a Crystal tool. The source code uses git to read repository metadata and compute a version tag.
Nix/Nix flakes Build environments seem to omit the .gitdirectory from the sources. I understand why(after reading Nix For Lang Packaging - NixOS Wiki), but I assume there is a way to bypass this behavior and include the .gitdirectory in the build environment?


Yes, most git related fetchers understand leaveDotGit.

Using that will cause you a lot of trouble, as every upstream commit will break your FOD, regardless if that commit actually affects you or not.

Instead a more common approach is to put a fake git script into the build environment that reacts on know invocations with predefined responses.

Sadly this approach only works if they use the git CLI, and not if they are reading the .git folder directly.


I’d rather recommend to remove that code and replace it with a hardcode from nix variables.


Yes, you are right, that is what I thought was best, and I’ll probably end up doing that. However, for the quick and easy route for personal use, and for the general case where changing an arbitrary amount of code might not be viable, I wanted to know that this was possible and how. Thanks!

Thanks, that answers it. Things did not click in that the fetcher was responsible for filtering the sources.

Then you can also use

src = ./path/to/project