9

I create my own repository to fetch some git source.

# packages.nix
with (import <nixpkgs> {});

rec {
  rustcSource = fetchgit {
    url = https://github.com/rust-lang/rust;
    rev = "3191fbae9da539442351f883bdabcad0d72efcb6";
    sha256 = "0w1l14kz9kxyj5dw3w9xxk1fzww5xqs3sf8saay0mh7nkmvrdb59";
  };
}

Then I build rustcSource,

sudo nix-env -f package.nix -A rustcSource

It reveals a store path of /nix/store/096fpy9qjbz5r14aadjnq9d2md9ql9cg-rust-3191fba. The problem is, I forgot to download it's submodules, so I change my expression to include submodules,

with (import <nixpkgs> {});

rec {
  rustcSource = fetchgit {
    url = https://github.com/rust-lang/rust;
    rev = "3191fbae9da539442351f883bdabcad0d72efcb6";
    sha256 = "0w1l14kz9kxyj5dw3w9xxk1fzww5xqs3sf8saay0mh7nkmvrdb59";
    leaveDotGit = true;
    fetchSubmodules = true;
  };
}

But, I discovered that nix-build doesn't recalculate the hash and see that the path has been built. So, it ends up not downloading the submodules.

Q: Is it nix bug? How can I "rebuild" or redownloading the repository?

P.S. Actually I create a derivation with fetchgit in it, but it fails because the submodules doesn't being downloaded. So, the above case simplify my problem.

3 Answers 3

6

Not a bug, this is by design.

Derivations that specify a hash are called fixed-output derivations and they only check if hash matches any existing derivations in store and use that. So your fetchSubmodules change is ignored.

For more discussion see https://github.com/NixOS/nix/issues/969

3
  • Thanks for the answer! Any elaboration on how to fix the issue? (so I can rebuild using fetchSubmodules set to true)
    – Abdillah
    Feb 5, 2017 at 22:57
  • 2
    Change the hash to something random and nix will report to you the correct hash.
    – iElectric
    Feb 13, 2017 at 13:25
  • Random value or just changing a letter didn't work, but clacke's comment still works: change the hash to 52 zeroes.
    – toraritte
    Feb 12, 2021 at 16:39
4

To fix the issue, you need to change the hash to some value that isn't already a valid hash of any path in your nix store.

For fixed-output derivations (those are the ones that have an explicit hash specified and only those get network access), if the hash already matches a path in the nix store, then nix will skip the download and just use the existing path. So slightly changing the hash (so that it no longer matches) should be enough to force a rebuild.

1
  • Thank you for your answer @bennofs! I actually don't specify about not changing hash. But actually, I tried to download a stable release of rustc. So, changing hash means changing version / stability..
    – Abdillah
    Feb 5, 2017 at 22:59
1

Fetching submodules will result in a package with a different hash. The easiest way to fix this is to change the hash to an invalid value and rebuild the package. The error message will include the correct hash. Use that and rebuild.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.