mirror of
https://github.com/unclechu/gRPC-haskell.git
synced 2024-11-14 15:19:43 +01:00
2cfca15c31
* 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
60 lines
1.9 KiB
Nix
60 lines
1.9 KiB
Nix
{ rev # The Git revision of nixpkgs to fetch
|
|
, sha256 # The SHA256 of the downloaded data
|
|
, outputSha256 ? null # The SHA256 output hash
|
|
, system ? builtins.currentSystem # This is overridable if necessary
|
|
}:
|
|
|
|
with {
|
|
ifThenElse = { bool, thenValue, elseValue }: (
|
|
if bool then thenValue else elseValue);
|
|
};
|
|
|
|
ifThenElse {
|
|
bool = (0 <= builtins.compareVersions builtins.nixVersion "1.12");
|
|
|
|
# In Nix 1.12, we can just give a `sha256` to `builtins.fetchTarball`.
|
|
thenValue = (
|
|
builtins.fetchTarball {
|
|
url = "https://github.com/NixOS/nixpkgs/archive/${rev}.tar.gz";
|
|
|
|
# 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
|
|
elseValue = (
|
|
(rec {
|
|
tarball = import <nix/fetchurl.nix> {
|
|
url = "https://github.com/NixOS/nixpkgs/archive/${rev}.tar.gz";
|
|
inherit sha256;
|
|
};
|
|
|
|
builtin-paths = import <nix/config.nix>;
|
|
|
|
script = builtins.toFile "nixpkgs-unpacker" ''
|
|
"$coreutils/mkdir" "$out"
|
|
cd "$out"
|
|
"$gzip" --decompress < "$tarball" | "$tar" -x --strip-components=1
|
|
'';
|
|
|
|
nixpkgs = builtins.derivation ({
|
|
name = "nixpkgs-${builtins.substring 0 6 rev}";
|
|
|
|
builder = builtins.storePath builtin-paths.shell;
|
|
|
|
args = [ script ];
|
|
|
|
inherit tarball system;
|
|
|
|
tar = builtins.storePath builtin-paths.tar;
|
|
gzip = builtins.storePath builtin-paths.gzip;
|
|
coreutils = builtins.storePath builtin-paths.coreutils;
|
|
} // (if null == outputSha256 then { } else {
|
|
outputHashMode = "recursive";
|
|
outputHashAlgo = "sha256";
|
|
outputHash = outputSha256;
|
|
}));
|
|
}).nixpkgs);
|
|
}
|