maintainers/scripts/bootstrap-files: fix nar extract on linux
`<nix/fetchurl.nix>` fails importing nar files on linux due to file not found errors. use nix-store to add the nar file to the store and get the hash.
This commit is contained in:
parent
1756576c4a
commit
e3c8b84dae
|
@ -6,6 +6,8 @@
|
||||||
#! nix-shell -p nix
|
#! nix-shell -p nix
|
||||||
#! nix-shell -p jq
|
#! nix-shell -p jq
|
||||||
|
|
||||||
|
set -o pipefail
|
||||||
|
|
||||||
# How the refresher works:
|
# How the refresher works:
|
||||||
#
|
#
|
||||||
# For a given list of <targets>:
|
# For a given list of <targets>:
|
||||||
|
@ -15,6 +17,9 @@
|
||||||
# 4. calculate hashes and craft the commit message with the details on
|
# 4. calculate hashes and craft the commit message with the details on
|
||||||
# how to upload the result to 'tarballs.nixos.org'
|
# how to upload the result to 'tarballs.nixos.org'
|
||||||
|
|
||||||
|
scratch_dir=$(mktemp -d)
|
||||||
|
trap 'rm -rf -- "${scratch_dir}"' EXIT
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
cat >&2 <<EOF
|
cat >&2 <<EOF
|
||||||
Usage:
|
Usage:
|
||||||
|
@ -101,15 +106,17 @@ is_cross() {
|
||||||
}
|
}
|
||||||
|
|
||||||
nar_sri_get() {
|
nar_sri_get() {
|
||||||
local ouput sri
|
local restore_path store_path
|
||||||
output=$(nix-build --expr \
|
((${#@} != 2)) && die "nar_sri_get /path/to/name.nar.xz name"
|
||||||
'import <nix/fetchurl.nix> {
|
restore_path="${scratch_dir}/$2"
|
||||||
url = "'"$1"'";
|
xz -d < "$1" | nix-store --restore "${restore_path}"
|
||||||
unpack = true;
|
[[ $? -ne 0 ]] && die "Failed to unpack '$1'"
|
||||||
}' 2>&1 || true)
|
|
||||||
sri=$(echo "$output" | awk '/^\s+got:\s+/{ print $2 }')
|
store_path=$(nix-store --add "${restore_path}")
|
||||||
[[ -z "$sri" ]] && die "$output"
|
[[ $? -ne 0 ]] && die "Failed to add '$restore_path' to store"
|
||||||
echo "$sri"
|
rm -rf -- "${restore_path}"
|
||||||
|
|
||||||
|
nix-hash --to-sri "$(nix-store --query --hash "${store_path}")"
|
||||||
}
|
}
|
||||||
|
|
||||||
# collect passed options
|
# collect passed options
|
||||||
|
@ -239,9 +246,12 @@ EOF
|
||||||
executable_nix="executable = true;"
|
executable_nix="executable = true;"
|
||||||
fi
|
fi
|
||||||
unpack_nix=
|
unpack_nix=
|
||||||
if [[ $fname = *.nar.* ]]; then
|
name_nix=
|
||||||
|
if [[ $fname = *.nar.xz ]]; then
|
||||||
unpack_nix="unpack = true;"
|
unpack_nix="unpack = true;"
|
||||||
sri=$(nar_sri_get "file://$p")
|
name_nix="name = \"${fname%.nar.xz}\";"
|
||||||
|
sri=$(nar_sri_get "$p" "${fname%.nar.xz}")
|
||||||
|
[[ $? -ne 0 ]] && die "Failed to get hash of '$p'"
|
||||||
else
|
else
|
||||||
sha256=$(nix-prefetch-url $executable_arg --name "$fname" "file://$p")
|
sha256=$(nix-prefetch-url $executable_arg --name "$fname" "file://$p")
|
||||||
[[ $? -ne 0 ]] && die "Failed to get the hash for '$p'"
|
[[ $? -ne 0 ]] && die "Failed to get the hash for '$p'"
|
||||||
|
@ -255,6 +265,7 @@ EOF
|
||||||
url = "http://tarballs.nixos.org/${s3_prefix}/${nixpkgs_revision}/$fname";
|
url = "http://tarballs.nixos.org/${s3_prefix}/${nixpkgs_revision}/$fname";
|
||||||
hash = "${sri}";$(
|
hash = "${sri}";$(
|
||||||
[[ -n ${executable_nix} ]] && printf "\n %s" "${executable_nix}"
|
[[ -n ${executable_nix} ]] && printf "\n %s" "${executable_nix}"
|
||||||
|
[[ -n ${name_nix} ]] && printf "\n %s" "${name_nix}"
|
||||||
[[ -n ${unpack_nix} ]] && printf "\n %s" "${unpack_nix}"
|
[[ -n ${unpack_nix} ]] && printf "\n %s" "${unpack_nix}"
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue
Block a user