nix-bitcoin/pkgs/spark-wallet/generate.sh

59 lines
1.8 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
set -euo pipefail
. "${BASH_SOURCE[0]%/*}/../../helper/run-in-nix-env" "nodePackages.node2nix gnupg wget jq moreutils gnused" "$@"
TMPDIR=$(mktemp -d -p /tmp)
trap 'rm -rf $TMPDIR' EXIT
2021-11-09 15:19:14 +00:00
version="0.3.1"
repo=https://github.com/shesek/spark-wallet
# Fetch and verify source tarball
file=spark-wallet-${version}-npm.tgz
url=$repo/releases/download/v${version}/$file
export GNUPGHOME=$TMPDIR
gpg --keyserver hkps://keyserver.ubuntu.com --recv-key FCF19B67866562F08A43AAD681F6104CD0F150FC
wget -P "$TMPDIR" "$url"
wget -P "$TMPDIR" "$repo/releases/download/v${version}/SHA256SUMS.asc"
gpg --verify "$TMPDIR/SHA256SUMS.asc"
(cd "$TMPDIR"; sha256sum --check --ignore-missing SHA256SUMS.asc)
hash=$(nix hash file "$TMPDIR/$file")
# Extract source
src=$TMPDIR/src
mkdir "$src"
tar xvf "$TMPDIR/$file" -C "$src" --strip-components 1 >/dev/null
# Make qrcode-terminal a strict dependency so that node2nix includes it in the package derivation.
jq '.dependencies["qrcode-terminal"] = .optionalDependencies["qrcode-terminal"]' "$src/package.json" | sponge "$src/package.json"
node2nix \
--nodejs-14 \
--input "$src/package.json" \
--lock "$src/npm-shrinkwrap.json" \
--composition composition.nix \
--no-copy-node-env
# Use node-env.nix from nixpkgs
# shellcheck disable=SC2016
nodeEnvImport='import "${toString pkgs.path}/pkgs/development/node-packages/node-env.nix"'
sed -i "s|import ./node-env.nix|$nodeEnvImport|" composition.nix
# Use the verified package src
read -rd '' fetchurl <<EOF || :
fetchurl {
url = "$url";
hash = "$hash";
};
EOF
sed -i "
# Use the verified package src
s|src = .*/src;|src = ${fetchurl//$'\n'/\\n}|
# github: use HTTPS instead of SSH, which requires user authentication
s|git+ssh://git@|https://|
s|ssh://git@|https://|
s|\.git#|#|
" node-packages.nix