requireFile: Make more flexible
This commit is contained in:
@@ -88,23 +88,33 @@ rec {
|
|||||||
(lib.concatMapStrings (x: "ln -s '${x.path}' '${x.name}';\n") entries));
|
(lib.concatMapStrings (x: "ln -s '${x.path}' '${x.name}';\n") entries));
|
||||||
|
|
||||||
# Require file
|
# Require file
|
||||||
requireFile = {name, sha256, url ? null, message ? null} :
|
requireFile = { name ? null
|
||||||
|
, sha256 ? null
|
||||||
|
, sha1 ? null
|
||||||
|
, url ? null
|
||||||
|
, message ? null
|
||||||
|
} :
|
||||||
assert (message != null) || (url != null);
|
assert (message != null) || (url != null);
|
||||||
|
assert (sha256 != null) || (sha1 != null);
|
||||||
|
assert (name != null) || (url != null);
|
||||||
let msg =
|
let msg =
|
||||||
if message != null then message
|
if message != null then message
|
||||||
else ''
|
else ''
|
||||||
Unfortunately, we may not download file ${name} automatically.
|
Unfortunately, we may not download file ${name_} automatically.
|
||||||
Please, go to ${url}, download it yourself, and add it to the Nix store
|
Please, go to ${url}, download it yourself, and add it to the Nix store
|
||||||
using either
|
using either
|
||||||
nix-store --add-fixed sha256 ${name}
|
nix-store --add-fixed ${hashAlgo} ${name_}
|
||||||
or
|
or
|
||||||
nix-prefetch-url file://path/to/${name}
|
nix-prefetch-url --type ${hashAlgo} file://path/to/${name_}
|
||||||
'';
|
'';
|
||||||
|
hashAlgo = if sha256 != null then "sha256" else "sha1";
|
||||||
|
hash = if sha256 != null then sha256 else sha1;
|
||||||
|
name_ = if name == null then baseNameOf (toString url) else name;
|
||||||
in
|
in
|
||||||
stdenv.mkDerivation {
|
stdenv.mkDerivation {
|
||||||
inherit name;
|
name = name_;
|
||||||
outputHashAlgo = "sha256";
|
outputHashAlgo = hashAlgo;
|
||||||
outputHash = sha256;
|
outputHash = hash;
|
||||||
builder = writeScript "restrict-message" ''
|
builder = writeScript "restrict-message" ''
|
||||||
source ${stdenv}/setup
|
source ${stdenv}/setup
|
||||||
cat <<_EOF_
|
cat <<_EOF_
|
||||||
|
|||||||
Reference in New Issue
Block a user