From f4872f33341b4e191aaee7e713e6b77c95b5fbfb Mon Sep 17 00:00:00 2001 From: Erik Arvstedt Date: Tue, 14 Dec 2021 19:51:21 +0100 Subject: [PATCH] spark-wallet: use node package lockfile --- pkgs/spark-wallet/default.nix | 13 +- pkgs/spark-wallet/generate.sh | 51 +- pkgs/spark-wallet/node-packages.nix | 1042 ++++++++++++++++----------- pkgs/spark-wallet/pkg.json | 3 - 4 files changed, 650 insertions(+), 459 deletions(-) delete mode 100644 pkgs/spark-wallet/pkg.json diff --git a/pkgs/spark-wallet/default.nix b/pkgs/spark-wallet/default.nix index ea6f456..4ed1bec 100644 --- a/pkgs/spark-wallet/default.nix +++ b/pkgs/spark-wallet/default.nix @@ -1,5 +1,8 @@ -{ stdenv, pkgs, lib }: -lib.head (builtins.attrValues (import ./composition.nix { - inherit pkgs; - inherit (stdenv.hostPlatform) system; -})) +{ pkgs }: +let + nodePackages = import ./composition.nix { inherit pkgs; }; +in +nodePackages.package.override { + # Required because spark-wallet uses `npm-shrinkwrap.json` as the lock file + reconstructLock = true; +} diff --git a/pkgs/spark-wallet/generate.sh b/pkgs/spark-wallet/generate.sh index 9a3f9c4..d869c2c 100755 --- a/pkgs/spark-wallet/generate.sh +++ b/pkgs/spark-wallet/generate.sh @@ -1,34 +1,49 @@ #!/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 moreutils gnused set -euo pipefail TMPDIR="$(mktemp -d -p /tmp)" trap "rm -rf $TMPDIR" EXIT -# Get/verify spark-wallet-npm.tgz 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 https://github.com/shesek/spark-wallet/releases/download/v${version}/SHA256SUMS.asc -wget -P $TMPDIR https://github.com/shesek/spark-wallet/releases/download/v${version}/spark-wallet-${version}-npm.tgz -(cd $TMPDIR; gpg --verify $TMPDIR/SHA256SUMS.asc; sha256sum -c --ignore-missing $TMPDIR/SHA256SUMS.asc) -shasum=$(sha256sum $TMPDIR/spark-wallet-${version}-npm.tgz | cut -d\ -f1) +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. -tar xvf $TMPDIR/spark-wallet-*-npm.tgz -C $TMPDIR -jq '.dependencies["qrcode-terminal"] = .optionalDependencies["qrcode-terminal"]' $TMPDIR/package/package.json | sponge $TMPDIR/package/package.json +jq '.dependencies["qrcode-terminal"] = .optionalDependencies["qrcode-terminal"]' $src/package.json | sponge $src/package.json -# Run node2nix -cp pkg.json $TMPDIR/pkg.json -node2nix --nodejs-10 -i $TMPDIR/pkg.json -c composition.nix --no-copy-node-env +# Generate nix pkg +node2nix \ + --nodejs-10 \ + --input $src/package.json \ + --lock $src/npm-shrinkwrap.json \ + --composition composition.nix \ + --no-copy-node-env -# 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 ``. -# This requires the `pkgs` variable which is available only in composition.nix, not in node-env.nix. +# 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/shesek/spark-wallet/releases/download/v$version/spark-wallet-$version-npm.tgz" -sed -i '/packageName = "spark-wallet";/!b;n;n;c\ src = fetchurl {\n url = "'$url'";\n sha256 = "'$shasum'";\n };' node-packages.nix +# Use the verified package src +read -d '' fetchurl <