diff --git a/.cirrus.yml b/.cirrus.yml index 2dff4ac..297a74f 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -10,7 +10,8 @@ task: matrix: - name: modules_test container: - image: nixos/nix + # Use Nix release 2.3.x, the default on NixOS stable + image: nixos/nix:2.3.12 # Besides virtualization, this also enables privileged containers which are required for # sandboxed builds kvm: true diff --git a/helper/fetch-release b/helper/fetch-release index dce8a16..7875766 100755 --- a/helper/fetch-release +++ b/helper/fetch-release @@ -1,9 +1,11 @@ #!/usr/bin/env nix-shell -#!nix-shell -i bash -p bash coreutils curl jq gnupg +#!nix-shell -i bash -p bash coreutils curl jq gnupg gnugrep set -euo pipefail scriptDir=$(cd "${BASH_SOURCE[0]%/*}" && pwd) +trap 'echo "Error at ${BASH_SOURCE[0]}, line $LINENO"' ERR + repo=fort-nix/nix-bitcoin if [[ ! -v version ]]; then version=$(curl -s --show-error "https://api.github.com/repos/$repo/releases/latest" | jq -r '.tag_name' | tail -c +2) @@ -17,6 +19,8 @@ mkdir -p -m 700 "$GPG_HOME" # Import key gpg --homedir $GPG_HOME --import "$scriptDir/key-jonasnick.bin" &> /dev/null +# Check that exactly one key was imported +(($(gpg --list-keys --with-colons | grep -c pub) == 1)) # Verify key fingerprint gpg --homedir $GPG_HOME --list-keys "36C7 1A37 C9D9 88BD E825 08D9 B1A7 0E4F 8DCD 0366" > /dev/null diff --git a/modules/btcpayserver.nix b/modules/btcpayserver.nix index 47b152e..2b55e5b 100644 --- a/modules/btcpayserver.nix +++ b/modules/btcpayserver.nix @@ -4,7 +4,7 @@ with lib; let options.services = { btcpayserver = { - enable = mkEnableOption "btcpayserver"; + enable = mkEnableOption "btcpayserver, a self-hosted Bitcoin payment processor"; address = mkOption { type = types.str; default = "127.0.0.1"; diff --git a/modules/charge-lnd.nix b/modules/charge-lnd.nix index 6f564dc..769b1ce 100644 --- a/modules/charge-lnd.nix +++ b/modules/charge-lnd.nix @@ -37,7 +37,7 @@ let policies = mkOption { type = types.lines; default = ""; - example = literalExample '' + example = '' [discourage-routing-out-of-balance] chan.max_ratio = 0.1 chan.min_capacity = 250000 diff --git a/modules/clightning.nix b/modules/clightning.nix index 965ae81..e1c6569 100644 --- a/modules/clightning.nix +++ b/modules/clightning.nix @@ -3,7 +3,7 @@ with lib; let options.services.clightning = { - enable = mkEnableOption "clightning"; + enable = mkEnableOption "clightning, a Lightning Network implementation in C"; address = mkOption { type = types.str; default = "127.0.0.1"; diff --git a/modules/electrs.nix b/modules/electrs.nix index 3091da1..32e29b0 100644 --- a/modules/electrs.nix +++ b/modules/electrs.nix @@ -3,7 +3,7 @@ with lib; let options.services.electrs = { - enable = mkEnableOption "electrs"; + enable = mkEnableOption "electrs, an Electrum server implemented in Rust"; address = mkOption { type = types.str; default = "127.0.0.1"; diff --git a/modules/joinmarket.nix b/modules/joinmarket.nix index 053a376..3b18c6e 100644 --- a/modules/joinmarket.nix +++ b/modules/joinmarket.nix @@ -3,7 +3,7 @@ with lib; let options.services.joinmarket = { - enable = mkEnableOption "JoinMarket"; + enable = mkEnableOption "JoinMarket, a Bitcoin CoinJoin implementation"; payjoinAddress = mkOption { type = types.str; default = "127.0.0.1"; @@ -58,7 +58,7 @@ let inherit (nbLib) cliExec; yieldgenerator = { - enable = mkEnableOption "yield generator bot"; + enable = mkEnableOption "JoinMarket yield generator bot"; ordertype = mkOption { type = types.enum [ "reloffer" "absoffer" ]; default = "reloffer"; diff --git a/modules/lightning-loop.nix b/modules/lightning-loop.nix index 8d9039b..614d39f 100644 --- a/modules/lightning-loop.nix +++ b/modules/lightning-loop.nix @@ -3,7 +3,7 @@ with lib; let options.services.lightning-loop = { - enable = mkEnableOption "lightning-loop"; + enable = mkEnableOption "Lightning Loop, a non-custodial off/on chain bridge"; rpcAddress = mkOption { type = types.str; default = "localhost"; diff --git a/modules/lightning-pool.nix b/modules/lightning-pool.nix index 092a83f..d60ea3c 100644 --- a/modules/lightning-pool.nix +++ b/modules/lightning-pool.nix @@ -3,7 +3,7 @@ with lib; let options.services.lightning-pool = { - enable = mkEnableOption "lightning-pool"; + enable = mkEnableOption "Lightning Pool, a marketplace for inbound lightning liquidity "; rpcAddress = mkOption { type = types.str; default = "localhost"; diff --git a/modules/liquid.nix b/modules/liquid.nix index 352bf84..075b918 100644 --- a/modules/liquid.nix +++ b/modules/liquid.nix @@ -4,7 +4,7 @@ with lib; let options = { services.liquidd = { - enable = mkEnableOption "Liquid sidechain"; + enable = mkEnableOption "Liquid Bitcoin sidechain daemon"; address = mkOption { type = types.str; default = "127.0.0.1"; diff --git a/modules/lnd.nix b/modules/lnd.nix index 409f1a7..6a69483 100644 --- a/modules/lnd.nix +++ b/modules/lnd.nix @@ -3,7 +3,7 @@ with lib; let options.services.lnd = { - enable = mkEnableOption "Lightning Network Daemon"; + enable = mkEnableOption "Lightning Network daemon, a Lightning Network implementation in Go"; address = mkOption { type = types.str; default = "localhost"; diff --git a/modules/rtl.nix b/modules/rtl.nix index 095fe4a..f40a3f7 100644 --- a/modules/rtl.nix +++ b/modules/rtl.nix @@ -3,7 +3,7 @@ with lib; let options.services.rtl = { - enable = mkEnableOption "rtl"; + enable = mkEnableOption "Ride The Lightning, a web interface for lnd and clightning "; address = mkOption { type = types.str; default = "127.0.0.1"; @@ -105,6 +105,7 @@ let cfg = config.services.rtl; nbLib = config.nix-bitcoin.lib; + nbPkgs = config.nix-bitcoin.pkgs; secretsDir = config.nix-bitcoin.secretsDir; node = { isLnd, index }: '' @@ -223,7 +224,7 @@ in { install -D -o ${cfg.user} -g ${cfg.group} ${lnd.networkDir}/admin.macaroon \ '${cfg.dataDir}/macaroons/admin.macaroon' ''); - ExecStart = "${pkgs.nodejs}/bin/node ${config.nix-bitcoin.pkgs.rtl}/lib/node_modules/rtl/rtl"; + ExecStart = "${nbPkgs.rtl}/bin/rtl"; # Show "rtl" instead of "node" in the journal SyslogIdentifier = "rtl"; User = cfg.user; @@ -247,7 +248,7 @@ in { StateDirectory = "cl-rest"; # cl-rest reads the config file from the working directory WorkingDirectory = cl-rest.dataDir; - ExecStart = "${pkgs.nodejs}/bin/node ${config.nix-bitcoin.pkgs.cl-rest}/lib/node_modules/c-lightning-rest/cl-rest"; + ExecStart = "${nbPkgs.cl-rest}/bin/cl-rest"; # Show "cl-rest" instead of "node" in the journal SyslogIdentifier = "cl-rest"; User = cfg.user; 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..ca44d4c 100644 --- a/pkgs/cl-rest/default.nix +++ b/pkgs/cl-rest/default.nix @@ -1,5 +1,23 @@ -{ stdenv, pkgs, lib }: -lib.head (builtins.attrValues (import ./composition.nix { - inherit pkgs; - inherit (stdenv.hostPlatform) system; -})) +{ pkgs, lib, makeWrapper }: +let + inherit (pkgs) nodejs; + nodePackages = import ./composition.nix { inherit pkgs nodejs; }; +in +nodePackages.package.overrideAttrs (old: { + nativeBuildInputs = (old.nativeBuildInputs or []) ++ [ + makeWrapper + ]; + + postInstall = '' + makeWrapper ${nodejs}/bin/node $out/bin/cl-rest \ + --add-flags $out/lib/node_modules/c-lightning-rest/cl-rest + ''; + + meta = with lib; { + description = "REST API for C-Lightning"; + homepage = "https://github.com/Ride-The-Lightning/c-lightning-REST"; + license = licenses.mit; + maintainers = with maintainers; [ nixbitcoin earvstedt ]; + platforms = platforms.unix; + }; +}) 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 < /dev/null +} + +echo "Fetching latest version" +version=$( + git ls-remote --tags https://github.com/krebs/krops | cut -f 2 \ + | sed -E 's|refs/tags/||g; s|((v)?(.*))|\1 \3|g' | sort -k 2 -V | tail -1 | cut -f 1 -d' ' +) +echo "rev: ${version}" +echo "sha256: $(archive_hash krebs/krops $version)" diff --git a/pkgs/krops/get-sha256.sh b/pkgs/krops/get-sha256.sh deleted file mode 100755 index d7cd792..0000000 --- a/pkgs/krops/get-sha256.sh +++ /dev/null @@ -1,14 +0,0 @@ -#! /usr/bin/env nix-shell -#! nix-shell -i bash -p git -set -euo pipefail - -archive_hash () { - repo=$1 - rev=$2 - nix-prefetch-url --unpack "https://github.com/${repo}/archive/${rev}.tar.gz" 2> /dev/null -} - -echo "Fetching latest krops commit" -latest=$(git ls-remote https://github.com/krebs/krops master | cut -f 1) -echo "rev: ${latest}" -echo "sha256: $(archive_hash krebs/krops $latest)" diff --git a/pkgs/liquid-swap/default.nix b/pkgs/liquid-swap/default.nix index 5eedc28..103e892 100644 --- a/pkgs/liquid-swap/default.nix +++ b/pkgs/liquid-swap/default.nix @@ -14,5 +14,12 @@ buildPythonPackage rec { installFlags = [ ".[CLI]" ]; # The tests unfortunately seem to require the PyQt for the GUI doCheck = false; -} + meta = with lib; { + description = "Swap issued assets on the Liquid network using confidential transactions"; + homepage = "https://github.com/Blockstream/liquid-swap"; + license = licenses.gpl3Only; + maintainers = with maintainers; [ nixbitcoin ]; + platforms = platforms.unix; + }; +} diff --git a/pkgs/rtl/composition.nix b/pkgs/rtl/composition.nix index f49b28e..01c4b77 100644 --- a/pkgs/rtl/composition.nix +++ b/pkgs/rtl/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/rtl/default.nix b/pkgs/rtl/default.nix index ea6f456..dfa909c 100644 --- a/pkgs/rtl/default.nix +++ b/pkgs/rtl/default.nix @@ -1,5 +1,23 @@ -{ stdenv, pkgs, lib }: -lib.head (builtins.attrValues (import ./composition.nix { - inherit pkgs; - inherit (stdenv.hostPlatform) system; -})) +{ pkgs, lib, makeWrapper }: +let + inherit (pkgs) nodejs; + nodePackages = import ./composition.nix { inherit pkgs nodejs; }; +in +nodePackages.package.overrideAttrs (old: { + nativeBuildInputs = (old.nativeBuildInputs or []) ++ [ + makeWrapper + ]; + + postInstall = '' + makeWrapper ${nodejs}/bin/node $out/bin/rtl \ + --add-flags $out/lib/node_modules/rtl/rtl + ''; + + meta = with lib; { + description = "A web interface for LND, c-lightning and Eclair"; + homepage = "https://github.com/Ride-The-Lightning/RTL"; + license = licenses.mit; + maintainers = with maintainers; [ nixbitcoin earvstedt ]; + platforms = platforms.unix; + }; +}) diff --git a/pkgs/rtl/generate.sh b/pkgs/rtl/generate.sh index 1a32cc1..8a1c256 100755 --- a/pkgs/rtl/generate.sh +++ b/pkgs/rtl/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.11.2" +repo=https://github.com/Ride-The-Lightning/RTL + +# 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/RTL/archive/refs/tags/v${version}.tar.gz -wget -P $TMPDIR https://github.com/Ride-The-Lightning/RTL/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/RTL/archive/refs/tags/v$version.tar.gz" -sed -i '/packageName = "rtl";/!b;n;n;c\ src = fetchurl {\n url = "'$url'";\n sha256 = "'$shasum'";\n };' node-packages.nix +# Use the verified package src +read -d '' fetchurl </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 </dev/null diff --git a/test/run-tests.sh b/test/run-tests.sh index 06ac514..f30c5a2 100755 --- a/test/run-tests.sh +++ b/test/run-tests.sh @@ -95,7 +95,7 @@ while :; do ;; --copy-src|-c) shift - if [[ ! $_nixBitcoinInCopySrc ]]; then + if [[ ! $_nixBitcoinInCopiedSrc ]]; then . "$scriptDir/lib/copy-src.sh" exit fi @@ -271,12 +271,17 @@ flake() { nixosSearch() { if ! checkFlakeSupport "nixosSearch"; then return; fi + if [[ $_nixBitcoinInCopiedSrc ]]; then + # flake-info requires that its target flake is under version control + . "$scriptDir/lib/create-git-repo.sh" + fi + if [[ $outLinkPrefix ]]; then # Add gcroots for flake-info nix build $scriptDir/nixos-search#flake-info -o "$outLinkPrefix-flake-info" fi echo "Running flake-info (nixos-search)" - nix run $scriptDir/nixos-search#flake-info -- flake ../. + nix run $scriptDir/nixos-search#flake-info -- flake "$scriptDir/.." } # A basic subset of tests to keep the total runtime within