You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fetchgit with leaveDotGit = true is still not completely deterministic #8567
2.status: stalehttps://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md6.topic: fetchFetchers (e.g. fetchgit, fetchsvn, ...)6.topic: reproducible buildsRun nix-build twice and get the same result.
The hash of the cargo git repository returned by fetchgit has changed twice already, even though the git revision didn't change (see de322b4 and now #8566).
How sad. So it may change even with the same git version?
It'd be interesting to know exactly what in .git/ that changes. But if there is non-determinism for single-threaded git repack of the repo, then I don't know what to do.
Btw, here is the script I used to "prove" that git clones could be deterministic (if anyone wants to play around with it):
It has a copy of the "make_deterministic_repo()" function from nixpkgs and it creates three repos in current dir with the same basename as the script itself.
UPDATE: I mean "make_deterministic_repo" (not ...clone())
As @bjornfor, it would be great if you could get your hands on two versions of the same derivation with different hashes. This might be hard, because sometimes it depends on the upstream (I first had problems when new commits where pushed to the master branch). Maybe a new branch is added, or something like that?
Ok, so I tarred up my local copy of the cargo src tree in my /nix/store (which is supposed to have the old sha256 hash), and then used nix-prefetch-git with --leave-dotGit and --fetch-submodules to clone a new tree to see how they differ. I have verified that nix-prefetch-git returned the same new sha256 hash as mentioned in issue #8566.
The most obvious differences are inside the fetched submodule in src/rust-installer, specifically:
In the old clone, there is a .git/shallow file (which contains a hash). This file doesn't exist in the new clone.
In the new clone, there is a new .git/refs/remotes directory, which itself contains an empty origin subdirectory. The old clone doesn't have these directories.
It seems that there are also differences in the pack files, but I haven't examined these.
Regarding point 1, it seems that the previous fetchgit did a shallow clone of the src/rust-installer submodule, because git log only shows one commit (the last one). However, now it seems to be doing a non-shallow clone of that submodule, because I can see the commit history (but only up to the same commit as in the previous fetchgit).
Neither the cargo derivation nor my nix-prefetch-git command used the deepClone option, they only used leaveDotGit and the option to fetch submodules.
Regarding git, I was using version 2.4.1 when I ran the nix-prefetch-git command.
However, I don't know with which git version my pre-existing cargo source was downloaded with. Apparently, the build logs of fetchgit derivations don't mention the git version...
what's the use case for leaveDotGit = true? It seems one could clone the repository with a normal git clone, then rm -rf the .git folder, and viola, you have a deterministic fetch. What am I missing?
What is causing such non-determinism? Is that we might be downloading separated commit, then later, as the repository is optimized, we might download packed files?
I think this is doable if we do not clone all the branches/tag, but only the one that we care about, and run
git repack -dnA
git gc --prune=now
Otherwise, we would have to white-list the tags / branches that we are interested in.
Also the solution above was suggested by @bjornfor before.
Regarding point 1, it seems that the previous fetchgit did a shallow clone of the src/rust-installer submodule, because git log only shows one commit (the last one). However, now it seems to be doing a non-shallow clone of that submodule, because I can see the commit history (but only up to the same commit as in the previous fetchgit).
Yes, this is an optimization I made a while ago, because otherwise we were pulling full repositories all the time, which is extremely inefficient. I think we can get rid of this limitation when we are downloading a copy of the history, by creating a branch, and making a local non-shared --depth=1 clone of the submodule and replacing the .git, by the one of the cloned version.
There are valid use-cases for leaveDotGit: Extracting information from .git deterministically (i.e. current commit hash) and then manually removing .git before FOD hashing is still deterministic.
These use-cases could be retained more safely by introducing an argument for commands to be run before .git removal though.
Deprecating leaveDotGit in favor of that new argument could perhaps happen as a fetchgit2 as there are other issues with the current incantation too:
That would effectively provide a space to run arbitrary code after checking out the repository, but before removing the .git directory or computing the FOD hash. That would cover all the use cases I'm aware of for leaveDotGit.
Add a deprecation warning to any calls to fetchgit that set leaveDotGit = true. Hopefully anyone who relies on leaveDotGit for a step that happens after the FOD calculation will see that and be able to rewrite their derivations to use the new hook.
Assuming nobody comes up with a use case for leaveDotGit that can't be handled with the new hook, replace the deprecation warning with an error after a release or two.
The obvious alternative would be to find a way to make the .git directory deterministic, but that's clearly a difficult problem. Even if we were to solve it now, FOD hashes would still need updating when the contents of the .git directory change (e.g. as happened in #372784 with Git v2.48). I could also believe we'd need to do more significant work to restore determinism when there are bigger changes, e.g. some of those currently planned for Git v3.0.
I'll add this to my to-do list, but that definitely shouldn't stop anyone else who wants to work on this problem from doing so; my to-do list is long and my time is sadly finite...
That would effectively provide a space to run arbitrary code after checking out the repository, but before removing the .git directory or computing the FOD hash. That would cover all the use cases I'm aware of for leaveDotGit.
That's a cool and simple enough idea. I guess to have a working & practical solution we would need to have a way to fake git commands in, e.g., the build phase of the derivation, otherwise it means that we need to manually patch the code which may be quite unpractical as it requires more maintenance and may be impossible to do when git commands are executed by pre-build binaries. This fake git command could read its argument from a file created in your NIX_PREFETCH_GIT_CHECKOUT_HOOK hook. The user could provide to this hook a list of commands to cache, like git rev-parse HEAD, then we would save the stdout/stderr/return status of the command inside a file (e.g. binary json…), and in the build phase, we would create a fake git binary that checks if its inputs are contained in the binary json file, if so it returns the stdout/stderr/status code, if not it forwards the argument to the original git command.
I'm also thinking that this may even be helpful to deal with derivations that try to download stuff during the build phase (e.g. some npm packages…), so a user could say "cache curl https://foo.com/mybinary" the same way we would cache git rev-parse HEAD. To support commands that download new files like wget, we can improve the binary json format to also include creation of files.
2.status: stalehttps://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md6.topic: fetchFetchers (e.g. fetchgit, fetchsvn, ...)6.topic: reproducible buildsRun nix-build twice and get the same result.
Activity
bjornfor commentedon Jun 30, 2015
How sad. So it may change even with the same git version?
It'd be interesting to know exactly what in .git/ that changes. But if there is non-determinism for single-threaded git repack of the repo, then I don't know what to do.
Btw, here is the script I used to "prove" that git clones could be deterministic (if anyone wants to play around with it):
https://gist.github.com/bjornfor/bb96b09d4bd1a488cd01
It has a copy of the "make_deterministic_repo()" function from nixpkgs and it creates three repos in current dir with the same basename as the script itself.
UPDATE: I mean "make_deterministic_repo" (not ...clone())
madjar commentedon Jun 30, 2015
I feared the day would happen.
As @bjornfor, it would be great if you could get your hands on two versions of the same derivation with different hashes. This might be hard, because sometimes it depends on the upstream (I first had problems when new commits where pushed to the master branch). Maybe a new branch is added, or something like that?
wizeman commentedon Jun 30, 2015
Ok, so I tarred up my local copy of the cargo src tree in my
/nix/store(which is supposed to have the old sha256 hash), and then usednix-prefetch-gitwith--leave-dotGitand--fetch-submodulesto clone a new tree to see how they differ. I have verified thatnix-prefetch-gitreturned the same new sha256 hash as mentioned in issue #8566.This is the resulting diff:
https://gist.github.com/wizeman/291be066b61e591051af
You can find the tarballs with full contents here:
https://dl.dropboxusercontent.com/u/731705/cargo-old.tar.bz2
https://dl.dropboxusercontent.com/u/731705/cargo-new.tar.bz2
wizeman commentedon Jun 30, 2015
The most obvious differences are inside the fetched submodule in
src/rust-installer, specifically:.git/shallowfile (which contains a hash). This file doesn't exist in the new clone..git/refs/remotesdirectory, which itself contains an emptyoriginsubdirectory. The old clone doesn't have these directories.It seems that there are also differences in the pack files, but I haven't examined these.
wizeman commentedon Jun 30, 2015
Regarding point 1, it seems that the previous
fetchgitdid a shallow clone of thesrc/rust-installersubmodule, becausegit logonly shows one commit (the last one). However, now it seems to be doing a non-shallow clone of that submodule, because I can see the commit history (but only up to the same commit as in the previousfetchgit).madjar commentedon Jun 30, 2015
Do you have a way to get the git versions used for both clones? If they differ, a change in the behavior might explain the difference.
jagajaga commentedon Jun 30, 2015
Do you use
--deepClone?wizeman commentedon Jul 1, 2015
Neither the cargo derivation nor my
nix-prefetch-gitcommand used thedeepCloneoption, they only usedleaveDotGitand the option to fetch submodules.Regarding git, I was using version
2.4.1when I ran thenix-prefetch-gitcommand.However, I don't know with which git version my pre-existing
cargosource was downloaded with. Apparently, the build logs offetchgitderivations don't mention the git version...bjornfor commentedon Jul 1, 2015
I grabbed this diff from two repositories at work, cloned at different times (and probably with different git versions):
https://gist.github.com/bjornfor/5e5ad0a03a52cbc6f70b
andrewrk commentedon Jul 16, 2015
what's the use case for
leaveDotGit = true? It seems one could clone the repository with a normalgit clone, thenrm -rfthe .git folder, and viola, you have a deterministic fetch. What am I missing?aflatter commentedon Jul 17, 2015
@andrewrk e.g. some ruby gems use
git ls-filesin their gemspec to define the list of all files in the package.nbp commentedon Jul 17, 2015
What is causing such non-determinism? Is that we might be downloading separated commit, then later, as the repository is optimized, we might download packed files?
I think this is doable if we do not clone all the branches/tag, but only the one that we care about, and run
Otherwise, we would have to white-list the tags / branches that we are interested in.
nbp commentedon Jul 17, 2015
Also the solution above was suggested by @bjornfor before.
Yes, this is an optimization I made a while ago, because otherwise we were pulling full repositories all the time, which is extremely inefficient. I think we can get rid of this limitation when we are downloading a copy of the history, by creating a branch, and making a local non-shared --depth=1 clone of the submodule and replacing the .git, by the one of the cloned version.
wizeman commentedon Jul 21, 2015
It seems that
leaveDotGitstill continues to cause hash mismatches for thecargopackage, making it very hard to maintain.See: de322b4, #8566 and #8862.
84 remaining items
nixos-discourse commentedon Jul 27, 2024
This issue has been mentioned on NixOS Discourse. There might be relevant details there:
https://discourse.nixos.org/t/fetchgit-hash-mismatch-with-qmk-firmware-submodules/49667/2
Scrumplex commentedon Sep 4, 2024
I think
fetchgitshould throw an eval warning referencing this issue whenleaveDotGitis enabled.Additionally, this issue doesn't seem to be documented in https://github.com/NixOS/nixpkgs/blob/43b37c5e92802000e2a988cc6652037b49c06a0e/doc/build-helpers/fetchers.chapter.md#fetchgit-fetchgit
nixos-discourse commentedon Oct 3, 2024
This issue has been mentioned on NixOS Discourse. There might be relevant details there:
https://discourse.nixos.org/t/git-fetcher-with-each-submodule-as-a-separate-deprivation/53861/1
Atemu commentedon Oct 8, 2024
There are valid use-cases for
leaveDotGit: Extracting information from .git deterministically (i.e. current commit hash) and then manually removing .git before FOD hashing is still deterministic.These use-cases could be retained more safely by introducing an argument for commands to be run before .git removal though.
Deprecating
leaveDotGitin favor of that new argument could perhaps happen as afetchgit2as there are other issues with the current incantation too:#347212
fix: support enableGitInfo in hugo
me-and commentedon Jul 16, 2025
Fun!
I'm inclined to:
Make the trick I'm pulling with
NIX_PREFETCH_GIT_CHECKOUT_HOOKin my Nix/Git CI tests into a hook that's more readily exposed and usable.That would effectively provide a space to run arbitrary code after checking out the repository, but before removing the
.gitdirectory or computing the FOD hash. That would cover all the use cases I'm aware of forleaveDotGit.Add a deprecation warning to any calls to
fetchgitthat setleaveDotGit = true. Hopefully anyone who relies onleaveDotGitfor a step that happens after the FOD calculation will see that and be able to rewrite their derivations to use the new hook.Assuming nobody comes up with a use case for
leaveDotGitthat can't be handled with the new hook, replace the deprecation warning with an error after a release or two.The obvious alternative would be to find a way to make the
.gitdirectory deterministic, but that's clearly a difficult problem. Even if we were to solve it now, FOD hashes would still need updating when the contents of the.gitdirectory change (e.g. as happened in #372784 with Git v2.48). I could also believe we'd need to do more significant work to restore determinism when there are bigger changes, e.g. some of those currently planned for Git v3.0.I'll add this to my to-do list, but that definitely shouldn't stop anyone else who wants to work on this problem from doing so; my to-do list is long and my time is sadly finite...
tobiasBora commentedon Jul 17, 2025
That's a cool and simple enough idea. I guess to have a working & practical solution we would need to have a way to fake git commands in, e.g., the build phase of the derivation, otherwise it means that we need to manually patch the code which may be quite unpractical as it requires more maintenance and may be impossible to do when git commands are executed by pre-build binaries. This fake git command could read its argument from a file created in your
NIX_PREFETCH_GIT_CHECKOUT_HOOKhook. The user could provide to this hook a list of commands to cache, likegit rev-parse HEAD, then we would save the stdout/stderr/return status of the command inside a file (e.g. binary json…), and in the build phase, we would create a fakegitbinary that checks if its inputs are contained in the binary json file, if so it returns the stdout/stderr/status code, if not it forwards the argument to the original git command.I'm also thinking that this may even be helpful to deal with derivations that try to download stuff during the build phase (e.g. some npm packages…), so a user could say "cache
curl https://foo.com/mybinary" the same way we would cachegit rev-parse HEAD. To support commands that download new files likewget, we can improve the binary json format to also include creation of files.ShamrockLee commentedon Nov 27, 2025
Hi there,
I opened PR #465497 to facilitate the
NIX_PREFETCH_GIT_CHECKOUT_HOOKwith a newfetchgitargumentpostCheckout. Please take a look!postCheckoutto allow gathering revision and commit metadata without leaving.git#465497packages: stabilize moonlight hash
packages: stabilize moonlight hash
glab: 1.126.0 -> 1.128.0