From 02e03227d8682b82e7f41fa659d51e56bc237504 Mon Sep 17 00:00:00 2001 From: Colin Date: Sun, 14 Jan 2024 04:33:12 +0000 Subject: [PATCH] servo: try to integrate peerswap with clightning, but it fails --- .../services/cryptocurrencies/clightning.nix | 8 +++++++- pkgs/additional/peerswap/default.nix | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/hosts/by-name/servo/services/cryptocurrencies/clightning.nix b/hosts/by-name/servo/services/cryptocurrencies/clightning.nix index 81fd7811..cac2b2d7 100644 --- a/hosts/by-name/servo/services/cryptocurrencies/clightning.nix +++ b/hosts/by-name/servo/services/cryptocurrencies/clightning.nix @@ -70,7 +70,7 @@ # - maxfeepercent defaults to 0.5 # - label is a human-friendly label for my records -{ config, ... }: +{ config, pkgs, ... }: { sane.persist.sys.byStore.ext = [ { user = "clightning"; group = "clightning"; mode = "0710"; path = "/var/lib/clightning"; } @@ -117,6 +117,12 @@ # - feature configs (i.e. experimental-xyz options) sane.services.clightning.extraConfig = '' log-level=debug:lightningd + # peerswap: + # - config example: + # XXX: peerswap crashes clightning on launch. stacktrace is useless. + # plugin=${pkgs.peerswap}/bin/peerswap + # peerswap-db-path=/var/lib/clightning/peerswap/swaps + # peerswap-policy-path=... ''; sane.services.clightning.extraConfigFiles = [ config.sops.secrets."lightning-config".path ]; sops.secrets."lightning-config" = { diff --git a/pkgs/additional/peerswap/default.nix b/pkgs/additional/peerswap/default.nix index c6b78068..c14b90e2 100644 --- a/pkgs/additional/peerswap/default.nix +++ b/pkgs/additional/peerswap/default.nix @@ -26,6 +26,24 @@ buildGoModule rec { vendorHash = "sha256-OOwXWsFVxieOtzF7arXVNeWo4YB/EQbxQMAIxDVIhfg="; proxyVendor = true; + postPatch = '' + # upstream Makefile builds with `-ldflags "-X main.GitCommit="`, but we bypass Makefile and have to do that manually. + # GOFLAGS or CGO_LDFLAGS could both sort of do this, but they struggle with the spaces/quoting of the above, + # so instead i manually patch in the values + substituteInPlace cmd/peerswap-plugin/main.go \ + --replace 'var GitCommit string' 'var GitCommit string = "${src.rev}"' + substituteInPlace cmd/peerswaplnd/peerswapd/main.go \ + --replace 'var GitCommit string' 'var GitCommit string = "${src.rev}"' + substituteInPlace cmd/peerswaplnd/pscli/main.go \ + --replace 'var GitCommit string' 'var GitCommit string = "${src.rev}"' + ''; + + postInstall = '' + # the upstream Makefile compiles peerswap-plugin/main.go into a binary named `peerswap`, + # but since we use buildGoModule, that doesn't go through the Makefile and we have to manually rename. + mv $out/bin/peerswap-plugin $out/bin/peerswap + ''; + meta = with lib; { description = "PeerSwap enables Lightning Network nodes to balance their channels by facilitating atomic swaps with direct peers."; homepage = "https://peerswap.dev";