Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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