How to `nix-build` again a built store path?

十年热恋 提交于 2021-02-18 05:32:09

问题


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.


回答1:


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




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/41486747/how-to-nix-build-again-a-built-store-path

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!