Fix the output of the nixpkgs derivation and make the pin forwards compatible with Nix 2.0 (#52)

* Fix the output of the nixpkgs derivation

* Use the fixed-output sha256 hash for builtins.fetchTarball

This change makes the nixpkgs pin forwards compatible with Nix 1.12.x
and Nix 2.0.

* Correct the phrasing of the code comment
This commit is contained in:
Parnell Springmeyer 2018-03-12 11:06:21 -05:00 committed by GitHub
parent 5fd44880da
commit 2cfca15c31
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 5 deletions

View file

@ -1,5 +1,6 @@
{ rev # The Git revision of nixpkgs to fetch { rev # The Git revision of nixpkgs to fetch
, sha256 # The SHA256 of the downloaded data , sha256 # The SHA256 of the downloaded data
, outputSha256 ? null # The SHA256 output hash
, system ? builtins.currentSystem # This is overridable if necessary , system ? builtins.currentSystem # This is overridable if necessary
}: }:
@ -15,7 +16,11 @@ ifThenElse {
thenValue = ( thenValue = (
builtins.fetchTarball { builtins.fetchTarball {
url = "https://github.com/NixOS/nixpkgs/archive/${rev}.tar.gz"; url = "https://github.com/NixOS/nixpkgs/archive/${rev}.tar.gz";
inherit sha256;
# builtins.fetchTarball does not need the sha256 hash of the
# packed and compressed tarball but it _does_ need the
# fixed-output sha256 hash.
sha256 = outputSha256;
}); });
# This hack should at least work for Nix 1.11 # This hack should at least work for Nix 1.11
@ -34,7 +39,7 @@ ifThenElse {
"$gzip" --decompress < "$tarball" | "$tar" -x --strip-components=1 "$gzip" --decompress < "$tarball" | "$tar" -x --strip-components=1
''; '';
nixpkgs = builtins.derivation { nixpkgs = builtins.derivation ({
name = "nixpkgs-${builtins.substring 0 6 rev}"; name = "nixpkgs-${builtins.substring 0 6 rev}";
builder = builtins.storePath builtin-paths.shell; builder = builtins.storePath builtin-paths.shell;
@ -46,6 +51,10 @@ ifThenElse {
tar = builtins.storePath builtin-paths.tar; tar = builtins.storePath builtin-paths.tar;
gzip = builtins.storePath builtin-paths.gzip; gzip = builtins.storePath builtin-paths.gzip;
coreutils = builtins.storePath builtin-paths.coreutils; coreutils = builtins.storePath builtin-paths.coreutils;
}; } // (if null == outputSha256 then { } else {
outputHashMode = "recursive";
outputHashAlgo = "sha256";
outputHash = outputSha256;
}));
}).nixpkgs); }).nixpkgs);
} }

View file

@ -7,6 +7,7 @@
# The SHA256 will be printed as the last line of stdout. # The SHA256 will be printed as the last line of stdout.
import ./fetch-nixpkgs.nix { import ./fetch-nixpkgs.nix {
rev = "74286ec9e76be7cd00c4247b9acb430c4bd9f1ce"; rev = "74286ec9e76be7cd00c4247b9acb430c4bd9f1ce";
sha256 = "0njb3qd2wxj7gil8y61lwh7zacmvr6zklv67w5zmvifi1fvalvdg"; sha256 = "0njb3qd2wxj7gil8y61lwh7zacmvr6zklv67w5zmvifi1fvalvdg";
outputSha256 = "13ydgpzl5nix4gc358iy9zjd5nrrpbpwpxmfhis4aai2zmkja3ak";
} }