Skip to content

Commit

Permalink
Merge #538: rtl: 0.12.3 -> 0.13.0, clightning-rest: 0.7.2 -> 0.8.0
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jonasnick committed Aug 21, 2022
2 parents b214018 + 53dd2a1 commit 81bf18b
Show file tree
Hide file tree
Showing 13 changed files with 276 additions and 5,769 deletions.
8 changes: 7 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,13 @@
nbPkgs = self.lib.mkNbPkgs { inherit system pkgs; };
in rec {
packages = flake-utils.lib.flattenTree (removeAttrs nbPkgs [
"pinned" "modulesPkgs" "nixops19_09" "krops" "generate-secrets" "netns-exec"
"fetchNodeModules"
"krops"
"modulesPkgs"
"netns-exec"
"nixops19_09"
"pinned"
"generate-secrets"
]) // {
inherit (import ./examples/qemu-vm/minimal-vm.nix self pkgs system)
# A simple demo VM.
Expand Down
24 changes: 24 additions & 0 deletions helper/update-fixed-output-derivation.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
set -euo pipefail

# The file that defines the derivation that should be updated
file=$1
# The name of the output of this flake that should be updated
flakeOutput=$2
# A pattern in a line preceding the hash that should be updated
patternPrecedingHash=$3

sed -i "/$patternPrecedingHash/,/hash/ s|hash = .*|hash = \"\";|" $file
# Display stderr and capture it. stdbuf is required to disable output buffering.
stderr=$(
nix build --no-link -L .#$flakeOutput |&
stdbuf -oL grep -v '\berror:.*failed to build$' |
tee /dev/stderr || :
)
hash=$(echo "$stderr" | sed -nE 's/.*?\bgot: *?(sha256-.*)/\1/p')
if [[ ! $hash ]]; then
echo
echo "Error: No hash in build output."
exit 1
fi
sed -i "/$patternPrecedingHash/,/hash/ s|hash = .*|hash = \"$hash\";|" $file
echo "(Note: The above hash mismatch message is not an error. It is part of the fetching process.)"
74 changes: 74 additions & 0 deletions pkgs/build-support/fetch-node-modules.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# This is a modified version of
# https://github.com/NixOS/nixpkgs/pull/128749

{ lib, stdenvNoCC, makeWrapper, nodejs }:

{ src
, hash ? ""
, runScripts ? false
, preferLocalBuild ? true
, npmFlags ? ""
, ...
} @ args:
stdenvNoCC.mkDerivation ({
inherit src preferLocalBuild;

name = "${src.name}-node_modules";
nativeBuildInputs = [
makeWrapper
(if args ? nodejs then args.nodejs else nodejs)
];

outputHashMode = "recursive";

impureEnvVars = lib.fetchers.proxyImpureEnvVars;

phases = "unpackPhase patchPhase buildPhase installPhase";

buildPhase = ''
runHook preBuild
if [[ ! -f package.json ]]; then
echo "Error: file `package.json` doesn't exist"
exit 1
fi
if [[ ! -f package-lock.json ]]; then
echo "Error: file `package-lock.json` doesn't exist"
exit 1
fi
export SOURCE_DATE_EPOCH=1
export npm_config_cache=/tmp
NPM_FLAGS="--omit=dev --omit=optional --no-update-notifier $npmFlags"
# Scripts may result in non-deterministic behavior.
# Some packages (e.g., Puppeteer) use postinstall scripts to download extra data.
if [[ ! $runScripts ]]; then
NPM_FLAGS+=" --ignore-scripts"
fi
echo "Running npm ci $NPM_FLAGS"
npm ci $NPM_FLAGS
cp package.json \
package-lock.json node_modules/
rm -f node_modules/.package-lock.json
runHook postBuild
'';

installPhase = ''
runHook preInstall
mkdir -p $out/lib
cp -r node_modules $out/lib
runHook postInstall
'';
} // (
if hash == "" then {
outputHashAlgo = "sha256";
outputHash = "";
} else {
outputHash = hash;
}
) // (builtins.removeAttrs args [ "hash" ]))
17 changes: 0 additions & 17 deletions pkgs/clightning-rest/composition.nix

This file was deleted.

54 changes: 43 additions & 11 deletions pkgs/clightning-rest/default.nix
Original file line number Diff line number Diff line change
@@ -1,16 +1,48 @@
{ pkgs, lib, makeWrapper }:
let
inherit (pkgs) nodejs;
nodePackages = import ./composition.nix { inherit pkgs nodejs; };
in
nodePackages.package.overrideAttrs (old: {
nativeBuildInputs = (old.nativeBuildInputs or []) ++ [
{ lib
, stdenvNoCC
, nodejs-16_x
, nodejs-slim-16_x
, fetchNodeModules
, fetchurl
, makeWrapper
, rsync
}:
let self = stdenvNoCC.mkDerivation {
pname = "clightning-rest";
version = "0.8.0";

src = fetchurl {
url = "https://github.com/Ride-The-Lightning/c-lightning-REST/archive/refs/tags/v${self.version}.tar.gz";
hash = "sha256-Rg0/lN7exNFlsMj+HQcFwVqNRzCd1ztu56q5VIkglko=";
};

passthru = {
nodejs = nodejs-16_x;
nodejsRuntime = nodejs-slim-16_x;

nodeModules = fetchNodeModules {
inherit (self) src nodejs;
hash = "sha256-aG60RANqmWQ4sbm450MS2DWEoRksjj9/z6PoKBLtDB4=";
};
};

nativeBuildInputs = [
makeWrapper
];

postInstall = ''
makeWrapper ${nodejs}/bin/node $out/bin/cl-rest \
--add-flags $out/lib/node_modules/c-lightning-rest/cl-rest
phases = "unpackPhase patchPhase installPhase";

installPhase = ''
dest=$out/lib/node_modules/clightning-rest
mkdir -p $dest
${rsync}/bin/rsync -a --inplace * ${self.nodeModules}/lib/node_modules \
--exclude=/{screenshots,'*.Dockerfile'} \
$dest
makeWrapper ${self.nodejsRuntime}/bin/node $out/bin/cl-rest \
--add-flags $dest/cl-rest.js
runHook postInstall
'';

meta = with lib; {
Expand All @@ -20,4 +52,4 @@ nodePackages.package.overrideAttrs (old: {
maintainers = with maintainers; [ nixbitcoin earvstedt ];
platforms = platforms.unix;
};
})
}; in self
66 changes: 31 additions & 35 deletions pkgs/clightning-rest/generate.sh
Original file line number Diff line number Diff line change
@@ -1,44 +1,40 @@
#!/usr/bin/env nix-shell
#! nix-shell -i bash -p nodePackages.node2nix gnupg wget jq gnused
#! nix-shell -i bash -p gnupg wget gnused
set -euo pipefail

TMPDIR="$(mktemp -d -p /tmp)"
trap "rm -rf $TMPDIR" EXIT

version="0.7.2"
version="0.8.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 $url
wget -P $TMPDIR $repo/releases/download/v${version}/$file.asc
gpg --verify $TMPDIR/$file.asc $TMPDIR/$file
hash=$(nix hash file $TMPDIR/$file)
scriptDir=$(cd "${BASH_SOURCE[0]%/*}" && pwd)

updateSrc() {
TMPDIR="$(mktemp -d /tmp/clightning-rest.XXX)"
trap "rm -rf $TMPDIR" EXIT

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

# Generate nix pkg
node2nix \
--input $src/package.json \
--lock $src/package-lock.json \
--composition composition.nix \
--no-copy-node-env
sed -i "
s|\bversion = .*;|version = \"$version\";|
s|\bhash = .*;|hash = \"$hash\";|
" default.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
updateNodeModulesHash() {
$scriptDir/../../helper/update-fixed-output-derivation.sh ./default.nix clightning-rest.nodeModules nodeModules
}

# 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
if [[ $# == 0 ]]; then
# Each of these can be run separately
updateSrc
updateNodeModulesHash
else
eval "$@"
fi
Loading

0 comments on commit 81bf18b

Please sign in to comment.