Skip to content

Commit 81bf18b

Browse files
committed
Merge #538: rtl: 0.12.3 -> 0.13.0, clightning-rest: 0.7.2 -> 0.8.0
53dd2a1 cl-rest: 0.7.2 -> 0.8.0 (Erik Arvstedt) 617ed4c rtl: 0.12.3-beta -> 0.13.0 (Erik Arvstedt) e63dafe pkgs: add `fetch-node-modules` (Erik Arvstedt) Pull request description: ACKs for top commit: jonasnick: ACK 53dd2a1 Tree-SHA512: aa4854b48d0186887a2db42b1f5e8fb27dc7da4ba6def50ee0a33d76ceb5425f593fb0c159e81809b67dda441559262872a331476136195c8033db94cc302026
2 parents b214018 + 53dd2a1 commit 81bf18b

File tree

13 files changed

+276
-5769
lines changed

13 files changed

+276
-5769
lines changed

flake.nix

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,13 @@
7373
nbPkgs = self.lib.mkNbPkgs { inherit system pkgs; };
7474
in rec {
7575
packages = flake-utils.lib.flattenTree (removeAttrs nbPkgs [
76-
"pinned" "modulesPkgs" "nixops19_09" "krops" "generate-secrets" "netns-exec"
76+
"fetchNodeModules"
77+
"krops"
78+
"modulesPkgs"
79+
"netns-exec"
80+
"nixops19_09"
81+
"pinned"
82+
"generate-secrets"
7783
]) // {
7884
inherit (import ./examples/qemu-vm/minimal-vm.nix self pkgs system)
7985
# A simple demo VM.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
set -euo pipefail
2+
3+
# The file that defines the derivation that should be updated
4+
file=$1
5+
# The name of the output of this flake that should be updated
6+
flakeOutput=$2
7+
# A pattern in a line preceding the hash that should be updated
8+
patternPrecedingHash=$3
9+
10+
sed -i "/$patternPrecedingHash/,/hash/ s|hash = .*|hash = \"\";|" $file
11+
# Display stderr and capture it. stdbuf is required to disable output buffering.
12+
stderr=$(
13+
nix build --no-link -L .#$flakeOutput |&
14+
stdbuf -oL grep -v '\berror:.*failed to build$' |
15+
tee /dev/stderr || :
16+
)
17+
hash=$(echo "$stderr" | sed -nE 's/.*?\bgot: *?(sha256-.*)/\1/p')
18+
if [[ ! $hash ]]; then
19+
echo
20+
echo "Error: No hash in build output."
21+
exit 1
22+
fi
23+
sed -i "/$patternPrecedingHash/,/hash/ s|hash = .*|hash = \"$hash\";|" $file
24+
echo "(Note: The above hash mismatch message is not an error. It is part of the fetching process.)"
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# This is a modified version of
2+
# https://github.com/NixOS/nixpkgs/pull/128749
3+
4+
{ lib, stdenvNoCC, makeWrapper, nodejs }:
5+
6+
{ src
7+
, hash ? ""
8+
, runScripts ? false
9+
, preferLocalBuild ? true
10+
, npmFlags ? ""
11+
, ...
12+
} @ args:
13+
stdenvNoCC.mkDerivation ({
14+
inherit src preferLocalBuild;
15+
16+
name = "${src.name}-node_modules";
17+
nativeBuildInputs = [
18+
makeWrapper
19+
(if args ? nodejs then args.nodejs else nodejs)
20+
];
21+
22+
outputHashMode = "recursive";
23+
24+
impureEnvVars = lib.fetchers.proxyImpureEnvVars;
25+
26+
phases = "unpackPhase patchPhase buildPhase installPhase";
27+
28+
buildPhase = ''
29+
runHook preBuild
30+
31+
if [[ ! -f package.json ]]; then
32+
echo "Error: file `package.json` doesn't exist"
33+
exit 1
34+
fi
35+
if [[ ! -f package-lock.json ]]; then
36+
echo "Error: file `package-lock.json` doesn't exist"
37+
exit 1
38+
fi
39+
40+
export SOURCE_DATE_EPOCH=1
41+
export npm_config_cache=/tmp
42+
NPM_FLAGS="--omit=dev --omit=optional --no-update-notifier $npmFlags"
43+
# Scripts may result in non-deterministic behavior.
44+
# Some packages (e.g., Puppeteer) use postinstall scripts to download extra data.
45+
if [[ ! $runScripts ]]; then
46+
NPM_FLAGS+=" --ignore-scripts"
47+
fi
48+
49+
echo "Running npm ci $NPM_FLAGS"
50+
npm ci $NPM_FLAGS
51+
52+
cp package.json \
53+
package-lock.json node_modules/
54+
rm -f node_modules/.package-lock.json
55+
56+
runHook postBuild
57+
'';
58+
59+
installPhase = ''
60+
runHook preInstall
61+
62+
mkdir -p $out/lib
63+
cp -r node_modules $out/lib
64+
65+
runHook postInstall
66+
'';
67+
} // (
68+
if hash == "" then {
69+
outputHashAlgo = "sha256";
70+
outputHash = "";
71+
} else {
72+
outputHash = hash;
73+
}
74+
) // (builtins.removeAttrs args [ "hash" ]))

pkgs/clightning-rest/composition.nix

Lines changed: 0 additions & 17 deletions
This file was deleted.

pkgs/clightning-rest/default.nix

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,48 @@
1-
{ pkgs, lib, makeWrapper }:
2-
let
3-
inherit (pkgs) nodejs;
4-
nodePackages = import ./composition.nix { inherit pkgs nodejs; };
5-
in
6-
nodePackages.package.overrideAttrs (old: {
7-
nativeBuildInputs = (old.nativeBuildInputs or []) ++ [
1+
{ lib
2+
, stdenvNoCC
3+
, nodejs-16_x
4+
, nodejs-slim-16_x
5+
, fetchNodeModules
6+
, fetchurl
7+
, makeWrapper
8+
, rsync
9+
}:
10+
let self = stdenvNoCC.mkDerivation {
11+
pname = "clightning-rest";
12+
version = "0.8.0";
13+
14+
src = fetchurl {
15+
url = "https://github.com/Ride-The-Lightning/c-lightning-REST/archive/refs/tags/v${self.version}.tar.gz";
16+
hash = "sha256-Rg0/lN7exNFlsMj+HQcFwVqNRzCd1ztu56q5VIkglko=";
17+
};
18+
19+
passthru = {
20+
nodejs = nodejs-16_x;
21+
nodejsRuntime = nodejs-slim-16_x;
22+
23+
nodeModules = fetchNodeModules {
24+
inherit (self) src nodejs;
25+
hash = "sha256-aG60RANqmWQ4sbm450MS2DWEoRksjj9/z6PoKBLtDB4=";
26+
};
27+
};
28+
29+
nativeBuildInputs = [
830
makeWrapper
931
];
1032

11-
postInstall = ''
12-
makeWrapper ${nodejs}/bin/node $out/bin/cl-rest \
13-
--add-flags $out/lib/node_modules/c-lightning-rest/cl-rest
33+
phases = "unpackPhase patchPhase installPhase";
34+
35+
installPhase = ''
36+
dest=$out/lib/node_modules/clightning-rest
37+
mkdir -p $dest
38+
${rsync}/bin/rsync -a --inplace * ${self.nodeModules}/lib/node_modules \
39+
--exclude=/{screenshots,'*.Dockerfile'} \
40+
$dest
41+
42+
makeWrapper ${self.nodejsRuntime}/bin/node $out/bin/cl-rest \
43+
--add-flags $dest/cl-rest.js
44+
45+
runHook postInstall
1446
'';
1547

1648
meta = with lib; {
@@ -20,4 +52,4 @@ nodePackages.package.overrideAttrs (old: {
2052
maintainers = with maintainers; [ nixbitcoin earvstedt ];
2153
platforms = platforms.unix;
2254
};
23-
})
55+
}; in self

pkgs/clightning-rest/generate.sh

Lines changed: 31 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,40 @@
11
#!/usr/bin/env nix-shell
2-
#! nix-shell -i bash -p nodePackages.node2nix gnupg wget jq gnused
2+
#! nix-shell -i bash -p gnupg wget gnused
33
set -euo pipefail
44

5-
TMPDIR="$(mktemp -d -p /tmp)"
6-
trap "rm -rf $TMPDIR" EXIT
7-
8-
version="0.7.2"
5+
version="0.8.0"
96
repo=https://github.com/Ride-The-Lightning/c-lightning-REST
107

11-
# Fetch and verify source tarball
12-
file=v${version}.tar.gz
13-
url=$repo/archive/refs/tags/$file
14-
export GNUPGHOME=$TMPDIR
15-
gpg --keyserver hkps://keyserver.ubuntu.com --recv-key 3E9BD4436C288039CA827A9200C9E2BC2E45666F
16-
wget -P $TMPDIR $url
17-
wget -P $TMPDIR $repo/releases/download/v${version}/$file.asc
18-
gpg --verify $TMPDIR/$file.asc $TMPDIR/$file
19-
hash=$(nix hash file $TMPDIR/$file)
8+
scriptDir=$(cd "${BASH_SOURCE[0]%/*}" && pwd)
9+
10+
updateSrc() {
11+
TMPDIR="$(mktemp -d /tmp/clightning-rest.XXX)"
12+
trap "rm -rf $TMPDIR" EXIT
2013

21-
# Extract source
22-
src=$TMPDIR/src
23-
mkdir $src
24-
tar xvf $TMPDIR/$file -C $src --strip-components 1 >/dev/null
14+
# Fetch and verify source tarball
15+
export GNUPGHOME=$TMPDIR
16+
# Fetch saubyk's key
17+
gpg --keyserver hkps://keyserver.ubuntu.com --recv-key 3E9BD4436C288039CA827A9200C9E2BC2E45666F
18+
file=v${version}.tar.gz
19+
wget -P $TMPDIR $repo/archive/refs/tags/$file
20+
wget -P $TMPDIR $repo/releases/download/v${version}/$file.asc
21+
gpg --verify $TMPDIR/$file.asc $TMPDIR/$file
22+
hash=$(nix hash file $TMPDIR/$file)
2523

26-
# Generate nix pkg
27-
node2nix \
28-
--input $src/package.json \
29-
--lock $src/package-lock.json \
30-
--composition composition.nix \
31-
--no-copy-node-env
24+
sed -i "
25+
s|\bversion = .*;|version = \"$version\";|
26+
s|\bhash = .*;|hash = \"$hash\";|
27+
" default.nix
28+
}
3229

33-
# Use node-env.nix from nixpkgs
34-
nodeEnvImport='import "${toString pkgs.path}/pkgs/development/node-packages/node-env.nix"'
35-
sed -i "s|import ./node-env.nix|$nodeEnvImport|" composition.nix
30+
updateNodeModulesHash() {
31+
$scriptDir/../../helper/update-fixed-output-derivation.sh ./default.nix clightning-rest.nodeModules nodeModules
32+
}
3633

37-
# Use the verified package src
38-
read -d '' fetchurl <<EOF || :
39-
fetchurl {
40-
url = "$url";
41-
hash = "$hash";
42-
};
43-
EOF
44-
sed -i "s|src = .*/src;|src = ${fetchurl//$'\n'/\\n}|" node-packages.nix
34+
if [[ $# == 0 ]]; then
35+
# Each of these can be run separately
36+
updateSrc
37+
updateNodeModulesHash
38+
else
39+
eval "$@"
40+
fi

0 commit comments

Comments
 (0)