requireFile: Make more flexible

This commit is contained in:
Shea Levy 2015-07-08 06:24:38 -04:00
parent 957390ecba
commit e987d1c1e3

View file

@ -88,23 +88,33 @@ rec {
(lib.concatMapStrings (x: "ln -s '${x.path}' '${x.name}';\n") entries));
# 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 (sha256 != null) || (sha1 != null);
assert (name != null) || (url != null);
let msg =
if message != null then message
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
using either
nix-store --add-fixed sha256 ${name}
nix-store --add-fixed ${hashAlgo} ${name_}
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
stdenv.mkDerivation {
inherit name;
outputHashAlgo = "sha256";
outputHash = sha256;
name = name_;
outputHashAlgo = hashAlgo;
outputHash = hash;
builder = writeScript "restrict-message" ''
source ${stdenv}/setup
cat <<_EOF_