mirror of
https://github.com/koverstreet/bcachefs-tools.git
synced 2025-02-02 00:00:03 +03:00
49 lines
1.6 KiB
Nix
49 lines
1.6 KiB
Nix
|
# `builtins.fetchTarball` only accepts a `sha256` argument in Nix version 1.12
|
||
|
# or later, so here we provide a function that can provide a compatible interface
|
||
|
# to Nix 1.11 or Nix 1.12
|
||
|
#
|
||
|
# TODO FIXME: remove this sometime after Nix 1.12 goes stable
|
||
|
|
||
|
{ url # URL of the nixpkgs tarball to download
|
||
|
, rev # The Git revision of nixpkgs to fetch
|
||
|
, sha256 # The SHA256 of the downloaded data
|
||
|
, 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 { inherit url sha256; });
|
||
|
|
||
|
# This hack should at least work for Nix 1.11
|
||
|
elseValue = (
|
||
|
(rec {
|
||
|
tarball = import <nix/fetchurl.nix> { inherit url 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;
|
||
|
};
|
||
|
}).nixpkgs);
|
||
|
}
|