rtl: use node package lockfile
This commit is contained in:
@@ -1,31 +1,44 @@
|
||||
#!/usr/bin/env nix-shell
|
||||
#! nix-shell -i bash -p nodePackages.node2nix gnupg wget jq moreutils
|
||||
#! nix-shell -i bash -p nodePackages.node2nix gnupg wget jq gnused
|
||||
set -euo pipefail
|
||||
|
||||
TMPDIR="$(mktemp -d -p /tmp)"
|
||||
trap "rm -rf $TMPDIR" EXIT
|
||||
|
||||
# Get/verify source tarball
|
||||
version="0.11.2"
|
||||
repo=https://github.com/Ride-The-Lightning/RTL
|
||||
|
||||
# Fetch and verify source tarball
|
||||
file=v${version}.tar.gz
|
||||
url=$repo/archive/refs/tags/$file
|
||||
export GNUPGHOME=$TMPDIR
|
||||
gpg --keyserver hkps://keyserver.ubuntu.com --recv-key 3E9BD4436C288039CA827A9200C9E2BC2E45666F
|
||||
wget -P $TMPDIR https://github.com/Ride-The-Lightning/RTL/archive/refs/tags/v${version}.tar.gz
|
||||
wget -P $TMPDIR https://github.com/Ride-The-Lightning/RTL/releases/download/v${version}/v${version}.tar.gz.asc
|
||||
gpg --verify $TMPDIR/v${version}.tar.gz.asc $TMPDIR/v${version}.tar.gz
|
||||
shasum=$(sha256sum $TMPDIR/v${version}.tar.gz | cut -d\ -f1)
|
||||
wget -P $TMPDIR $url
|
||||
wget -P $TMPDIR $repo/releases/download/v${version}/$file.asc
|
||||
gpg --verify $TMPDIR/$file.asc $TMPDIR/$file
|
||||
hash=$(nix hash file $TMPDIR/$file)
|
||||
|
||||
# Run node2nix
|
||||
mkdir $TMPDIR/package && tar xvf $TMPDIR/v${version}.tar.gz -C $TMPDIR/package --strip-components 1
|
||||
cp pkg.json $TMPDIR/pkg.json
|
||||
node2nix --nodejs-10 -i $TMPDIR/pkg.json -c composition.nix --no-copy-node-env
|
||||
# Extract source
|
||||
src=$TMPDIR/src
|
||||
mkdir $src
|
||||
tar xvf $TMPDIR/$file -C $src --strip-components 1 >/dev/null
|
||||
|
||||
# Set node env import.
|
||||
# The reason for not providing a custom node-env.nix file is the following:
|
||||
# To be flakes-compatible, we have to locate the nixpgs source via `pkgs.path` instead of `<nixpkgs>`.
|
||||
# This requires the `pkgs` variable which is available only in composition.nix, not in node-env.nix.
|
||||
# Generate nix pkg
|
||||
node2nix \
|
||||
--input $src/package.json \
|
||||
--lock $src/package-lock.json \
|
||||
--composition composition.nix \
|
||||
--no-copy-node-env
|
||||
|
||||
# Use node-env.nix from nixpkgs
|
||||
nodeEnvImport='import "${toString pkgs.path}/pkgs/development/node-packages/node-env.nix"'
|
||||
sed -i "s|import ./node-env.nix|$nodeEnvImport|" composition.nix
|
||||
|
||||
# Use verified source in node-packages.nix
|
||||
url="https://github.com/Ride-The-Lightning/RTL/archive/refs/tags/v$version.tar.gz"
|
||||
sed -i '/packageName = "rtl";/!b;n;n;c\ src = fetchurl {\n url = "'$url'";\n sha256 = "'$shasum'";\n };' node-packages.nix
|
||||
# Use the verified package src
|
||||
read -d '' fetchurl <<EOF || :
|
||||
fetchurl {
|
||||
url = "$url";
|
||||
hash = "$hash";
|
||||
};
|
||||
EOF
|
||||
sed -i "s|src = .*/src;|src = ${fetchurl//$'\n'/\\n}|" node-packages.nix
|
||||
|
||||
Reference in New Issue
Block a user