From 3091b0a4fb97512294325f5b7b35052a1985fb88 Mon Sep 17 00:00:00 2001 From: Erik Arvstedt Date: Tue, 14 Dec 2021 19:51:20 +0100 Subject: [PATCH] cl-rest: use node package lockfile --- pkgs/cl-rest/composition.nix | 2 +- pkgs/cl-rest/default.nix | 10 +- pkgs/cl-rest/generate.sh | 47 ++-- pkgs/cl-rest/node-packages.nix | 429 ++++++++++++++++++++------------- 4 files changed, 291 insertions(+), 197 deletions(-) diff --git a/pkgs/cl-rest/composition.nix b/pkgs/cl-rest/composition.nix index f49b28e..01c4b77 100644 --- a/pkgs/cl-rest/composition.nix +++ b/pkgs/cl-rest/composition.nix @@ -2,7 +2,7 @@ {pkgs ? import { inherit system; - }, system ? builtins.currentSystem, nodejs ? pkgs."nodejs-10_x"}: + }, system ? builtins.currentSystem, nodejs ? pkgs."nodejs-12_x"}: let nodeEnv = import "${toString pkgs.path}/pkgs/development/node-packages/node-env.nix" { diff --git a/pkgs/cl-rest/default.nix b/pkgs/cl-rest/default.nix index ea6f456..b7931b7 100644 --- a/pkgs/cl-rest/default.nix +++ b/pkgs/cl-rest/default.nix @@ -1,5 +1,5 @@ -{ stdenv, pkgs, lib }: -lib.head (builtins.attrValues (import ./composition.nix { - inherit pkgs; - inherit (stdenv.hostPlatform) system; -})) +{ pkgs }: +let + nodePackages = import ./composition.nix { inherit pkgs; inherit (pkgs) nodejs; }; +in +nodePackages.package diff --git a/pkgs/cl-rest/generate.sh b/pkgs/cl-rest/generate.sh index 002cd2e..d458a70 100755 --- a/pkgs/cl-rest/generate.sh +++ b/pkgs/cl-rest/generate.sh @@ -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.6.0" +repo=https://github.com/Ride-The-Lightning/c-lightning-REST + +# 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/c-lightning-REST/archive/refs/tags/v${version}.tar.gz -wget -P $TMPDIR https://github.com/Ride-The-Lightning/c-lightning-REST/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 ``. -# 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/c-lightning-REST/archive/refs/tags/v$version.tar.gz" -sed -i '/packageName = "c-lightning-rest";/!b;n;n;c\ src = fetchurl {\n url = "'$url'";\n sha256 = "'$shasum'";\n };' node-packages.nix +# Use the verified package src +read -d '' fetchurl <