Using fakeSha256 when updating derivations
Nobody has claimed this yet.
- Dominant language
- Nix
- Stars
- 4k
- Forks
- 339
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 7
Description
I'm not entirely sure what the precise underlying cause is of this behavior, but I've noticed the following non-obvious gotcha when updating Nix derivations in the past:
- Modify a derivation somehow
- e.g. bump a package version, either fetching a binary to
patchelf, updating some Haskell dependency, etc.
- e.g. bump a package version, either fetching a binary to
- Forget to modify the
sha256field- That is to say, the valid
sha256associated with the previously working derivation remains
- That is to say, the valid
- Build the derivation
- The derivation actually does build, leading developer to believe that their change was effective
- Attempt to use the derivation, observing that the result from the previously successful derivation is the one being pulled from the store
A behavioral reproduction:
- Clone
nixpkgsandcdinto the directory- The patches below specifically refer to the
nixpkgs-unstablebranch as of 13 June 2020 - Relevant commit hash is
dcb64ea42e64aaecd8e6fef65cc86245c9666818
- The patches below specifically refer to the
- Apply the following (incorrect) patch
incorrect patch
diff --git a/pkgs/applications/misc/hello/default.nix b/pkgs/applications/misc/hello/default.nix
index 32c8c696..e3555418 100644
--- a/pkgs/applications/misc/hello/default.nix
+++ b/pkgs/applications/misc/hello/default.nix
@@ -2,7 +2,7 @@
stdenv.mkDerivation rec {
pname = "hello";
- version = "2.10";
+ version = "2.9";
src = fetchurl {
url = "mirror://gnu/hello/${pname}-${version}.tar.gz";
- Run the following command and observe that the version is still
2.10
nix-shell -E '{pkgs ? import ./. {}}: pkgs.mkShell { buildInputs = [ pkgs.hello ]; }' --command 'hello --version'
- Drop the previous patch and apply the following (correct) patch
correct patch
diff --git a/pkgs/applications/misc/hello/default.nix b/pkgs/applications/misc/hello/default.nix
index 32c8c696..c0f60198 100644
--- a/pkgs/applications/misc/hello/default.nix
+++ b/pkgs/applications/misc/hello/default.nix
@@ -2,11 +2,11 @@
stdenv.mkDerivation rec {
pname = "hello";
- version = "2.10";
+ version = "2.9";
src = fetchurl {
url = "mirror://gnu/hello/${pname}-${version}.tar.gz";
- sha256 = "0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i";
+ sha256 = "19qy37gkasc4csb1d3bdiz9snn8mir2p3aj0jgzmfv0r2hi7mfzc";
};
doCheck = true;
- Run the following command and observe that the version is now (correctly)
2.9
nix-shell -E '{pkgs ? import ./. {}}: pkgs.mkShell { buildInputs = [ pkgs.hello ]; }' --command 'hello --version'
I think having a worked out example (like the one above) would help, but an explanation of Nix's underlying behavior here would be very nice as well.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the reproduction using pkgs/applications/misc/hello/default.nix and the shown nix-shell command, comparing the incorrect and correct patches. Add a worked documentation example that explains the observed behavior and shows the expected version output; verify it against the cited nixpkgs revision and commands.
Written by the indexing model from the issue text.
Assessment
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100