diff --git a/modules/backups.nix b/modules/backups.nix deleted file mode 100644 index 7205f03..0000000 --- a/modules/backups.nix +++ /dev/null @@ -1,127 +0,0 @@ -{ config, lib, pkgs, ... }: - -with lib; -let - options.services.backups = { - enable = mkOption { - type = types.bool; - default = false; - description = '' - Enable backups of node data. - This uses the NixOS duplicity service. - To further configure the backup, you can set NixOS options `services.duplicity.*`. - The `services.duplicity.cleanup.*` options are particularly useful. - ''; - }; - with-bulk-data = mkOption { - type = types.bool; - default = false; - description = '' - Whether to also backup Bitcoin blockchain and other bulk data. - ''; - }; - destination = mkOption { - type = types.str; - default = "file:///var/lib/localBackups"; - description = '' - Where to back up to. - ''; - }; - frequency = mkOption { - type = types.nullOr types.str; - default = null; - description = '' - Run backup with the given frequency. If null, do not run automatically. - ''; - }; - postgresqlDatabases = mkOption { - type = types.listOf types.str; - default = []; - description = "List of database names to backup."; - }; - extraFiles = mkOption { - type = types.listOf types.str; - default = []; - example = [ "/var/lib/nginx" ]; - description = "Additional files to be appended to filelist."; - }; - }; - - cfg = config.services.backups; - - # Potential backup file paths are matched against filelist - # entries from top to bottom. - # The first match determines inclusion or exclusion. - includeFileList = builtins.toFile "filelist.txt" '' - ${builtins.concatStringsSep "\n" cfg.extraFiles} - - ${optionalString (!cfg.with-bulk-data) '' - - ${config.services.bitcoind.dataDir}/blocks - - ${config.services.bitcoind.dataDir}/chainstate - - ${config.services.bitcoind.dataDir}/indexes - ''} - ${config.services.bitcoind.dataDir} - ${config.services.clightning.dataDir} - ${config.services.clightning-rest.dataDir} - ${config.services.lnd.dataDir} - ${optionalString (!cfg.with-bulk-data) '' - - ${config.services.liquidd.dataDir}/*/blocks - - ${config.services.liquidd.dataDir}/*/chainstate - - ${config.services.liquidd.dataDir}/*/indexes - ''} - ${config.services.liquidd.dataDir} - ${optionalString cfg.with-bulk-data "${config.services.electrs.dataDir}"} - ${config.services.nbxplorer.dataDir} - ${config.services.btcpayserver.dataDir} - ${config.services.joinmarket.dataDir} - ${optionalString config.nix-bitcoin.generateSecrets "${config.nix-bitcoin.secretsDir}"} - /var/lib/tor - /var/lib/nixos - - ${builtins.concatStringsSep "\n" postgresqlBackupPaths} - - # Exclude all unspecified files and directories - - / - ''; - - postgresqlBackupDir = config.services.postgresqlBackup.location; - postgresqlBackupPaths = map (db: "${postgresqlBackupDir}/${db}.sql.gz") cfg.postgresqlDatabases; - postgresqlBackupServices = map (db: "postgresqlBackup-${db}.service") cfg.postgresqlDatabases; -in { - inherit options; - - config = mkIf cfg.enable { - environment.systemPackages = [ pkgs.duplicity ]; - - services.duplicity = { - enable = true; - inherit includeFileList; - fullIfOlderThan = mkDefault "1M"; - targetUrl = cfg.destination; - frequency = cfg.frequency; - secretFile = "${config.nix-bitcoin.secretsDir}/backup-encryption-env"; - }; - - systemd.services.duplicity = { - wants = postgresqlBackupServices; - after = postgresqlBackupServices ++ [ "nix-bitcoin-secrets.target" ]; - }; - - services.postgresqlBackup = { - enable = mkIf (cfg.postgresqlDatabases != []) true; - databases = cfg.postgresqlDatabases; - }; - - nix-bitcoin.secrets.backup-encryption-env.user = "root"; - nix-bitcoin.generateSecretsCmds.backups = '' - makePasswordSecret backup-encryption-password - if [[ backup-encryption-password -nt backup-encryption-env ]]; then - echo "PASSPHRASE=$(cat backup-encryption-password)" > backup-encryption-env - fi - ''; - - services.backups.postgresqlDatabases = mkIf config.services.btcpayserver.enable ( - [ "btcpaydb" ] ++ optional cfg.with-bulk-data "nbxplorer" - ); - }; -} diff --git a/modules/bitcoind.nix b/modules/bitcoind.nix index 36ef911..d0df9bd 100644 --- a/modules/bitcoind.nix +++ b/modules/bitcoind.nix @@ -173,14 +173,6 @@ let default = if cfg.tor.proxy then config.nix-bitcoin.torClientAddressWithPort else null; description = "Connect through SOCKS5 proxy"; }; - i2p = mkOption { - type = types.enum [ false true "only-outgoing" ]; - default = false; - description = '' - Enable peer connections via i2p. - With `only-outgoing`, incoming i2p connections are disabled. - ''; - }; dataDirReadableByGroup = mkOption { type = types.bool; default = false; @@ -289,8 +281,6 @@ let nbLib = config.nix-bitcoin.lib; secretsDir = config.nix-bitcoin.secretsDir; - i2pSAM = config.services.i2pd.proto.sam; - configFile = builtins.toFile "bitcoin.conf" '' # We're already logging via journald nodebuglogfile=1 @@ -318,8 +308,6 @@ let ${optionalString cfg.listenWhitelisted "whitebind=${cfg.address}:${toString cfg.whitelistedPort}"} ${optionalString (cfg.proxy != null) "proxy=${cfg.proxy}"} - ${optionalString (cfg.i2p != false) "i2psam=${nbLib.addressWithPort i2pSAM.address i2pSAM.port}"} - ${optionalString (cfg.i2p == "only-outgoing") "i2pacceptincoming=0"} ${optionalString (cfg.discover != null) "discover=${if cfg.discover then "1" else "0"}"} ${lib.concatMapStrings (node: "addnode=${node}\n") cfg.addnodes} @@ -377,11 +365,6 @@ in { } ]; - services.i2pd = mkIf (cfg.i2p != false) { - enable = true; - proto.sam.enable = true; - }; - systemd.tmpfiles.rules = [ "d '${cfg.dataDir}' 0770 ${cfg.user} ${cfg.group} - -" ]; @@ -392,9 +375,6 @@ in { # Use `wants` instead of `requires` for `nix-bitcoin-secrets.target` # so that bitcoind and all dependent services are not restarted when # the secrets target restarts. - # The secrets target always restarts when deploying with one of the methods - # in ./deployment. - # # TODO-EXTERNAL: Instead of `wants`, use a future systemd dependency type # that propagates initial start failures but no restarts "nix-bitcoin-secrets.target" diff --git a/modules/btcpayserver.nix b/modules/btcpayserver.nix deleted file mode 100644 index 5fecc57..0000000 --- a/modules/btcpayserver.nix +++ /dev/null @@ -1,287 +0,0 @@ -{ config, lib, pkgs, ... }: - -with lib; -let - options.services = { - btcpayserver = { - enable = mkEnableOption "btcpayserver, a self-hosted Bitcoin payment processor"; - address = mkOption { - type = types.str; - default = "127.0.0.1"; - description = "Address to listen on."; - }; - port = mkOption { - type = types.port; - default = 23000; - description = "Port to listen on."; - }; - package = mkOption { - type = types.package; - default = if cfg.btcpayserver.lbtc then - config.nix-bitcoin.pkgs.btcpayserver.override { altcoinSupport = true; } - else - config.nix-bitcoin.pkgs.btcpayserver; - defaultText = "(See source)"; - description = "The package providing btcpayserver binaries."; - }; - dataDir = mkOption { - type = types.path; - default = "/var/lib/btcpayserver"; - description = "The data directory for btcpayserver."; - }; - lightningBackend = mkOption { - type = types.nullOr (types.enum [ "clightning" "lnd" ]); - default = null; - description = "The lightning node implementation to use."; - }; - lbtc = mkOption { - type = types.bool; - default = false; - description = "Enable liquid support in btcpayserver."; - }; - rootpath = mkOption { - type = types.nullOr types.str; - default = null; - example = "btcpayserver"; - description = "The prefix for root-relative btcpayserver URLs."; - }; - user = mkOption { - type = types.str; - default = "btcpayserver"; - description = "The user as which to run btcpayserver."; - }; - group = mkOption { - type = types.str; - default = cfg.btcpayserver.user; - description = "The group as which to run btcpayserver."; - }; - tor.enforce = nbLib.tor.enforce; - }; - - nbxplorer = { - enable = mkOption { - # This option is only used by netns-isolation - internal = true; - default = cfg.btcpayserver.enable; - description = '' - nbxplorer is always enabled when btcpayserver is enabled. - ''; - }; - package = mkOption { - type = types.package; - default = config.nix-bitcoin.pkgs.nbxplorer; - defaultText = "config.nix-bitcoin.pkgs.nbxplorer"; - description = "The package providing nbxplorer binaries."; - }; - address = mkOption { - type = types.str; - default = "127.0.0.1"; - description = "Address to listen on."; - }; - port = mkOption { - type = types.port; - default = 24444; - description = "Port to listen on."; - }; - dataDir = mkOption { - type = types.path; - default = "/var/lib/nbxplorer"; - description = "The data directory for nbxplorer."; - }; - user = mkOption { - type = types.str; - default = "nbxplorer"; - description = "The user as which to run nbxplorer."; - }; - group = mkOption { - type = types.str; - default = cfg.nbxplorer.user; - description = "The group as which to run nbxplorer."; - }; - tor.enforce = nbLib.tor.enforce; - }; - }; - - cfg = config.services; - nbLib = config.nix-bitcoin.lib; - - inherit (config.services) bitcoind liquidd; -in { - inherit options; - - config = mkIf cfg.btcpayserver.enable { - services.bitcoind = { - enable = true; - rpc.users.btcpayserver = { - passwordHMACFromFile = true; - rpcwhitelist = cfg.bitcoind.rpc.users.public.rpcwhitelist ++ [ - "setban" - "generatetoaddress" - ]; - }; - listenWhitelisted = true; - }; - services.clightning.enable = mkIf (cfg.btcpayserver.lightningBackend == "clightning") true; - services.lnd = mkIf (cfg.btcpayserver.lightningBackend == "lnd") { - enable = true; - macaroons.btcpayserver = { - inherit (cfg.btcpayserver) user; - permissions = ''{"entity":"info","action":"read"},{"entity":"onchain","action":"read"},{"entity":"offchain","action":"read"},{"entity":"address","action":"read"},{"entity":"message","action":"read"},{"entity":"peers","action":"read"},{"entity":"signer","action":"read"},{"entity":"invoices","action":"read"},{"entity":"invoices","action":"write"},{"entity":"address","action":"write"}''; - }; - }; - services.liquidd = mkIf cfg.btcpayserver.lbtc { - enable = true; - listenWhitelisted = true; - }; - services.postgresql = { - enable = true; - ensureDatabases = [ - "btcpaydb" # This name is kept for backwards compatibility - "nbxplorer" - ]; - ensureUsers = [ - { name = cfg.btcpayserver.user; } - { name = cfg.nbxplorer.user; } - ]; - }; - systemd.services.postgresql-setup.postStart = '' - psql -tAc ' - ALTER DATABASE "btcpaydb" OWNER TO "${cfg.btcpayserver.user}"; - ALTER DATABASE "nbxplorer" OWNER TO "${cfg.nbxplorer.user}"; - ' - ''; - - systemd.tmpfiles.rules = [ - "d '${cfg.nbxplorer.dataDir}' 0770 ${cfg.nbxplorer.user} ${cfg.nbxplorer.group} - -" - "d '${cfg.btcpayserver.dataDir}' 0770 ${cfg.btcpayserver.user} ${cfg.btcpayserver.group} - -" - ]; - - systemd.services.nbxplorer = let - configFile = builtins.toFile "config" '' - network=${bitcoind.network} - btcrpcuser=${cfg.bitcoind.rpc.users.btcpayserver.name} - btcrpcurl=http://${nbLib.addressWithPort bitcoind.rpc.address cfg.bitcoind.rpc.port} - btcnodeendpoint=${nbLib.addressWithPort bitcoind.address bitcoind.whitelistedPort} - bind=${cfg.nbxplorer.address} - port=${toString cfg.nbxplorer.port} - ${optionalString cfg.btcpayserver.lbtc '' - chains=btc,lbtc - lbtcrpcuser=${liquidd.rpcuser} - lbtcrpcurl=http://${nbLib.addressWithPort liquidd.rpc.address liquidd.rpc.port} - lbtcnodeendpoint=${nbLib.addressWithPort liquidd.address liquidd.whitelistedPort} - ''} - postgres=User ID=${cfg.nbxplorer.user};Host=/run/postgresql;Database=nbxplorer - ''; - in rec { - wantedBy = [ "multi-user.target" ]; - requires = [ "postgresql.target" ]; - wants = [ "bitcoind.service" ] ++ optional cfg.btcpayserver.lbtc "liquidd.service"; - after = requires ++ wants ++ [ "nix-bitcoin-secrets.target" ]; - preStart = '' - install -m 600 ${configFile} '${cfg.nbxplorer.dataDir}/settings.config' - { - echo "btcrpcpassword=$(cat ${config.nix-bitcoin.secretsDir}/bitcoin-rpcpassword-btcpayserver)" - ${optionalString cfg.btcpayserver.lbtc '' - echo "lbtcrpcpassword=$(cat ${config.nix-bitcoin.secretsDir}/liquid-rpcpassword)" - ''} - } >> '${cfg.nbxplorer.dataDir}/settings.config' - ''; - serviceConfig = nbLib.defaultHardening // { - ExecStart = '' - ${cfg.nbxplorer.package}/bin/nbxplorer --conf=${cfg.nbxplorer.dataDir}/settings.config \ - --datadir=${cfg.nbxplorer.dataDir} - ''; - User = cfg.nbxplorer.user; - Restart = "on-failure"; - RestartSec = "10s"; - ReadWritePaths = [ cfg.nbxplorer.dataDir ]; - MemoryDenyWriteExecute = false; - } // nbLib.allowedIPAddresses cfg.nbxplorer.tor.enforce; - }; - - systemd.services.btcpayserver = let - nbExplorerUrl = "http://${nbLib.addressWithPort cfg.nbxplorer.address cfg.nbxplorer.port}/"; - nbExplorerCookie = "${cfg.nbxplorer.dataDir}/${bitcoind.makeNetworkName "Main" "RegTest"}/.cookie"; - configFile = builtins.toFile "btcpayserver-config" ('' - network=${bitcoind.network} - bind=${cfg.btcpayserver.address} - port=${toString cfg.btcpayserver.port} - socksendpoint=${config.nix-bitcoin.torClientAddressWithPort} - btcexplorerurl=${nbExplorerUrl} - btcexplorercookiefile=${nbExplorerCookie} - postgres=User ID=${cfg.btcpayserver.user};Host=/run/postgresql;Database=btcpaydb - '' + optionalString (cfg.btcpayserver.rootpath != null) '' - rootpath=${cfg.btcpayserver.rootpath} - '' + optionalString (cfg.btcpayserver.lightningBackend == "clightning") '' - btclightning=type=clightning;server=unix:///${cfg.clightning.dataDir}/${bitcoind.makeNetworkName "bitcoin" "regtest"}/lightning-rpc - '' + optionalString (cfg.btcpayserver.lightningBackend == "lnd") - ( - "btclightning=type=lnd-rest;" + - "server=https://${nbLib.address cfg.lnd.restAddress}:${toString cfg.lnd.restPort}/;" + - "macaroonfilepath=/run/lnd/btcpayserver.macaroon;" + - "certfilepath=${config.services.lnd.certPath}" + - "\n" - ) - + optionalString cfg.btcpayserver.lbtc '' - chains=btc,lbtc - lbtcexplorerurl=${nbExplorerUrl} - lbtcexplorercookiefile=${nbExplorerCookie} - ''); - in rec { - wantedBy = [ "multi-user.target" ]; - requires = [ "postgresql.target" ]; - wants = [ "nbxplorer.service" ] - ++ optional (cfg.btcpayserver.lightningBackend != null) "${cfg.btcpayserver.lightningBackend}.service"; - after = requires ++ wants; - serviceConfig = nbLib.defaultHardening // { - ExecStart = '' - ${cfg.btcpayserver.package}/bin/btcpayserver --conf=${configFile} \ - --datadir='${cfg.btcpayserver.dataDir}' - ''; - User = cfg.btcpayserver.user; - # Since 2.4.0, btcpayserver uses `Host.CreateDefaultBuilder`, which sets the - # ASP.NET content root to the working directory instead of the app directory. - # The web root (`wwwroot`) is resolved relative to the content root, so - # btcpayserver must be started from its app directory. - WorkingDirectory = "${cfg.btcpayserver.package}/lib/btcpayserver"; - # Also restart after the program has exited successfully. - # This is required to support restarting from the web interface after - # interactive plugin installation. - # Restart rate limiting is implemented via the `startLimit*` options below. - Restart = "always"; - ReadWritePaths = [ cfg.btcpayserver.dataDir ]; - MemoryDenyWriteExecute = false; - } // nbLib.allowedIPAddresses cfg.btcpayserver.tor.enforce; - startLimitIntervalSec = 30; - startLimitBurst = 10; - }; - - users.users.${cfg.nbxplorer.user} = { - isSystemUser = true; - group = cfg.nbxplorer.group; - extraGroups = [ "bitcoinrpc-public" ] - ++ optional cfg.btcpayserver.lbtc liquidd.group; - home = cfg.nbxplorer.dataDir; - }; - users.groups.${cfg.nbxplorer.group} = {}; - users.users.${cfg.btcpayserver.user} = { - isSystemUser = true; - group = cfg.btcpayserver.group; - extraGroups = [ cfg.nbxplorer.group ] - ++ optional (cfg.btcpayserver.lightningBackend == "clightning") cfg.clightning.user; - home = cfg.btcpayserver.dataDir; - }; - users.groups.${cfg.btcpayserver.group} = {}; - - nix-bitcoin.secrets = { - bitcoin-rpcpassword-btcpayserver = { - user = cfg.bitcoind.user; - group = cfg.nbxplorer.group; - }; - bitcoin-HMAC-btcpayserver.user = cfg.bitcoind.user; - }; - nix-bitcoin.generateSecretsCmds.btcpayserver = '' - makeBitcoinRPCPassword btcpayserver - ''; - }; -} diff --git a/modules/charge-lnd.nix b/modules/charge-lnd.nix deleted file mode 100644 index d9053c9..0000000 --- a/modules/charge-lnd.nix +++ /dev/null @@ -1,136 +0,0 @@ -{ config, lib, pkgs, ... }: - -with lib; -let - options.services.charge-lnd = with types; { - enable = mkEnableOption "charge-lnd, policy-based fee manager"; - - extraFlags = mkOption { - type = listOf str; - default = []; - example = [ "--verbose" "--dry-run" ]; - description = "Extra flags to pass to the charge-lnd command."; - }; - - interval = mkOption { - type = str; - default = "*-*-* 04:00:00"; - example = "hourly"; - description = '' - Systemd calendar expression when to adjust fees. - - See {man}`systemd.time(7)` for possible values. - - Default is once a day. - ''; - }; - - randomDelay = mkOption { - type = str; - default = "1h"; - description = '' - Random delay to add to scheduled time. - ''; - }; - - policies = mkOption { - type = types.lines; - default = ""; - example = '' - [discourage-routing-out-of-balance] - chan.max_ratio = 0.1 - chan.min_capacity = 250000 - strategy = static - base_fee_msat = 10000 - fee_ppm = 500 - - [encourage-routing-to-balance] - chan.min_ratio = 0.9 - chan.min_capacity = 250000 - strategy = static - base_fee_msat = 1 - fee_ppm = 2 - - [default] - strategy = ignore - ''; - description = '' - Policy definitions in INI format. - - See https://github.com/accumulator/charge-lnd/blob/master/README.md#usage - for possible properties and parameters. - - Policies are evaluated from top to bottom. - The first matching policy (or `default`) is applied. - ''; - }; - }; - - cfg = config.services.charge-lnd; - nbLib = config.nix-bitcoin.lib; - - lnd = config.services.lnd; - - user = "charge-lnd"; - group = user; - dataDir = "/var/lib/charge-lnd"; - configFile = builtins.toFile "charge-lnd.config" cfg.policies; - checkedConfig = pkgs.runCommand "charge-lnd-checked.config" { } '' - ${config.nix-bitcoin.pkgs.charge-lnd}/bin/charge-lnd --check --config ${configFile} - cp ${configFile} $out - ''; -in -{ - inherit options; - - config = mkIf cfg.enable { - services.lnd = { - enable = true; - macaroons.charge-lnd = { - user = user; - permissions = ''{"entity":"info","action":"read"},{"entity":"onchain","action":"read"},{"entity":"offchain","action":"read"},{"entity":"offchain","action":"write"}''; - }; - }; - - systemd.services.charge-lnd = { - documentation = [ "https://github.com/accumulator/charge-lnd/blob/master/README.md" ]; - after = [ "lnd.service" ]; - requires = [ "lnd.service" ]; - # lnd's data directory (--lnddir) is not accessible to charge-lnd. - # Instead use directory "lnddir-proxy" as lnddir and link relevant files to it. - preStart = '' - macaroonDir=${dataDir}/lnddir-proxy/data/chain/bitcoin/mainnet - mkdir -p $macaroonDir - ln -sf /run/lnd/charge-lnd.macaroon $macaroonDir - ln -sf ${lnd.certPath} ${dataDir}/lnddir-proxy/tls.cert - ''; - serviceConfig = nbLib.defaultHardening // { - ExecStart = '' - ${config.nix-bitcoin.pkgs.charge-lnd}/bin/charge-lnd \ - --lnddir ${dataDir}/lnddir-proxy \ - --grpc ${nbLib.addressWithPort lnd.rpcAddress lnd.rpcPort} \ - --config ${checkedConfig} \ - ${escapeShellArgs cfg.extraFlags} - ''; - Type = "oneshot"; - User = user; - Group = group; - StateDirectory = "charge-lnd"; - } // nbLib.allowLocalIPAddresses; - }; - - systemd.timers.charge-lnd = { - wantedBy = [ "timers.target" ]; - timerConfig = { - OnCalendar = cfg.interval; - RandomizedDelaySec = cfg.randomDelay; - }; - }; - - users.users.${user} = { - isSystemUser = true; - group = group; - }; - users.groups.${group} = {}; - }; -} diff --git a/modules/clightning-plugins/clboss.nix b/modules/clightning-plugins/clboss.nix deleted file mode 100644 index 60bb29d..0000000 --- a/modules/clightning-plugins/clboss.nix +++ /dev/null @@ -1,64 +0,0 @@ -{ config, lib, pkgs, ... }: - -with lib; -let cfg = config.services.clightning.plugins.clboss; in -{ - options.services.clightning.plugins.clboss = { - enable = mkOption { - type = types.bool; - default = false; - description = '' - Whether to enable CLBOSS (clightning plugin). - See also: https://github.com/ZmnSCPxj/clboss#operating - ''; - }; - min-onchain = mkOption { - type = types.ints.positive; - default = 30000; - description = '' - Target amount (in satoshi) that CLBOSS will leave on-chain. - clboss will only open new channels if the funds in your clightning wallet are - larger than this amount. - ''; - }; - min-channel = mkOption { - type = types.ints.positive; - default = 500000; - description = "The minimum size (in satoshi) of channels created by CLBOSS."; - }; - max-channel = mkOption { - type = types.ints.positive; - default = 16777215; - description = "The maximum size (in satoshi) of channels created by CLBOSS."; - }; - zerobasefee = mkOption { - type = types.enum [ "require" "allow" "disallow" ]; - default = "allow"; - description = '' - `require`: set `base_fee` to 0. - `allow`: set `base_fee` according to the CLBOSS heuristics, which may include value 0. - `disallow`: set `base_fee` to according to the CLBOSS heuristics, with a minimum value of 1. - ''; - }; - package = mkOption { - type = types.package; - default = config.nix-bitcoin.pkgs.clboss; - defaultText = "config.nix-bitcoin.pkgs.clboss"; - description = "The package providing clboss binaries."; - }; - }; - - config = mkIf cfg.enable { - services.clightning.extraConfig = '' - plugin=${cfg.package}/bin/clboss - clboss-min-onchain=${toString cfg.min-onchain} - clboss-min-channel=${toString cfg.min-channel} - clboss-max-channel=${toString cfg.max-channel} - clboss-zerobasefee=${cfg.zerobasefee} - ''; - - systemd.services.clightning.path = [ - pkgs.dnsutils - ] ++ optional config.services.clightning.tor.proxy (hiPrio config.nix-bitcoin.torify); - }; -} diff --git a/modules/clightning-plugins/clnrest.nix b/modules/clightning-plugins/clnrest.nix deleted file mode 100644 index d8f42be..0000000 --- a/modules/clightning-plugins/clnrest.nix +++ /dev/null @@ -1,90 +0,0 @@ -{ config, lib, pkgs, ... }: - -with lib; -let - options = { - services.clightning.plugins.clnrest = { - enable = mkOption { - type = types.bool; - default = false; - description = '' - Enable clnrest (clightning plugin). - - clnrest provides a clightning REST API, using clightning RPC calls as its backend. - It also broadcasts clightning notifications to listeners connected to its websocket server. - - See here for all available options: - https://docs.corelightning.org/docs/rest - Extra options can be set via `services.clightning.extraConfig`. - ''; - }; - address = mkOption { - type = types.str; - default = "127.0.0.1"; - description = "Address to listen for REST connections."; - }; - port = mkOption { - type = types.port; - default = 3010; - description = "REST server port."; - }; - createAdminRune = mkOption { - type = types.bool; - default = true; - description = '' - Create a rune with admin permissions at path `''${config.services.clightning.networkDir}/admin-rune`. - ''; - }; - package = mkOption { - type = types.package; - default = config.nix-bitcoin.pkgs.clnrest; - defaultText = "config.nix-bitcoin.pkgs.clnrest"; - description = "The package providing clnrest binaries."; - }; - }; - - # Internal read-only options used by `./nodeinfo.nix` and `./onion-services.nix` - services.clnrest = let - inherit (config.nix-bitcoin.lib) mkAlias; - in { - enable = mkAlias cfg.enable; - address = mkAlias cfg.address; - port = mkAlias cfg.port; - }; - }; - - cfg = config.services.clightning.plugins.clnrest; - nbLib = config.nix-bitcoin.lib; - inherit (config.services) clightning; - - runePath = "${clightning.networkDir}/admin-rune"; -in -{ - inherit options; - - config = mkIf cfg.enable { - services.clightning.extraConfig = '' - plugin=${cfg.package}/bin/clnrest - clnrest-host=${cfg.address} - clnrest-port=${toString cfg.port} - ''; - - systemd.services.clightning.postStart = mkAfter ( - optionalString cfg.createAdminRune '' - if [[ ! -e '${runePath}' ]]; then - rune=$(${clightning.cli}/bin/lightning-cli createrune | ${pkgs.jq}/bin/jq -r .rune) - install -m 640 <(echo "$rune") '${runePath}' - fi - '' + - # Wait until the clnrest server is listening. - # Usually, the server is already listening at this point. - # But when clnrest is running for the first time, certificates are generated - # before the server starts, which can take a few seconds. - '' - while ! { exec 3>/dev/tcp/${nbLib.address cfg.address}/${toString cfg.port}; } &>/dev/null; do - sleep 0.1 - done - '' - ); - }; -} diff --git a/modules/clightning-plugins/default.nix b/modules/clightning-plugins/default.nix deleted file mode 100644 index 10744cf..0000000 --- a/modules/clightning-plugins/default.nix +++ /dev/null @@ -1,31 +0,0 @@ -{ config, lib, pkgs, ... }: - -with lib; -let - options.services.clightning.plugins = { - currencyrate.enable = mkEnableOption "Currencyrate (clightning plugin)"; - monitor.enable = mkEnableOption "Monitor (clightning plugin)"; - rebalance.enable = mkEnableOption "Rebalance (clightning plugin)"; - }; - - cfg = config.services.clightning.plugins; - pluginPkgs = config.nix-bitcoin.pkgs.clightning-plugins; -in { - imports = [ - ./clboss.nix - ./clnrest.nix - ./feeadjuster.nix - ./trustedcoin.nix - ./zmq.nix - ]; - - inherit options; - - config = { - services.clightning.extraConfig = mkMerge [ - (mkIf cfg.currencyrate.enable "plugin=${pluginPkgs.currencyrate.path}") - (mkIf cfg.monitor.enable "plugin=${pluginPkgs.monitor.path}") - (mkIf cfg.rebalance.enable "plugin=${pluginPkgs.rebalance.path}") - ]; - }; -} diff --git a/modules/clightning-plugins/feeadjuster.nix b/modules/clightning-plugins/feeadjuster.nix deleted file mode 100644 index 7e7c905..0000000 --- a/modules/clightning-plugins/feeadjuster.nix +++ /dev/null @@ -1,78 +0,0 @@ -{ config, lib, ... }: - -with lib; -let - options.services.clightning.plugins.feeadjuster = { - enable = mkOption { - type = types.bool; - default = false; - description = '' - Enable feeaduster (clightning plugin). - This plugin auto-updates channel fees to keep channels balanced. - - See here for all available options: - https://github.com/lightningd/plugins/blob/master/feeadjuster/feeadjuster.py - Extra options can be set via `services.clightning.extraConfig`. - ''; - }; - fuzz = mkOption { - type = types.bool; - default = true; - description = "Enable update threshold randomization and hysteresis."; - }; - adjustOnForward = mkOption { - type = types.bool; - default = false; - description = "Automatically update fees on forward events."; - }; - method = mkOption { - type = types.enum [ "soft" "default" "hard" ]; - default = "default"; - description = '' - Adjustment method to calculate channel fees. - `soft`: less difference when adjusting fees. - `hard`: greater difference when adjusting fees. - ''; - }; - adjustDaily = mkOption { - type = types.bool; - default = true; - description = "Automatically update fees daily."; - }; - }; - - cfg = config.services.clightning.plugins.feeadjuster; - inherit (config.services) clightning; -in -{ - inherit options; - - config = mkIf (cfg.enable && clightning.enable) { - services.clightning.extraConfig = '' - plugin=${config.nix-bitcoin.pkgs.clightning-plugins.feeadjuster.path} - feeadjuster-adjustment-method="${cfg.method}" - '' + optionalString (!cfg.fuzz) '' - feeadjuster-deactivate-fuzz - '' + optionalString (!cfg.adjustOnForward) '' - feeadjuster-deactivate-fee-update - ''; - - systemd = mkIf cfg.adjustDaily { - services.clightning-feeadjuster = { - # Only run when clightning is running - requisite = [ "clightning.service" ]; - after = [ "clightning.service" ]; - serviceConfig = { - Type = "oneshot"; - User = "clightning"; - ExecStart = "${clightning.package}/bin/lightning-cli --lightning-dir ${clightning.dataDir} feeadjust"; - }; - unitConfig.JoinsNamespaceOf = [ "clightning.service" ]; - startAt = [ "daily" ]; - }; - timers.clightning-feeadjuster.timerConfig = { - RandomizedDelaySec = "6h"; - }; - }; - }; -} diff --git a/modules/clightning-plugins/trustedcoin.nix b/modules/clightning-plugins/trustedcoin.nix deleted file mode 100644 index e55b8f0..0000000 --- a/modules/clightning-plugins/trustedcoin.nix +++ /dev/null @@ -1,40 +0,0 @@ -{ config, lib, pkgs, ... }: - -with lib; -let cfg = config.services.clightning.plugins.trustedcoin; in -{ - options.services.clightning.plugins.trustedcoin = { - enable = mkEnableOption "Trustedcoin (clightning plugin)"; - - package = mkOption { - type = types.package; - default = config.nix-bitcoin.pkgs.trustedcoin; - defaultText = "config.nix-bitcoin.pkgs.trustedcoin"; - description = "The package providing trustedcoin binaries."; - }; - - tor.proxy = mkOption { - type = types.bool; - default = config.services.clightning.tor.proxy; - description = "Whether to proxy outgoing connections with Tor."; - }; - }; - - config = mkIf cfg.enable { - services.clightning = { - useBcliPlugin = false; - extraConfig = '' - plugin=${cfg.package}/bin/trustedcoin - ''; - tor.enforce = mkIf (!cfg.tor.proxy) false; - }; - - systemd.services.clightning.environment = mkIf (cfg.tor.proxy) { - HTTPS_PROXY = let - clnProxy = config.services.clightning.proxy; - proxy = if clnProxy != null then clnProxy else config.nix-bitcoin.torClientAddressWithPort; - in - "socks5://${proxy}"; - }; - }; -} diff --git a/modules/clightning-plugins/zmq.nix b/modules/clightning-plugins/zmq.nix deleted file mode 100644 index f2e7627..0000000 --- a/modules/clightning-plugins/zmq.nix +++ /dev/null @@ -1,50 +0,0 @@ -{ config, lib, ... }: - -with lib; -let - options.services.clightning.plugins.zmq = { - enable = mkEnableOption "ZMQ (clightning plugin)"; - } // lib.genAttrs endpoints mkEndpointOption; - - cfg = config.services.clightning.plugins.zmq; - - nbLib = config.nix-bitcoin.lib; - - endpoints = [ - "channel-opened" - "connect" - "disconnect" - "invoice-payment" - "warning" - "forward-event" - "sendpay-success" - "sendpay-failure" - ]; - - mkEndpointOption = name: - mkOption { - type = types.nullOr types.str; - default = null; - description = "Endpoint for ${name}"; - }; - - setEndpoint = ep: - let value = builtins.getAttr ep cfg; in - optionalString (value != null) '' - zmq-pub-${ep}=${value} - ''; -in -{ - inherit options; - - config = mkIf cfg.enable { - services.clightning.extraConfig = '' - plugin=${config.nix-bitcoin.pkgs.clightning-plugins.zmq.path} - ${concatStrings (map setEndpoint endpoints)} - ''; - - # The zmq server requires AF_NETLINK - systemd.services.clightning.serviceConfig.RestrictAddressFamilies = - mkForce nbLib.allowNetlink.RestrictAddressFamilies; - }; -} diff --git a/modules/clightning-replication.nix b/modules/clightning-replication.nix deleted file mode 100644 index 9ee4eeb..0000000 --- a/modules/clightning-replication.nix +++ /dev/null @@ -1,230 +0,0 @@ -{ config, lib, pkgs, ... }: - -with lib; -let - options.services.clightning.replication = { - enable = mkOption { - type = types.bool; - default = false; - description = '' - Enable live replication of the clightning database. - This prevents losing off-chain funds when the primary wallet file becomes - inaccessible. - - For setting the destination, you can either define option `sshfs.destination` - or `local.directory`. - - When `encrypt` is `false`, file `lightningd.sqlite3` is written to the destination. - When `encrypt` is `true`, directory `lightningd-db` is written to the destination. - It includes the encrypted database and gocryptfs metadata. - - See also: https://github.com/ElementsProject/lightning/blob/master/doc/BACKUP.md - ''; - }; - sshfs = { - destination = mkOption { - type = types.nullOr types.str; - default = null; - example = "user@10.0.0.1:directory"; - description = '' - The SSH destination for which a SSHFS will be mounted. - `directory` is relative to the home of `user`. - - A SSH key is automatically generated and stored in file - `$secretsDir/clightning-replication-ssh`. - The SSH server must allow logins via this key. - I.e., the `authorized_keys` file of `user` must contain - `$secretsDir/clightning-replication-ssh.pub`. - ''; - }; - port = mkOption { - type = types.port; - default = 22; - description = "SSH port of the remote server."; - }; - sshOptions = mkOption { - type = with types; listOf str; - default = [ "reconnect" "ServerAliveInterval=50" ]; - description = "SSH options used for mounting the SSHFS."; - }; - }; - local = { - directory = mkOption { - type = types.nullOr types.path; - default = null; - example = "/var/backup/clightning"; - description = '' - This option can be specified instead of `sshfs.destination` to enable - replication to a local directory. - - If `local.setupDirectory` is disabled, the directory - - must already exist when `clightning.service` (or `clightning-replication-mounts.service` - if `encrypt` is `true`) starts. - - must have write permissions for the `clightning` user. - - This option is also useful if you want to use a custom remote destination, - like a NFS or SMB share. - ''; - }; - setupDirectory = mkOption { - type = types.bool; - default = true; - description = '' - Create `local.directory` if it doesn't exist and set write permissions - for the `clightning` user. - ''; - }; - }; - encrypt = mkOption { - type = types.bool; - default = false; - description = '' - Whether to encrypt the replicated database with gocryptfs. - The encryption password is automatically generated and stored - in file {file}`$secretsDir/clightning-replication-password`. - ''; - }; - }; - - cfg = config.services.clightning.replication; - inherit (config.services) clightning; - - secretsDir = config.nix-bitcoin.secretsDir; - network = config.services.bitcoind.makeNetworkName "bitcoin" "regtest"; - user = clightning.user; - group = clightning.group; - - useSshfs = cfg.sshfs.destination != null; - useMounts = useSshfs || cfg.encrypt; - - localDir = cfg.local.directory; - mountsDir = "/var/cache/clightning-replication"; - sshfsDir = "${mountsDir}/sshfs"; - plaintextDir = "${mountsDir}/plaintext"; - destDir = - if cfg.encrypt then - plaintextDir - else if useSshfs then - sshfsDir - else - localDir; -in { - inherit options; - - config = mkIf cfg.enable { - assertions = [ - { assertion = useSshfs || (localDir != null); - message = '' - services.clightning.replication: One of `sshfs.destination` or - `local.directory` must be set. - ''; - } - { assertion = !useSshfs || (localDir == null); - message = '' - services.clightning.replication: Only one of `sshfs.destination` and - `local.directory` must be set. - ''; - } - ]; - - environment.systemPackages = optionals cfg.encrypt [ pkgs.gocryptfs ]; - - systemd.tmpfiles.rules = optional (localDir != null && cfg.local.setupDirectory) - "d '${localDir}' 0770 ${user} ${group} - -"; - - services.clightning.wallet = let - mainDB = "${clightning.dataDir}/${network}/lightningd.sqlite3"; - replicaDB = "${destDir}/lightningd.sqlite3"; - in "sqlite3://${mainDB}:${replicaDB}"; - - systemd.services.clightning = { - bindsTo = mkIf useMounts [ "clightning-replication-mounts.service" ]; - serviceConfig.ReadWritePaths = [ - # We can't simply set `destDir` here because it might point to - # a FUSE mount. - # FUSE mounts can only be set up as `ReadWritePaths` by systemd when they - # are accessible by root. - # But FUSE mounts are only accessible by the mounting user and - # not by root. - # (This could be circumvented by FUSE-mounting `destDir` with option `allow_other`, - # but this would grant access to all users.) - (if useMounts then mountsDir else localDir) - ]; - }; - - systemd.services.clightning-replication-mounts = mkIf useMounts { - requiredBy = [ "clightning.service" ]; - before = [ "clightning.service" ]; - wants = [ "nix-bitcoin-secrets.target" ]; - after = [ "nix-bitcoin-secrets.target" ]; - path = [ - # Includes - # - The SUID-wrapped `fusermount` binary which enables FUSE - # for non-root users - # - The SUID-wrapped `mount` binary, used for unmounting - "/run/wrappers" - ] ++ optionals cfg.encrypt [ - # Includes `logger`, required by gocryptfs - pkgs.util-linux - ]; - - script = - optionalString useSshfs '' - mkdir -p ${sshfsDir} - ${pkgs.sshfs}/bin/sshfs ${cfg.sshfs.destination} -p ${toString cfg.sshfs.port} ${sshfsDir} \ - -o ${builtins.concatStringsSep "," ([ - "IdentityFile='${secretsDir}'/clightning-replication-ssh-key" - ] ++ cfg.sshfs.sshOptions)} - '' + - optionalString cfg.encrypt '' - cipherDir="${if useSshfs then sshfsDir else localDir}/lightningd-db" - mkdir -p "$cipherDir" ${plaintextDir} - gocryptfs=(${pkgs.gocryptfs}/bin/gocryptfs -passfile '${secretsDir}/clightning-replication-password') - # 1. init - if [[ ! -e $cipherDir/gocryptfs.conf ]]; then - "''${gocryptfs[@]}" -init "$cipherDir" - fi - # 2. mount - "''${gocryptfs[@]}" "$cipherDir" ${plaintextDir} - ''; - - postStop = - optionalString cfg.encrypt '' - umount ${plaintextDir} || true - '' + - optionalString useSshfs '' - umount ${sshfsDir} - ''; - - serviceConfig = { - StopPropagatedFrom = [ "clightning.service" ]; - CacheDirectory = "clightning-replication"; - CacheDirectoryMode = "770"; - User = user; - RemainAfterExit = "yes"; - Type = "oneshot"; - }; - }; - - nix-bitcoin = mkMerge [ - (mkIf useSshfs { - secrets.clightning-replication-ssh-key = { - user = user; - permissions = "400"; - }; - generateSecretsCmds.clightning-replication-ssh-key = '' - if [[ ! -f clightning-replication-ssh-key ]]; then - ${pkgs.openssh}/bin/ssh-keygen -t ed25519 -q -N "" -C "" -f clightning-replication-ssh-key - fi - ''; - }) - - (mkIf cfg.encrypt { - secrets.clightning-replication-password.user = user; - generateSecretsCmds.clightning-replication-password = '' - makePasswordSecret clightning-replication-password - ''; - }) - ]; - }; -} diff --git a/modules/clightning-rest.nix b/modules/clightning-rest.nix deleted file mode 100644 index 7466640..0000000 --- a/modules/clightning-rest.nix +++ /dev/null @@ -1,105 +0,0 @@ -{ config, lib, pkgs, ... }: - -with lib; -let - options.services.clightning-rest = { - enable = mkEnableOption "lightning-rest"; - port = mkOption { - type = types.port; - default = 3001; - description = "REST server port."; - }; - docPort = mkOption { - type = types.port; - default = 4001; - description = "Swagger API documentation server port."; - }; - dataDir = mkOption { - type = types.path; - default = "/var/lib/clightning-rest"; - description = "The data directory for clightning-rest."; - }; - extraConfig = mkOption { - type = types.attrs; - default = {}; - example = { - DOMAIN = "mynode.org"; - }; - description = '' - Extra config options. - See: https://github.com/Ride-The-Lightning/c-lightning-REST#option-1-via-config-file-cl-rest-configjson - ''; - }; - # Used by ./rtl.nix - group = mkOption { - readOnly = true; - default = clightning.group; - description = "The group under which clightning-rest is run."; - }; - # Rest server address. - # Not configurable. The server always listens on all interfaces: - # https://github.com/Ride-The-Lightning/c-lightning-REST/issues/84 - # Required by netns-isolation. - address = mkOption { - internal = true; - default = "0.0.0.0"; - }; - tor.enforce = nbLib.tor.enforce; - }; - - cfg = config.services.clightning-rest; - nbLib = config.nix-bitcoin.lib; - nbPkgs = config.nix-bitcoin.pkgs; - - inherit (config.services) - bitcoind - clightning; - - configFile = builtins.toFile "clightning-rest-config" (builtins.toJSON ({ - PORT = cfg.port; - DOCPORT = cfg.docPort; - LNRPCPATH = "${clightning.dataDir}/${bitcoind.makeNetworkName "bitcoin" "regtest"}/lightning-rpc"; - EXECMODE = "production"; - PROTOCOL = "https"; - RPCCOMMANDS = ["*"]; - } // cfg.extraConfig)); -in { - inherit options; - - config = mkIf cfg.enable { - services.clightning.enable = true; - - systemd.tmpfiles.rules = [ - "d '${cfg.dataDir}' 0770 ${clightning.user} ${cfg.group} - -" - ]; - - systemd.services.clightning-rest = mkIf cfg.enable { - wantedBy = [ "multi-user.target" ]; - wants = [ "clightning.service" ]; - after = [ "clightning.service" ]; - path = [ pkgs.openssl ]; - environment.CL_REST_STATE_DIR = cfg.dataDir; - preStart = '' - ln -sfn ${configFile} cl-rest-config.json - ''; - postStart = '' - while [[ ! -e '${cfg.dataDir}/certs/access.macaroon' ]]; do - sleep 0.1 - done - ''; - serviceConfig = nbLib.defaultHardening // { - # clightning-rest reads the config file from the working directory - WorkingDirectory = cfg.dataDir; - ExecStart = "${nbPkgs.clightning-rest}/bin/cl-rest"; - # Show "clightning-rest" instead of "node" in the journal - SyslogIdentifier = "clightning-rest"; - User = clightning.user; - Restart = "on-failure"; - RestartSec = "10s"; - ReadWritePaths = [ cfg.dataDir ]; - inherit (nbLib.allowNetlink) RestrictAddressFamilies; - } // nbLib.allowedIPAddresses cfg.tor.enforce - // nbLib.nodejs; - }; - }; -} diff --git a/modules/clightning.nix b/modules/clightning.nix deleted file mode 100644 index 3427851..0000000 --- a/modules/clightning.nix +++ /dev/null @@ -1,208 +0,0 @@ -{ config, lib, pkgs, ... }: - -with lib; -let - options.services.clightning = { - enable = mkEnableOption "clightning, a Lightning Network implementation in C"; - address = mkOption { - type = types.str; - default = "127.0.0.1"; - description = "Address to listen for peer connections."; - }; - port = mkOption { - type = types.port; - default = 9735; - description = "Port to listen for peer connections."; - }; - proxy = mkOption { - type = types.nullOr types.str; - default = if cfg.tor.proxy then config.nix-bitcoin.torClientAddressWithPort else null; - description = '' - Socks proxy for connecting to Tor nodes (or for all connections if option always-use-proxy is set). - ''; - }; - always-use-proxy = mkOption { - type = types.bool; - default = cfg.tor.proxy; - description = '' - Always use the proxy, even to connect to normal IP addresses. - You can still connect to Unix domain sockets manually. - This also disables all DNS lookups, to avoid leaking address information. - ''; - }; - dataDir = mkOption { - type = types.path; - default = "/var/lib/clightning"; - description = "The data directory for clightning."; - }; - networkDir = mkOption { - readOnly = true; - default = "${cfg.dataDir}/${network}"; - description = "The network data directory."; - }; - wallet = mkOption { - type = types.nullOr types.str; - default = null; - example = "sqlite3:///var/lib/clightning/bitcoin/lightningd.sqlite3"; - description = '' - Wallet data scheme (sqlite3 or postgres) and location/connection - parameters, as fully qualified data source name. - ''; - }; - useBcliPlugin = mkOption { - type = types.bool; - default = true; - description = '' - Use bitcoind (via plugin `bcli`) for getting block data. - This option is disabled by plugins that use other sources for - fetching block data, like `trustedcoin`. - ''; - }; - extraConfig = mkOption { - type = types.lines; - default = ""; - example = '' - alias=mynode - ''; - description = '' - Extra lines appended to the configuration file. - - See all available options at - https://github.com/ElementsProject/lightning/blob/master/doc/lightningd-config.5.md - or by running {command}`lightningd --help`. - ''; - }; - user = mkOption { - type = types.str; - default = "clightning"; - description = "The user as which to run clightning."; - }; - group = mkOption { - type = types.str; - default = cfg.user; - description = "The group as which to run clightning."; - }; - package = mkOption { - type = types.package; - default = nbPkgs.clightning; - defaultText = "config.nix-bitcoin.pkgs.clightning"; - description = "The package providing clightning binaries."; - }; - cli = mkOption { - readOnly = true; - default = pkgs.writers.writeBashBin "lightning-cli" '' - ${cfg.package}/bin/lightning-cli --lightning-dir='${cfg.dataDir}' "$@" - ''; - defaultText = "(See source)"; - description = "Binary to connect with the clightning instance."; - }; - getPublicAddressCmd = mkOption { - type = types.str; - default = ""; - description = '' - Bash expression which outputs the public service address to announce to peers. - If left empty, no address is announced. - ''; - }; - tor = nbLib.tor; - }; - - cfg = config.services.clightning; - nbLib = config.nix-bitcoin.lib; - nbPkgs = config.nix-bitcoin.pkgs; - - inherit (config.services) bitcoind; - - network = bitcoind.makeNetworkName "bitcoin" "regtest"; - configFile = pkgs.writeText "config" '' - network=${network} - ${optionalString (!cfg.useBcliPlugin) "disable-plugin=bcli"} - ${optionalString (cfg.proxy != null) "proxy=${cfg.proxy}"} - always-use-proxy=${boolToString cfg.always-use-proxy} - bind-addr=${cfg.address}:${toString cfg.port} - bitcoin-rpcconnect=${nbLib.address bitcoind.rpc.address} - bitcoin-rpcport=${toString bitcoind.rpc.port} - bitcoin-rpcuser=${bitcoind.rpc.users.public.name} - rpc-file-mode=0660 - log-timestamps=false - ${optionalString (cfg.wallet != null) "wallet=${cfg.wallet}"} - ${ # TODO-EXTERNAL: When updating from a version of clightning before 22.11 - # to version 22.11.1, then the database upgrade needs to be allowed - # explicitly. Remove this when it's unlikely that this module is used - # with a clightning version 22.11.1 package. - optionalString (cfg.package.version == "22.11.1") "database-upgrade=true"} - ${cfg.extraConfig} - ''; - - # If a public clightning onion service is enabled, use the onion port as the public port - publicPort = if (config.nix-bitcoin.onionServices.clightning.enable or false) - && config.nix-bitcoin.onionServices.clightning.public - then - (builtins.elemAt config.services.tor.relay.onionServices.clightning.map 0).port - else - cfg.port; -in { - inherit options; - - config = mkIf cfg.enable { - services.bitcoind = { - enable = true; - # Increase rpc thread count due to reports that lightning implementations fail - # under high bitcoind rpc load - rpc.threads = 16; - }; - - environment.systemPackages = [ cfg.package (hiPrio cfg.cli) ]; - - systemd.tmpfiles.rules = [ - "d '${cfg.dataDir}' 0770 ${cfg.user} ${cfg.group} - -" - ]; - - systemd.services.clightning = { - path = [ bitcoind.package ]; - wantedBy = [ "multi-user.target" ]; - requires = [ "bitcoind.service" ]; - after = [ "bitcoind.service" "nix-bitcoin-secrets.target" ]; - preStart = '' - # Remove an existing socket so that `postStart` can detect when when a new - # socket has been created and clightning is ready to accept RPC connections. - # This will no longer be needed when clightning supports systemd startup notifications. - rm -f ${cfg.networkDir}/lightning-rpc - - umask u=rw,g=r,o= - { - cat ${configFile} - echo "bitcoin-rpcpassword=$(cat ${config.nix-bitcoin.secretsDir}/bitcoin-rpcpassword-public)" - ${optionalString (cfg.getPublicAddressCmd != "") '' - echo "announce-addr=$(${cfg.getPublicAddressCmd}):${toString publicPort}" - ''} - } > '${cfg.dataDir}/config' - ''; - serviceConfig = nbLib.defaultHardening // { - ExecStart = "${cfg.package}/bin/lightningd --lightning-dir=${cfg.dataDir}"; - User = cfg.user; - Restart = "on-failure"; - RestartSec = "10s"; - ReadWritePaths = [ cfg.dataDir ]; - # DB upgrades or recovery after a crash can take a while - TimeoutStartSec = "10m"; - } // nbLib.allowedIPAddresses cfg.tor.enforce; - # Wait until the rpc socket appears - postStart = '' - while [[ ! -e ${cfg.networkDir}/lightning-rpc ]]; do - sleep 0.1 - done - # Needed to enable lightning-cli for users with group 'clightning' - chmod g+x ${cfg.networkDir} - ''; - }; - - users.users.${cfg.user} = { - isSystemUser = true; - group = cfg.group; - extraGroups = [ "bitcoinrpc-public" ]; - }; - users.groups.${cfg.group} = {}; - nix-bitcoin.operator.groups = [ cfg.group ]; - }; -} diff --git a/modules/deployment/krops.nix b/modules/deployment/krops.nix deleted file mode 100644 index a31a01b..0000000 --- a/modules/deployment/krops.nix +++ /dev/null @@ -1,24 +0,0 @@ -{ lib, ... }: -{ - nix-bitcoin = { - secretsDir = "/var/src/secrets"; - setupSecrets = true; - }; - environment.variables.NIX_PATH = lib.mkForce "/var/src"; - - # The file syncing step in krops resets the secrets file permissions. - # So force `setup-secrets.service` to restart on deployment. - # Stop it at activation start so that it gets restarted at the end. - system.activationScripts.nixBitcoinStopSetupSecrets = '' - ${/* Skip this step if systemd is not running, i.e. when booting or in nixos-install */ ""} - if [[ -e /run/systemd/system ]]; then - if ! output=$(/run/current-system/systemd/bin/systemctl stop setup-secrets.service --no-block 2>&1); then - # Ignore if the unit is not loaded, which can happen on the first deployment - if [[ $output != *setup-secrets.service\ not\ loaded* ]]; then - echo "$output" - false - fi - fi - fi - ''; -} diff --git a/modules/deployment/nixops.nix b/modules/deployment/nixops.nix deleted file mode 100644 index 980d91c..0000000 --- a/modules/deployment/nixops.nix +++ /dev/null @@ -1,27 +0,0 @@ -{ config, ... }: -{ - nix-bitcoin.secretsSetupMethod = "nixops"; - - deployment.keys = builtins.mapAttrs (n: v: { - keyFile = "${config.nix-bitcoin.deployment.secretsDir}/${n}"; - destDir = config.nix-bitcoin.secretsDir; - inherit (v) user group permissions; - }) config.nix-bitcoin.secrets; - - # nixops makes the secrets directory accessible only for users with group 'key'. - # For compatibility with other deployment methods besides nixops, we forego the - # use of the 'key' group and make the secrets dir world-readable instead. - # This is safe because all containing files have their specific private - # permissions set. - systemd.services.allowSecretsDirAccess = { - requires = [ "keys.target" ]; - after = [ "keys.target" ]; - script = "chmod o+x ${config.nix-bitcoin.secretsDir}"; - serviceConfig.Type = "oneshot"; - }; - - systemd.targets.nix-bitcoin-secrets = { - requires = [ "allowSecretsDirAccess.service" ]; - after = [ "allowSecretsDirAccess.service" ]; - }; -} diff --git a/modules/fulcrum.nix b/modules/fulcrum.nix deleted file mode 100644 index 4ed4fe8..0000000 --- a/modules/fulcrum.nix +++ /dev/null @@ -1,140 +0,0 @@ -{ config, lib, pkgs, ... }: - -with lib; -let - options.services.fulcrum = { - enable = mkOption { - type = types.bool; - default = false; - description = '' - Enable fulcrum, an Electrum server implemented in C++. - - Compared to electrs, fulcrum has a 3x larger database size but - can serve arbitrary address queries instantly. - - fulcrum also enables `txindex` in bitcoind (this is a requirement), - which increases the bitcoind datadir size by 8% of the `blocks` size. - - This module disables peering (a distributed list of electrum servers that can - be queried by clients), but you can manually enable it via option - {option}`extraConfig`. - ''; - }; - address = mkOption { - type = types.str; - default = "127.0.0.1"; - description = "Address to listen for RPC connections."; - }; - port = mkOption { - type = types.port; - default = 50001; - description = "Port to listen for RPC connections."; - }; - dataDir = mkOption { - type = types.path; - default = "/var/lib/fulcrum"; - description = "The data directory for fulcrum."; - }; - extraConfig = mkOption { - type = types.lines; - default = ""; - example = '' - peering = true - ''; - description = '' - Extra lines appended to the configuration file. - - See all available options at - https://github.com/cculianu/Fulcrum/blob/master/doc/fulcrum-example-config.conf - ''; - }; - user = mkOption { - type = types.str; - default = "fulcrum"; - description = "The user as which to run fulcrum."; - }; - group = mkOption { - type = types.str; - default = cfg.user; - description = "The group as which to run fulcrum."; - }; - tor.enforce = nbLib.tor.enforce; - }; - - cfg = config.services.fulcrum; - nbLib = config.nix-bitcoin.lib; - secretsDir = config.nix-bitcoin.secretsDir; - bitcoind = config.services.bitcoind; - - configFile = builtins.toFile "fulcrum.conf" '' - datadir = ${cfg.dataDir} - tcp = ${cfg.address}:${toString cfg.port} - - bitcoind = ${nbLib.addressWithPort bitcoind.rpc.address bitcoind.rpc.port} - rpcuser = ${bitcoind.rpc.users.public.name} - - # Disable logging timestamps - ts-format = none - - peering = false - - ${cfg.extraConfig} - ''; -in { - inherit options; - - config = mkIf cfg.enable { - assertions = [ - { assertion = bitcoind.prune == 0; - message = "Fulcrum does not support bitcoind pruning."; - } - { assertion = - !(config.services ? electrs) - || !config.services.electrs.enable - || config.services.electrs.port != cfg.port; - message = '' - Fulcrum and Electrs can't both bind to TCP RPC port ${cfg.port}. - Change `services.electrs.port` or `services.fulcrum.port` - to a port other than ${cfg.port}. - ''; - } - ]; - - services.bitcoind = { - enable = true; - txindex = true; - }; - - systemd.tmpfiles.rules = [ - "d '${cfg.dataDir}' 0770 ${cfg.user} ${cfg.group} - -" - ]; - - systemd.services.fulcrum = { - wantedBy = [ "multi-user.target" ]; - wants = [ "bitcoind.service" ]; - after = [ "bitcoind.service" "nix-bitcoin-secrets.target" ]; - preStart = '' - { - cat ${configFile} - echo "rpcpassword = $(cat ${secretsDir}/bitcoin-rpcpassword-public)" - } > '${cfg.dataDir}/fulcrum.conf' - ''; - serviceConfig = nbLib.defaultHardening // { - ExecStart = "${config.nix-bitcoin.pkgs.fulcrum}/bin/Fulcrum '${cfg.dataDir}/fulcrum.conf'"; - User = cfg.user; - Group = cfg.group; - Restart = "on-failure"; - RestartSec = "10s"; - ReadWritePaths = cfg.dataDir; - ProcSubset = "all"; # Fulcrum requires read access to /proc/meminfo - } // nbLib.allowedIPAddresses cfg.tor.enforce; - }; - - users.users.${cfg.user} = { - isSystemUser = true; - group = cfg.group; - extraGroups = [ "bitcoinrpc-public" ]; - }; - users.groups.${cfg.group} = {}; - }; -} diff --git a/modules/hardware-wallets.nix b/modules/hardware-wallets.nix deleted file mode 100644 index 905f126..0000000 --- a/modules/hardware-wallets.nix +++ /dev/null @@ -1,84 +0,0 @@ -{ config, lib, pkgs, ... }: - -with lib; -let - options.services.hardware-wallets = { - ledger = mkOption { - type = types.bool; - default = false; - description = '' - If enabled, the ledger udev rules will be installed. - ''; - }; - trezor = mkOption { - type = types.bool; - default = false; - description = '' - If enabled, the trezor udev rules will be installed. - ''; - }; - group = mkOption { - type = types.str; - default = "hardware-wallets"; - description = '' - Group the hardware wallet udev rules apply to. - ''; - }; - }; - - cfg = config.services.hardware-wallets; -in { - inherit options; - - config = mkMerge [ - (mkIf (cfg.ledger || cfg.trezor) { - assertions = [ - { assertion = (config.services.bitcoind.disablewallet == null || !config.services.bitcoind.disablewallet); - message = '' - Hardware-Wallets are not compatible with bitcoind.disablewallet. - ''; - } - ]; - - environment.systemPackages = [ - config.nix-bitcoin.pkgs.hwi - # Provides lsusb for debugging - pkgs.usbutils - ]; - - users.groups.${cfg.group} = {}; - nix-bitcoin.operator.groups = [ cfg.group ]; - }) - - (mkIf cfg.ledger { - # Ledger Nano S according to https://github.com/LedgerHQ/udev-rules/blob/master/add_udev_rules.sh - # Don't use rules from nixpkgs because we want to use our own group. - services.udev.packages = lib.singleton (pkgs.writeTextFile { - name = "ledger-udev-rules"; - destination = "/etc/udev/rules.d/20-ledger.rules"; - text = '' - SUBSYSTEMS=="usb", ATTRS{idVendor}=="2c97", ATTRS{idProduct}=="0001", MODE="0660", GROUP="${cfg.group}" - ''; - }); - }) - (mkIf cfg.trezor { - environment.systemPackages = [ config.nix-bitcoin.pkgs.pyPkgs.nbPython3PackagesWithUnlockedEcdsa.trezor ]; - # Don't use rules from nixpkgs because we want to use our own group. - services.udev.packages = lib.singleton (pkgs.writeTextFile { - name = "trezord-udev-rules"; - destination = "/etc/udev/rules.d/52-trezor.rules"; - text = '' - # TREZOR v1 (One) - SUBSYSTEM=="usb", ATTR{idVendor}=="534c", ATTR{idProduct}=="0001", MODE="0660", GROUP="${cfg.group}", TAG+="uaccess", SYMLINK+="trezor%n" - KERNEL=="hidraw*", ATTRS{idVendor}=="534c", ATTRS{idProduct}=="0001", MODE="0660", GROUP="${cfg.group}", TAG+="uaccess" - - # TREZOR v2 (T) - SUBSYSTEM=="usb", ATTR{idVendor}=="1209", ATTR{idProduct}=="53c0", MODE="0660", GROUP="${cfg.group}", TAG+="uaccess", SYMLINK+="trezor%n" - SUBSYSTEM=="usb", ATTR{idVendor}=="1209", ATTR{idProduct}=="53c1", MODE="0660", GROUP="${cfg.group}", TAG+="uaccess", SYMLINK+="trezor%n" - KERNEL=="hidraw*", ATTRS{idVendor}=="1209", ATTRS{idProduct}=="53c1", MODE="0660", GROUP="${cfg.group}", TAG+="uaccess" - ''; - }); - services.trezord.enable = true; - }) - ]; -} diff --git a/modules/joinmarket-ob-watcher.nix b/modules/joinmarket-ob-watcher.nix deleted file mode 100644 index 537b0b3..0000000 --- a/modules/joinmarket-ob-watcher.nix +++ /dev/null @@ -1,133 +0,0 @@ -{ config, lib, pkgs, ... }: - -with lib; -let - options.services.joinmarket-ob-watcher = { - enable = mkEnableOption "JoinMarket orderbook watcher"; - address = mkOption { - type = types.str; - default = "127.0.0.1"; - description = "HTTP server address."; - }; - port = mkOption { - type = types.port; - default = 62601; - description = "HTTP server port."; - }; - dataDir = mkOption { - readOnly = true; - default = "/var/lib/joinmarket-ob-watcher"; - description = "The data directory for JoinMarket orderbook watcher."; - }; - settings = mkOption { - type = with types; attrsOf anything; - example = { - LOGGING = { - console_log_level = "DEBUG"; - }; - }; - description = '' - Joinmarket settings. - See here for possible options: - https://github.com/JoinMarket-Org/joinmarket-clientserver/blob/v0.9.11/src/jmclient/configure.py#L98 - ''; - }; - user = mkOption { - type = types.str; - default = "joinmarket-ob-watcher"; - description = "The user as which to run JoinMarket."; - }; - group = mkOption { - type = types.str; - default = cfg.user; - description = "The group as which to run JoinMarket."; - }; - # This option is only used by netns-isolation. - # Tor is always enabled. - tor.enforce = nbLib.tor.enforce; - }; - - cfg = config.services.joinmarket-ob-watcher; - nbLib = config.nix-bitcoin.lib; - nbPkgs = config.nix-bitcoin.pkgs; - secretsDir = config.nix-bitcoin.secretsDir; - - inherit (config.services) bitcoind joinmarket; -in { - inherit options; - - config = mkIf cfg.enable { - services.bitcoind.rpc.users.joinmarket-ob-watcher = { - passwordHMACFromFile = true; - rpcwhitelist = bitcoind.rpc.users.public.rpcwhitelist ++ [ - "listwallets" - ]; - }; - - # Joinmarket is Tor-only - services.tor = { - enable = true; - client.enable = true; - }; - - systemd.tmpfiles.rules = [ - "d '${cfg.dataDir}' 0770 ${cfg.user} ${cfg.group} - -" - ]; - - services.joinmarket-ob-watcher.settings = { - BLOCKCHAIN = config.services.joinmarket.settings.BLOCKCHAIN // { - rpc_user = bitcoind.rpc.users.joinmarket-ob-watcher.name; - rpc_wallet_file = ""; - }; - inherit (config.services.joinmarket.settings) - "MESSAGING:onion" - "MESSAGING:server1" - "MESSAGING:server2" - "MESSAGING:server3"; - }; - - systemd.services.joinmarket-ob-watcher = rec { - wantedBy = [ "multi-user.target" ]; - requires = [ "tor.service" "bitcoind.service" ]; - after = requires ++ [ "nix-bitcoin-secrets.target" ]; - # The service writes to HOME/.config/matplotlib - environment.HOME = cfg.dataDir; - preStart = '' - { - cat ${builtins.toFile "joinmarket-ob-watcher.cfg" ((generators.toINI {}) cfg.settings)} - echo - echo '[BLOCKCHAIN]' - echo "rpc_password = $(cat ${secretsDir}/bitcoin-rpcpassword-joinmarket-ob-watcher)" - } > '${cfg.dataDir}/joinmarket.cfg' - ''; - serviceConfig = nbLib.defaultHardening // rec { - StateDirectory = "joinmarket-ob-watcher"; - StateDirectoryMode = "770"; - WorkingDirectory = cfg.dataDir; # The service creates dir 'logs' in the working dir - User = cfg.user; - ExecStart = '' - ${nbPkgs.joinmarket}/bin/jm-ob-watcher --datadir=${cfg.dataDir} \ - --host=${cfg.address} --port=${toString cfg.port} - ''; - SystemCallFilter = nbLib.defaultHardening.SystemCallFilter ++ [ "mbind" ] ; - Restart = "on-failure"; - RestartSec = "10s"; - } // nbLib.allowedIPAddresses cfg.tor.enforce; - }; - - users.users.${cfg.user} = { - isSystemUser = true; - group = cfg.group; - home = cfg.dataDir; - }; - users.groups.${cfg.group} = {}; - - nix-bitcoin.secrets = { - bitcoin-rpcpassword-joinmarket-ob-watcher.user = cfg.user; - bitcoin-HMAC-joinmarket-ob-watcher.user = bitcoind.user; - }; - nix-bitcoin.generateSecretsCmds.joinmarket-ob-watcher = '' - makeBitcoinRPCPassword joinmarket-ob-watcher - ''; - }; -} diff --git a/modules/joinmarket.nix b/modules/joinmarket.nix deleted file mode 100644 index 1ea6684..0000000 --- a/modules/joinmarket.nix +++ /dev/null @@ -1,398 +0,0 @@ -{ config, lib, pkgs, ... }: - -with lib; -let - options.services.joinmarket = { - enable = mkEnableOption "JoinMarket, a Bitcoin CoinJoin implementation"; - payjoinAddress = mkOption { - type = types.str; - default = "127.0.0.1"; - description = '' - The address where payjoin onion connections are forwarded to. - This address is never used directly, it only serves as the internal endpoint - for the payjoin onion service. - The onion service is automatically setup by joinmarket and accepts - connections at port 80. - ''; - }; - payjoinPort = mkOption { - type = types.port; - default = 64180; # A random private port - description = "The port corresponding to option {option}`payjoinAddress`."; - }; - messagingAddress = mkOption { - type = types.str; - default = "127.0.0.1"; - description = '' - The address where messaging onion connections are forwarded to. - This address is never used directly, it only serves as the internal endpoint - for the messaging onion service. - The onion service is automatically setup by joinmarket. - ''; - }; - messagingPort = mkOption { - type = types.port; - default = 64181; # payjoinPort + 1 - description = "The port corresponding to option {option}`messagingAddress`."; - }; - dataDir = mkOption { - type = types.path; - default = "/var/lib/joinmarket"; - description = "The data directory for JoinMarket."; - }; - rpcWalletFile = mkOption { - type = types.nullOr types.nonEmptyStr; - default = "jm_wallet"; - description = '' - Name of the watch-only bitcoind wallet the JoinMarket addresses are imported to. - ''; - }; - settings = mkOption { - type = with types; attrsOf anything; - example = { - POLICY = { - merge_algorithm = "gradual"; - tx_fees = 5; - }; - LOGGING = { - console_log_level = "DEBUG"; - }; - }; - description = '' - Joinmarket settings. - See here for possible options: - https://raw.githubusercontent.com/JoinMarket-Org/joinmarket-clientserver/master/src/jmclient/configure.py#:~:text=defaultconfig%20= - If your web browser does not support text fragment URLs, you can can manually - search for string `defaultconfig =` to jump to the correct location. - ''; - }; - user = mkOption { - type = types.str; - default = "joinmarket"; - description = "The user as which to run JoinMarket."; - }; - group = mkOption { - type = types.str; - default = cfg.user; - description = "The group as which to run JoinMarket."; - }; - cli = mkOption { - default = cli; - defaultText = "(See source)"; - }; - # This option is only used by netns-isolation. - # Tor is always enabled. - tor.enforce = nbLib.tor.enforce; - inherit (nbLib) cliExec; - - yieldgenerator = { - enable = mkOption { - type = types.bool; - default = false; - description = '' - Enable the JoinMarket yield generator bot. - Documentation: https://github.com/JoinMarket-Org/joinmarket-clientserver/blob/master/docs/YIELDGENERATOR.md - ''; - }; - ordertype = mkOption { - type = types.enum [ "reloffer" "absoffer" ]; - default = "reloffer"; - description = '' - Which fee type to actually use. - ''; - }; - cjfee_a = mkOption { - type = types.ints.unsigned; - default = 500; - description = '' - Absolute offer fee you wish to receive for coinjoins (cj) in Satoshis. - ''; - }; - cjfee_r = mkOption { - type = types.float; - default = 0.00002; - description = '' - Relative offer fee you wish to receive based on a cj's amount. - ''; - }; - cjfee_factor = mkOption { - type = types.float; - default = 0.1; - description = '' - Variance around the average cj fee. - ''; - }; - txfee_contribution_factor = mkOption { - type = types.float; - default = 0.3; - description = '' - Variance around the average tx fee. - ''; - }; - minsize = mkOption { - type = types.ints.unsigned; - default = 100000; - description = '' - Minimum size of your cj offer in Satoshis. Lower cj amounts will be disregarded. - ''; - }; - size_factor = mkOption { - type = types.float; - default = 0.1; - description = '' - Variance around all offer sizes. - ''; - }; - }; - }; - - cfg = config.services.joinmarket; - nbLib = config.nix-bitcoin.lib; - nbPkgs = config.nix-bitcoin.pkgs; - secretsDir = config.nix-bitcoin.secretsDir; - runAsUser = config.nix-bitcoin.runAsUserCmd; - - inherit (config.services) bitcoind; - - torAddress = config.services.tor.client.socksListenAddress; - - socks5Settings = { - socks5 = true; - socks5_host = torAddress.addr; - socks5_port = torAddress.port; - }; - - # The jm scripts create a 'logs' dir in the working dir, - # so run them inside dataDir. - cli = pkgs.runCommand "joinmarket-cli" {} '' - mkdir -p "$out/bin" - jm=${nbPkgs.joinmarket}/bin - cd "$jm" - for bin in jm-*; do - { - echo "#!${pkgs.bash}/bin/bash"; - echo "cd '${cfg.dataDir}' && ${cfg.cliExec} ${runAsUser} ${cfg.user} "$jm/$bin" --datadir='${cfg.dataDir}' \"\$@\""; - } > "$out/bin/$bin" - done - chmod -R +x "$out/bin" - ''; -in { - inherit options; - - config = mkMerge [ - { - services.joinmarket.settings = { - DAEMON = { - no_daemon = 0; - daemon_port = 27183; - daemon_host = "127.0.0.1"; - }; - BLOCKCHAIN = { - blockchain_source = bitcoind.makeNetworkName "bitcoin-rpc" "regtest"; - network = bitcoind.makeNetworkName "mainnet" "testnet"; - rpc_host = nbLib.address bitcoind.rpc.address; - rpc_port = bitcoind.rpc.port; - rpc_user = bitcoind.rpc.users.privileged.name; - rpc_wallet_file = if cfg.rpcWalletFile == null then "" else cfg.rpcWalletFile; - }; - LOGGING = { - color = false; - }; - PAYJOIN = { - onion_socks5_host = torAddress.addr; - onion_socks5_port = torAddress.port; - tor_control_host = "unix:/run/tor/control"; - onion_serving_host = cfg.payjoinAddress; - onion_serving_port = cfg.payjoinPort; - hidden_service_ssl = false; - }; - YIELDGENERATOR = removeAttrs cfg.yieldgenerator [ - "enable" - # TODO: This is only needed when ./obsolete-options.nix is imported - "txfee" - ]; - - # Messaging settings have to be fully specified because joinmarket doesn't - # provide default messaging settings. - # (`jmclient/configure.py` actually does contain default messaging settings, but - # they are removed via fn `_remove_unwanted_default_settings`) - "MESSAGING:onion" = socks5Settings // { - type = "onion"; - tor_control_host = "unix:/run/tor/control"; - # Required option, but ignored because `tor_control_host` is a unix socket - tor_control_port = 9051; - onion_serving_host = cfg.messagingAddress; - onion_serving_port = cfg.messagingPort; - hidden_service_dir = ""; - directory_nodes = "g3hv4uynnmynqqq2mchf3fcm3yd46kfzmcdogejuckgwknwyq5ya6iad.onion:5222,3kxw6lf5vf6y26emzwgibzhrzhmhqiw6ekrek3nqfjjmhwznb2moonad.onion:5222,bqlpq6ak24mwvuixixitift4yu42nxchlilrcqwk2ugn45tdclg42qid.onion:5222"; - }; - # irc.darkscience.net - "MESSAGING:server1" = socks5Settings // { - host = "darkirc6tqgpnwd3blln3yfv5ckl47eg7llfxkmtovrv7c7iwohhb6ad.onion"; - channel = "joinmarket-pit"; - port = 6697; - usessl = true; - }; - # ilita - "MESSAGING:server2" = socks5Settings // { - host = "ilitafrzzgxymv6umx2ux7kbz3imyeko6cnqkvy4nisjjj4qpqkrptid.onion"; - channel = "joinmarket-pit"; - port = 6667; - usessl = false; - }; - # irc.hackint.org - "MESSAGING:server3" = socks5Settings // { - host = "ncwkrwxpq2ikcngxq3dy2xctuheniggtqeibvgofixpzvrwpa77tozqd.onion"; - channel = "joinmarket-pit"; - port = 6667; - usessl = false; - }; - }; - } - - (mkIf cfg.enable { - assertions = [ - { - assertion = lib.versionOlder bitcoind.package.version "30"; - message = '' - Joinmarket is not compatible with bitcoind >= 30. - (https://github.com/JoinMarket-Org/joinmarket-clientserver/pull/1775) - - To fix this, add the following to your config: - services.bitcoind.package = config.nix-bitcoin.pkgs.bitcoind_29; - ''; - } - ]; - - services.bitcoind = { - enable = true; - disablewallet = false; - # TODO-EXTERNAL: remove when joinmarket supports descriptor wallets - # (https://github.com/JoinMarket-Org/joinmarket-clientserver/issues/1571). - extraConfig = '' - deprecatedrpc=create_bdb - ''; - }; - - # Joinmarket is Tor-only - services.tor = { - enable = true; - client.enable = true; - # Needed for payjoin onion service creation - controlSocket.enable = true; - }; - - environment.systemPackages = [ - (hiPrio cfg.cli) - ]; - - systemd.tmpfiles.rules = [ - "d '${cfg.dataDir}' 0770 ${cfg.user} ${cfg.group} - -" - ]; - - systemd.services.joinmarket = { - wantedBy = [ "multi-user.target" ]; - requires = [ "bitcoind.service" ]; - after = [ "bitcoind.service" "nix-bitcoin-secrets.target" ]; - preStart = '' - { - cat ${builtins.toFile "joinmarket.cfg" ((generators.toINI {}) cfg.settings)} - echo - echo '[BLOCKCHAIN]' - echo "rpc_password = $(cat ${secretsDir}/bitcoin-rpcpassword-privileged)" - } > '${cfg.dataDir}/joinmarket.cfg' - ''; - postStart = '' - walletname=wallet.jmdat - wallet="${cfg.dataDir}/wallets/$walletname" - if [[ ! -f $wallet ]]; then - ${optionalString (cfg.rpcWalletFile != null) '' - echo "Create watch-only wallet ${cfg.rpcWalletFile}" - if ! output=$(${bitcoind.cli}/bin/bitcoin-cli -named createwallet \ - wallet_name="${cfg.rpcWalletFile}" \ - descriptors=false \ - ${optionalString (!bitcoind.regtest) "disable_private_keys=true"} 2>&1 - ); then - # Ignore error if bitcoind wallet already exists - if [[ $output != *"already exists"* ]]; then - echo "$output" - exit 1 - fi - fi - ''} - - # Restore wallet from seed if available - seed=() - if [[ -e jm-wallet-seed ]]; then - seed=(--recovery-seed-file jm-wallet-seed) - fi - cd "${cfg.dataDir}" - - # Strip trailing newline from password file - if ! tr -d '\n' < '${secretsDir}/jm-wallet-password' \ - | ${nbPkgs.joinmarket}/bin/jm-genwallet \ - --datadir="${cfg.dataDir}" --wallet-password-stdin "''${seed[@]}" "$walletname" \ - | (if ((! ''${#seed[@]})); then - umask u=r,go= - grep -ohP '(?<=recovery_seed:).*' > jm-wallet-seed - else - cat > /dev/null - fi); then - echo "wallet creation failed" - rm -f "$wallet" jm-wallet-seed - exit 1 - fi - fi - ''; - serviceConfig = nbLib.defaultHardening // { - ExecStart = "${nbPkgs.joinmarket}/bin/joinmarketd"; - WorkingDirectory = cfg.dataDir; # The service creates 'commitmentlist' in the working dir - User = cfg.user; - Restart = "on-failure"; - RestartSec = "10s"; - ReadWritePaths = [ cfg.dataDir ]; - } // nbLib.allowedIPAddresses cfg.tor.enforce; - }; - - users.users.${cfg.user} = { - isSystemUser = true; - group = cfg.group; - home = cfg.dataDir; - # Allow access to the tor control socket, needed for payjoin onion service creation - extraGroups = [ "tor" "bitcoin" ]; - }; - users.groups.${cfg.group} = {}; - nix-bitcoin.operator = { - groups = [ cfg.group ]; - allowRunAsUsers = [ cfg.user ]; - }; - - nix-bitcoin.secrets.jm-wallet-password.user = cfg.user; - nix-bitcoin.generateSecretsCmds.joinmarket = '' - makePasswordSecret jm-wallet-password - ''; - }) - - (mkIf (cfg.enable && cfg.yieldgenerator.enable) { - systemd.services.joinmarket-yieldgenerator = { - wantedBy = [ "joinmarket.service" ]; - requires = [ "joinmarket.service" ]; - after = [ "joinmarket.service" "nix-bitcoin-secrets.target" ]; - script = '' - tr -d "\n" <"${secretsDir}/jm-wallet-password" \ - | ${nbPkgs.joinmarket}/bin/jm-yg-privacyenhanced --datadir='${cfg.dataDir}' \ - --wallet-password-stdin wallet.jmdat - ''; - serviceConfig = nbLib.defaultHardening // rec { - WorkingDirectory = cfg.dataDir; # The service creates dir 'logs' in the working dir - # Show "joinmarket-yieldgenerator" instead of "bash" in the journal. - # The start script has to run alongside the main process - # because it provides the wallet password via stdin to the main process - SyslogIdentifier = "joinmarket-yieldgenerator"; - User = cfg.user; - ReadWritePaths = [ cfg.dataDir ]; - } // nbLib.allowTor; - }; - }) - ]; -} diff --git a/modules/lightning-loop.nix b/modules/lightning-loop.nix deleted file mode 100644 index e84d7b9..0000000 --- a/modules/lightning-loop.nix +++ /dev/null @@ -1,147 +0,0 @@ -{ config, lib, pkgs, ... }: - -with lib; -let - options.services.lightning-loop = { - enable = mkEnableOption "Lightning Loop, a non-custodial off/on chain bridge"; - rpcAddress = mkOption { - type = types.str; - default = "127.0.0.1"; - description = "Address to listen for gRPC connections."; - }; - rpcPort = mkOption { - type = types.port; - default = 11010; - description = "Port to listen for gRPC connections."; - }; - restAddress = mkOption { - type = types.str; - default = cfg.rpcAddress; - description = "Address to listen for REST connections."; - }; - restPort = mkOption { - type = types.port; - default = 8081; - description = "Port to listen for REST connections."; - }; - package = mkOption { - type = types.package; - default = config.nix-bitcoin.pkgs.lightning-loop; - defaultText = "config.nix-bitcoin.pkgs.lightning-loop"; - description = "The package providing lightning-loop binaries."; - }; - dataDir = mkOption { - type = types.path; - default = "/var/lib/lightning-loop"; - description = "The data directory for lightning-loop."; - }; - proxy = mkOption { - type = types.nullOr types.str; - default = if cfg.tor.proxy then config.nix-bitcoin.torClientAddressWithPort else null; - description = "`host:port` of SOCKS5 proxy for connnecting to the loop server."; - }; - certificate = { - extraIPs = mkOption { - type = with types; listOf str; - default = []; - example = [ "60.100.0.1" ]; - description = '' - Extra `subjectAltName` IPs added to the certificate. - This works the same as loop option {option}`tlsextraip`. - ''; - }; - extraDomains = mkOption { - type = with types; listOf str; - default = []; - example = [ "example.com" ]; - description = '' - Extra `subjectAltName` domain names added to the certificate. - This works the same as loop option {option}`tlsextradomain`. - ''; - }; - }; - extraConfig = mkOption { - type = types.lines; - default = ""; - example = '' - debuglevel=trace - ''; - description = '' - Extra lines appended to the configuration file. - See here for all available options: - https://github.com/lightninglabs/loop/blob/11ab596080e9d36f1df43edbeba0702b25aa7457/loopd/config.go#L119 - ''; - }; - cli = mkOption { - default = pkgs.writers.writeBashBin "loop" '' - ${cfg.package}/bin/loop \ - --rpcserver ${nbLib.addressWithPort cfg.rpcAddress cfg.rpcPort} \ - --macaroonpath '${cfg.dataDir}/${network}/loop.macaroon' \ - --tlscertpath '${secretsDir}/loop-cert' "$@" - ''; - defaultText = "(See source)"; - description = "Binary to connect with the lightning-loop instance."; - }; - tor = nbLib.tor; - }; - - cfg = config.services.lightning-loop; - nbLib = config.nix-bitcoin.lib; - secretsDir = config.nix-bitcoin.secretsDir; - - lnd = config.services.lnd; - - network = config.services.bitcoind.network; - configFile = builtins.toFile "loop.conf" '' - datadir=${cfg.dataDir} - network=${network} - rpclisten=${cfg.rpcAddress}:${toString cfg.rpcPort} - restlisten=${cfg.restAddress}:${toString cfg.restPort} - logdir=${cfg.dataDir}/logs - tlscertpath=${secretsDir}/loop-cert - tlskeypath=${secretsDir}/loop-key - - lnd.host=${nbLib.addressWithPort lnd.rpcAddress lnd.rpcPort} - lnd.macaroonpath=${lnd.networkDir}/admin.macaroon - lnd.tlspath=${lnd.certPath} - - ${optionalString (cfg.proxy != null) "server.proxy=${cfg.proxy}"} - - ${cfg.extraConfig} - ''; -in { - inherit options; - - config = mkIf cfg.enable { - services.lnd.enable = true; - - environment.systemPackages = [ cfg.package (hiPrio cfg.cli) ]; - - systemd.tmpfiles.rules = [ - "d '${cfg.dataDir}' 0770 ${lnd.user} ${lnd.group} - -" - ]; - - services.lightning-loop.certificate.extraIPs = mkIf (cfg.rpcAddress != "127.0.0.1") [ "${cfg.rpcAddress}" ]; - - systemd.services.lightning-loop = { - wantedBy = [ "multi-user.target" ]; - requires = [ "lnd.service" ]; - after = [ "lnd.service" "nix-bitcoin-secrets.target" ]; - serviceConfig = nbLib.defaultHardening // { - ExecStart = "${cfg.package}/bin/loopd --configfile=${configFile}"; - User = lnd.user; - Restart = "on-failure"; - RestartSec = "10s"; - ReadWritePaths = [ cfg.dataDir ]; - } // nbLib.allowedIPAddresses cfg.tor.enforce; - }; - - nix-bitcoin.secrets = { - loop-key.user = lnd.user; - loop-cert.user = lnd.user; - }; - nix-bitcoin.generateSecretsCmds.lightning-loop = '' - makeCert loop '${nbLib.mkCertExtraAltNames cfg.certificate}' - ''; - }; -} diff --git a/modules/lightning-pool.nix b/modules/lightning-pool.nix deleted file mode 100644 index bf760e6..0000000 --- a/modules/lightning-pool.nix +++ /dev/null @@ -1,113 +0,0 @@ -{ config, lib, pkgs, ... }: - -with lib; -let - options.services.lightning-pool = { - enable = mkEnableOption "Lightning Pool, a marketplace for inbound lightning liquidity "; - rpcAddress = mkOption { - type = types.str; - default = "127.0.0.1"; - description = "Address to listen for gRPC connections."; - }; - rpcPort = mkOption { - type = types.port; - default = 12010; - description = "Port to listen for gRPC connections."; - }; - restAddress = mkOption { - type = types.str; - default = cfg.rpcAddress; - description = "Address to listen for REST connections."; - }; - restPort = mkOption { - type = types.port; - default = 8281; - description = "Port to listen for REST connections."; - }; - package = mkOption { - type = types.package; - default = config.nix-bitcoin.pkgs.lightning-pool; - defaultText = "config.nix-bitcoin.pkgs.lightning-pool"; - description = "The package providing lightning-pool binaries."; - }; - dataDir = mkOption { - type = types.path; - default = "/var/lib/lightning-pool"; - description = "The data directory for lightning-pool."; - }; - proxy = mkOption { - type = types.nullOr types.str; - default = if cfg.tor.proxy then config.nix-bitcoin.torClientAddressWithPort else null; - description = "host:port of SOCKS5 proxy for connnecting to the pool auction server."; - }; - extraConfig = mkOption { - type = types.lines; - default = ""; - example = '' - debuglevel=trace - ''; - description = "Extra lines appended to the configuration file."; - }; - cli = mkOption { - default = pkgs.writers.writeBashBin "pool" '' - exec ${cfg.package}/bin/pool \ - --rpcserver ${nbLib.addressWithPort cfg.rpcAddress cfg.rpcPort} \ - --network ${network} \ - --basedir '${cfg.dataDir}' "$@" - ''; - defaultText = "(See source)"; - description = "Binary to connect with the lightning-pool instance."; - }; - tor = nbLib.tor; - }; - - cfg = config.services.lightning-pool; - nbLib = config.nix-bitcoin.lib; - - lnd = config.services.lnd; - - network = config.services.bitcoind.network; - configFile = builtins.toFile "pool.conf" '' - rpclisten=${cfg.rpcAddress}:${toString cfg.rpcPort} - restlisten=${cfg.restAddress}:${toString cfg.restPort} - ${optionalString (cfg.proxy != null) "proxy=${cfg.proxy}"} - - lnd.host=${lnd.rpcAddress}:${toString lnd.rpcPort} - lnd.macaroondir=${lnd.networkDir} - lnd.tlspath=${lnd.certPath} - - ${cfg.extraConfig} - ''; -in { - inherit options; - - config = mkIf cfg.enable { - services.lnd.enable = true; - - environment.systemPackages = [ cfg.package (hiPrio cfg.cli) ]; - - systemd.tmpfiles.rules = [ - "d '${cfg.dataDir}' 0770 lnd lnd - -" - ]; - - systemd.services.lightning-pool = { - wantedBy = [ "multi-user.target" ]; - requires = [ "lnd.service" ]; - after = [ "lnd.service" ]; - preStart = '' - mkdir -p '${cfg.dataDir}/${network}' - ln -sfn ${configFile} '${cfg.dataDir}/${network}/poold.conf' - ''; - serviceConfig = nbLib.defaultHardening // { - # TODO: temporary sleep to prevent race condition - ExecStartPre = "${pkgs.coreutils}/bin/sleep 5"; - ExecStart = "${cfg.package}/bin/poold --basedir='${cfg.dataDir}' --network=${network}"; - User = "lnd"; - Restart = "on-failure"; - RestartSec = "10s"; - ReadWritePaths = [ cfg.dataDir ]; - } // (nbLib.allowedIPAddresses cfg.tor.enforce) - // nbLib.allowNetlink; # required by gRPC-Go - }; - }; -} diff --git a/modules/liquid.nix b/modules/liquid.nix deleted file mode 100644 index f7716de..0000000 --- a/modules/liquid.nix +++ /dev/null @@ -1,294 +0,0 @@ -{ config, pkgs, lib, ... }: - -with lib; -let - options = { - services.liquidd = { - enable = mkEnableOption "Liquid Bitcoin sidechain daemon"; - address = mkOption { - type = types.str; - default = "127.0.0.1"; - description = "Address to listen for peer connections."; - }; - port = mkOption { - type = types.port; - default = 7042; - description = "Override the default port on which to listen for connections."; - }; - onionPort = mkOption { - type = types.nullOr types.port; - # When the liquidd onion service is enabled, add an onion-tagged socket - # to distinguish local connections from Tor connections - default = if (config.nix-bitcoin.onionServices.liquidd.enable or false) then 7043 else null; - description = '' - Port to listen for Tor peer connections. - If set, inbound connections to this port are tagged as onion peers. - ''; - }; - listen = mkOption { - type = types.bool; - default = false; - description = '' - Listen for peer connections at `address:port` - and `address:onionPort` (if {option}`onionPort` is set). - ''; - }; - listenWhitelisted = mkOption { - type = types.bool; - default = false; - description = '' - Listen for peer connections at `address:whitelistedPort`. - Peers connected through this socket are automatically whitelisted. - ''; - }; - whitelistedPort = mkOption { - type = types.port; - default = 7044; - description = "See {option}`listenWhitelisted`."; - }; - extraConfig = mkOption { - type = types.lines; - default = ""; - example = '' - par=16 - rpcthreads=16 - logips=1 - ''; - description = "Extra lines appended to {file}`elements.conf`."; - }; - dataDir = mkOption { - type = types.path; - default = "/var/lib/liquidd"; - description = "The data directory for liquidd."; - }; - rpc = { - address = mkOption { - type = types.str; - default = "127.0.0.1"; - description = "Address to listen for JSON-RPC connections."; - }; - port = mkOption { - type = types.port; - default = 7041; - description = "Port to listen for JSON-RPC connections."; - }; - users = mkOption { - default = {}; - example = { - alice.passwordHMAC = "f7efda5c189b999524f151318c0c86$d5b51b3beffbc02b724e5d095828e0bc8b2456e9ac8757ae3211a5d9b16a22ae"; - bob.passwordHMAC = "b2dd077cb54591a2f3139e69a897ac$4e71f08d48b4347cf8eff3815c0e25ae2e9a4340474079f55705f40574f4ec99"; - }; - type = with types; attrsOf (submodule rpcUserOpts); - description = '' - RPC user information for JSON-RPC connections. - ''; - }; - }; - rpcallowip = mkOption { - type = types.listOf types.str; - default = [ "127.0.0.1" ]; - description = '' - Allow JSON-RPC connections from specified source. - ''; - }; - rpcuser = mkOption { - type = types.str; - default = "liquidrpc"; - description = "Username for JSON-RPC connections"; - }; - proxy = mkOption { - type = types.nullOr types.str; - default = if cfg.tor.proxy then config.nix-bitcoin.torClientAddressWithPort else null; - description = "Connect through SOCKS5 proxy"; - }; - dbCache = mkOption { - type = types.nullOr (types.ints.between 4 16384); - default = null; - example = 4000; - description = "Override the default database cache size in megabytes."; - }; - prune = mkOption { - type = types.nullOr (types.coercedTo - (types.enum [ "disable" "manual" ]) - (x: if x == "disable" then 0 else 1) - types.ints.unsigned - ); - default = null; - example = 10000; - description = '' - Reduce storage requirements by enabling pruning (deleting) of old - blocks. This allows the pruneblockchain RPC to be called to delete - specific blocks, and enables automatic pruning of old blocks if a - target size in MiB is provided. This mode is incompatible with -txindex - and -rescan. Warning: Reverting this setting requires re-downloading - the entire blockchain. (`disable` = disable pruning blocks, `manual` - = allow manual pruning via RPC, >=550 = automatically prune block files - to stay under the specified target size in MiB) - ''; - }; - validatepegin = mkOption { - type = types.nullOr types.bool; - default = null; - description = '' - Validate pegin claims. All functionaries must run this. - ''; - }; - user = mkOption { - type = types.str; - default = "liquid"; - description = "The user as which to run liquidd."; - }; - group = mkOption { - type = types.str; - default = cfg.user; - description = "The group as which to run liquidd."; - }; - cli = mkOption { - readOnly = true; - default = pkgs.writers.writeBashBin "elements-cli" '' - ${nbPkgs.elementsd}/bin/elements-cli -datadir='${cfg.dataDir}' "$@" - ''; - defaultText = "(See source)"; - description = "Binary to connect with the liquidd instance."; - }; - swapCli = mkOption { - default = pkgs.writers.writeBashBin "liquidswap-cli" '' - ${nbPkgs.liquid-swap}/bin/liquidswap-cli -c '${cfg.dataDir}/elements.conf' "$@" - ''; - defaultText = "(See source)"; - description = "Binary for managing liquid swaps."; - }; - tor = nbLib.tor; - }; - }; - - cfg = config.services.liquidd; - nbLib = config.nix-bitcoin.lib; - nbPkgs = config.nix-bitcoin.pkgs; - secretsDir = config.nix-bitcoin.secretsDir; - - bitcoind = config.services.bitcoind; - - configFile = pkgs.writeText "elements.conf" '' - # We're already logging via journald - nodebuglogfile=1 - - startupnotify=/run/current-system/systemd/bin/systemd-notify --ready - - chain=${bitcoind.makeNetworkName "liquidv1" '' - regtest - [regtest]'' # Add [regtest] config section - } - ${optionalString (cfg.dbCache != null) "dbcache=${toString cfg.dbCache}"} - ${optionalString (cfg.prune != null) "prune=${toString cfg.prune}"} - ${optionalString (cfg.validatepegin != null) "validatepegin=${if cfg.validatepegin then "1" else "0"}"} - - # Connection options - listen=${if (cfg.listen || cfg.listenWhitelisted) then "1" else "0"} - ${optionalString cfg.listen - "bind=${cfg.address}:${toString cfg.port}"} - ${optionalString (cfg.listen && cfg.onionPort != null) - "bind=${cfg.address}:${toString cfg.onionPort}=onion"} - ${optionalString cfg.listenWhitelisted - "whitebind=${cfg.address}:${toString cfg.whitelistedPort}"} - ${optionalString (cfg.proxy != null) "proxy=${cfg.proxy}"} - - # RPC server options - rpcport=${toString cfg.rpc.port} - ${concatMapStringsSep "\n" - (rpcUser: "rpcauth=${rpcUser.name}:${rpcUser.passwordHMAC}") - (attrValues cfg.rpc.users) - } - rpcbind=${cfg.rpc.address} - rpcconnect=${cfg.rpc.address} - ${lib.concatMapStrings (rpcallowip: "rpcallowip=${rpcallowip}\n") cfg.rpcallowip} - rpcuser=${cfg.rpcuser} - mainchainrpchost=${nbLib.address bitcoind.rpc.address} - mainchainrpcport=${toString bitcoind.rpc.port} - mainchainrpcuser=${bitcoind.rpc.users.public.name} - - # Extra config options (from liquidd nixos service) - ${cfg.extraConfig} - ''; - rpcUserOpts = { name, ... }: { - options = { - name = mkOption { - type = types.str; - example = "alice"; - description = '' - Username for JSON-RPC connections. - ''; - }; - passwordHMAC = mkOption { - type = with types; uniq (strMatching "[0-9a-f]+\\$[0-9a-f]{64}"); - example = "f7efda5c189b999524f151318c0c86$d5b51b3beffbc02b724e5d095828e0bc8b2456e9ac8757ae3211a5d9b16a22ae"; - description = '' - Password HMAC-SHA-256 for JSON-RPC connections. Must be a string of the - format `$`. - ''; - }; - }; - config = { - name = mkDefault name; - }; - }; -in { - inherit options; - - config = mkIf cfg.enable { - assertions = [ - { assertion = bitcoind.regtest -> cfg.validatepegin != true; - message = "liquidd: `validatepegin` is incompatible with regtest."; - } - ]; - - services.bitcoind.enable = true; - - environment.systemPackages = [ - nbPkgs.elementsd - (hiPrio cfg.cli) - (hiPrio cfg.swapCli) - ]; - - systemd.tmpfiles.rules = [ - "d '${cfg.dataDir}' 0770 ${cfg.user} ${cfg.group} - -" - ]; - - systemd.services.liquidd = { - wants = [ "bitcoind.service" ]; - after = [ "bitcoind.service" "nix-bitcoin-secrets.target" ]; - wantedBy = [ "multi-user.target" ]; - preStart = '' - install -m 640 ${configFile} '${cfg.dataDir}/elements.conf' - { - echo "rpcpassword=$(cat ${secretsDir}/liquid-rpcpassword)" - echo "mainchainrpcpassword=$(cat ${secretsDir}/bitcoin-rpcpassword-public)" - } >> '${cfg.dataDir}/elements.conf' - ''; - serviceConfig = nbLib.defaultHardening // { - Type = "notify"; - NotifyAccess = "all"; - User = cfg.user; - Group = cfg.group; - TimeoutStartSec = "2h"; - TimeoutStopSec = "2h"; - ExecStart = "${nbPkgs.elementsd}/bin/elementsd -datadir='${cfg.dataDir}'"; - Restart = "on-failure"; - ReadWritePaths = [ cfg.dataDir ]; - } // nbLib.allowedIPAddresses cfg.tor.enforce; - }; - - users.users.${cfg.user} = { - isSystemUser = true; - group = cfg.group; - extraGroups = [ "bitcoinrpc-public" ]; - }; - users.groups.${cfg.group} = {}; - nix-bitcoin.operator.groups = [ cfg.group ]; - - nix-bitcoin.secrets.liquid-rpcpassword.user = cfg.user; - nix-bitcoin.generateSecretsCmds.liquid = '' - makePasswordSecret liquid-rpcpassword - ''; - }; -} diff --git a/modules/lnd.nix b/modules/lnd.nix index 94e26b6..5111823 100644 --- a/modules/lnd.nix +++ b/modules/lnd.nix @@ -191,19 +191,6 @@ in { inherit options; config = mkIf cfg.enable { - assertions = [ - { assertion = - !(config.services ? clightning) - || !config.services.clightning.enable - || config.services.clightning.port != cfg.port; - message = '' - LND and clightning can't both bind to lightning port 9735. Either - disable LND/clightning or change services.clightning.port or - services.lnd.port to a port other than 9735. - ''; - } - ]; - services.bitcoind = { enable = true; diff --git a/modules/lndconnect.nix b/modules/lndconnect.nix deleted file mode 100644 index df5494c..0000000 --- a/modules/lndconnect.nix +++ /dev/null @@ -1,282 +0,0 @@ -{ config, lib, pkgs, ... }: - -with lib; -let - options = { - services.lnd.lndconnect = { - enable = mkOption { - type = types.bool; - default = false; - description = '' - Add a `lndconnect` binary to the system environment which prints - connection info for lnd clients. - See: https://github.com/LN-Zap/lndconnect - - Usage: - ```bash - # Print QR code - lndconnect - - # Print URL - lndconnect --url - ``` - ''; - }; - onion = mkOption { - type = types.bool; - default = false; - description = '' - Create an onion service for the lnd REST server, - which is used by lndconnect. - ''; - }; - }; - - services.clightning.plugins.clnrest.lnconnect = { - enable = mkOption { - type = types.bool; - default = false; - description = '' - Add a `lnconnect-clnrest` binary to the system environment which prints - connection info for clightning clients. - See: https://github.com/LN-Zap/lndconnect - - Usage: - ```bash - # Print QR code - lnconnect-clnrest - - # Print URL - lnconnect-clnrest --url - ``` - ''; - }; - onion = mkOption { - type = types.bool; - default = false; - description = '' - Create an onion service for the clnrest server, - which is used by lnconnect. - ''; - }; - }; - - services.clightning-rest.lndconnect = { - enable = mkOption { - type = types.bool; - default = false; - description = '' - Add a `lndconnect-clightning` binary to the system environment which prints - connection info for clightning clients. - See: https://github.com/LN-Zap/lndconnect - - Usage: - ```bash - # Print QR code - lndconnect-clightning - - # Print URL - lndconnect-clightning --url - ``` - ''; - }; - onion = mkOption { - type = types.bool; - default = false; - description = '' - Create an onion service for the clightning REST server, - which is used by lndconnect. - ''; - }; - }; - - nix-bitcoin.mkLndconnect = mkOption { - readOnly = true; - default = mkLndconnect; - description = '' - A function to create a lndconnect binary. - See the source for further details. - ''; - }; - }; - - nbLib = config.nix-bitcoin.lib; - runAsUser = config.nix-bitcoin.runAsUserCmd; - - inherit (config.services) - lnd - clightning - clightning-rest; - - inherit (clightning.plugins) clnrest; - - mkLndconnect = { - name, - shebang ? "#!${pkgs.stdenv.shell} -e", - isClightning ? false, - isClnrest ? false, - port, - authSecretPath, - enableOnion, - onionService ? null, - certPath ? null - }: - # TODO-EXTERNAL: - # lndconnect requires a --configfile argument, although it's unused - # https://github.com/LN-Zap/lndconnect/issues/25 - lib.hiPrio (pkgs.writeScriptBin name '' - ${shebang} - url=$( - ${getExe config.nix-bitcoin.pkgs.lndconnect} --url \ - ${optionalString enableOnion "--host=$(cat ${config.nix-bitcoin.onionAddresses.dataDir}/${onionService})"} \ - --port=${toString port} \ - ${if enableOnion || certPath == null then "--nocert" else "--tlscertpath='${certPath}'"} \ - --adminmacaroonpath='${authSecretPath}' \ - --configfile=/dev/null "$@" - ) - - ${optionalString isClightning - # - Change URL procotcol to c-lightning-rest - # - Encode macaroon as hex (in uppercase) instead of base 64. - # Because `macaroon` is always the last URL fragment, the - # sed replacement below works correctly. - '' - macaroonHex=$(${getExe pkgs.xxd} -p -u -c 99999 '${authSecretPath}') - url=$( - echo "$url" | ${getExe pkgs.gnused} " - s|^lndconnect|c-lightning-rest| - s|macaroon=.*|macaroon=$macaroonHex| - "; - ) - '' - } - - ${optionalString isClnrest - # Change URL procotcol to clnrest - '' - url=$( - echo "$url" | ${getExe pkgs.gnused} " - s|^lndconnect|clnrest| - s|macaroon=.*|rune=$(cat '${authSecretPath}')| - "; - ) - '' - } - - # If --url is in args - if [[ " $* " =~ " --url " ]]; then - echo "$url" - else - # This UTF-8 encoding yields a smaller, more convenient output format - # compared to the native lndconnect output - echo -n "$url" | ${getExe pkgs.qrencode} -t UTF8 -o - - fi - ''); - - operatorName = config.nix-bitcoin.operator.name; -in { - inherit options; - - config = mkMerge [ - (mkIf (lnd.enable && lnd.lndconnect.enable) - (mkMerge [ - { - environment.systemPackages = [( - mkLndconnect { - name = "lndconnect"; - # Run as lnd user because the macaroon and cert are not group-readable - shebang = "#!/usr/bin/env -S ${runAsUser} ${lnd.user} ${pkgs.bash}/bin/bash"; - enableOnion = lnd.lndconnect.onion; - onionService = "${lnd.user}/lnd-rest"; - port = lnd.restPort; - certPath = lnd.certPath; - authSecretPath = "${lnd.networkDir}/admin.macaroon"; - } - )]; - - services.lnd.restAddress = mkIf (!lnd.lndconnect.onion) "0.0.0.0"; - } - - (mkIf lnd.lndconnect.onion { - services.tor = { - enable = true; - relay.onionServices.lnd-rest = nbLib.mkOnionService { - target.addr = nbLib.address lnd.restAddress; - target.port = lnd.restPort; - port = lnd.restPort; - }; - }; - nix-bitcoin.onionAddresses.access = { - ${lnd.user} = [ "lnd-rest" ]; - ${operatorName} = [ "lnd-rest" ]; - }; - }) - ])) - - (mkIf (clnrest.enable && clnrest.lnconnect.enable) - (mkMerge [ - { - environment.systemPackages = [( - mkLndconnect { - name = "lnconnect-clnrest"; - isClnrest = true; - enableOnion = clnrest.lnconnect.onion; - onionService = "${operatorName}/clnrest"; - port = clnrest.port; - certPath = "${clightning.networkDir}/client.pem"; - authSecretPath = "${clightning.networkDir}/admin-rune"; - } - )]; - - services.clightning.plugins.clnrest.address = mkIf (!clnrest.lnconnect.onion) "0.0.0.0"; - } - - (mkIf clnrest.lnconnect.onion { - services.tor = { - enable = true; - relay.onionServices.clnrest = nbLib.mkOnionService { - target.addr = nbLib.address clnrest.address; - target.port = clnrest.port; - port = clnrest.port; - }; - }; - # This also allows nodeinfo to show the clnrest onion address - nix-bitcoin.onionAddresses.access.${operatorName} = [ "clnrest" ]; - }) - ]) - ) - - (mkIf (clightning-rest.enable && clightning-rest.lndconnect.enable) - (mkMerge [ - { - environment.systemPackages = [( - mkLndconnect { - name = "lndconnect-clightning"; - isClightning = true; - enableOnion = clightning-rest.lndconnect.onion; - onionService = "${operatorName}/clightning-rest"; - port = clightning-rest.port; - certPath = "${clightning-rest.dataDir}/certs/certificate.pem"; - authSecretPath = "${clightning-rest.dataDir}/certs/access.macaroon"; - } - )]; - - # clightning-rest always binds to all interfaces - } - - (mkIf clightning-rest.lndconnect.onion { - services.tor = { - enable = true; - relay.onionServices.clightning-rest = nbLib.mkOnionService { - target.addr = nbLib.address clightning-rest.address; - target.port = clightning-rest.port; - port = clightning-rest.port; - }; - }; - # This also allows nodeinfo to show the clightning-rest onion address - nix-bitcoin.onionAddresses.access.${operatorName} = [ "clightning-rest" ]; - }) - ]) - ) - ]; -} diff --git a/modules/mempool.nix b/modules/mempool.nix index b120380..7e28b9f 100644 --- a/modules/mempool.nix +++ b/modules/mempool.nix @@ -94,19 +94,6 @@ let default = 8999; description = "Mempool backend port."; }; - electrumServer = mkOption { - type = types.enum [ "electrs" "fulcrum" ]; - default = "electrs"; - description = '' - The Electrum server to use for fetching address information. - - Possible options: - - electrs: - Small database size, slow when querying new addresses. - - fulcrum: - Large database size, quickly serves arbitrary address queries. - ''; - }; settings = mkOption { type = with types; attrsOf (attrsOf anything); example = { @@ -170,8 +157,7 @@ let inherit (config.services) bitcoind - electrs - fulcrum; + electrs; torSocket = config.services.tor.client.socksListenAddress; @@ -240,8 +226,7 @@ in { config = mkIf cfg.enable { services.bitcoind.txindex = true; - services.electrs.enable = mkIf (cfg.electrumServer == "electrs" ) true; - services.fulcrum.enable = mkIf (cfg.electrumServer == "fulcrum" ) true; + services.electrs.enable = true; services.mysql = { enable = true; package = pkgs.mariadb; @@ -272,11 +257,9 @@ in { USERNAME = bitcoind.rpc.users.public.name; PASSWORD = "@btcRpcPassword@"; }; - ELECTRUM = let - server = config.services.${cfg.electrumServer}; - in { - HOST = server.address; - PORT = server.port; + ELECTRUM = { + HOST = electrs.address; + PORT = electrs.port; TLS_ENABLED = false; }; DATABASE = { @@ -298,7 +281,7 @@ in { systemd.services.mempool = rec { wantedBy = [ "multi-user.target" ]; requires = [ "mysql.service" ]; - wants = [ "${cfg.electrumServer}.service" ]; + wants = [ "electrs.service" ]; after = requires ++ wants; preStart = '' mkdir -p '${cacheDir}/cache' diff --git a/modules/modules.nix b/modules/modules.nix index 1b3c204..2927816 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -10,33 +10,15 @@ # Main features ./bitcoind.nix - ./clightning.nix - ./clightning-plugins - ./clightning-rest.nix - ./clightning-replication.nix ./lnd.nix - ./lightning-loop.nix - ./lightning-pool.nix - ./charge-lnd.nix - ./lndconnect.nix # Requires onion-addresses.nix - ./rtl.nix ./mempool.nix ./electrs.nix - ./fulcrum.nix - ./liquid.nix - ./btcpayserver.nix - ./joinmarket.nix - ./joinmarket-ob-watcher.nix - ./hardware-wallets.nix # Support features - ./versioning.nix ./security.nix ./onion-addresses.nix ./onion-services.nix - ./netns-isolation.nix ./nodeinfo.nix - ./backups.nix ]; disabledModules = [ "services/networking/bitcoind.nix" ]; diff --git a/modules/netns-isolation.nix b/modules/netns-isolation.nix deleted file mode 100644 index 1f83186..0000000 --- a/modules/netns-isolation.nix +++ /dev/null @@ -1,366 +0,0 @@ -{ config, lib, pkgs, ... }: - -with lib; -let - options.nix-bitcoin.netns-isolation = { - enable = mkEnableOption "netns isolation"; - - addressblock = mkOption { - type = types.ints.u8; - default = 1; - description = '' - The address block N in 169.254.N.0/24, used as the prefix for netns addresses. - ''; - }; - - services = mkOption { - default = {}; - type = types.attrsOf (types.submodule { - options = { - id = mkOption { - # TODO: Assert uniqueness - type = types.ints.between 11 255; - description = '' - id for the netns, used for the IP address host part and - for naming the interfaces. Must be unique. Must be greater than 10. - ''; - }; - connections = mkOption { - type = with types; listOf str; - default = []; - }; - }; - }); - }; - - allowedUser = mkOption { - type = types.str; - description = '' - User that is allowed to execute commands in the service network namespaces. - ''; - default = config.nix-bitcoin.operator.name; - }; - - netns = mkOption { - readOnly = true; - default = netns; - description = "Exposes netns parameters."; - }; - - bridgeIp = mkOption { - readOnly = true; - default = bridgeIp; - description = "IP of the netns bridge interface."; - }; - }; - - cfg = config.nix-bitcoin.netns-isolation; - - netns = builtins.mapAttrs (n: v: { - inherit (v) id; - address = "169.254.${toString cfg.addressblock}.${toString v.id}"; - availableNetns = availableNetns.${n}; - netnsName = "nb-${n}"; - }) enabledServices; - - # Symmetric netns connection matrix - # if clightning.connections = [ "bitcoind" ]; then - # availableNetns.bitcoind = [ "clighting" ]; - # and - # availableNetns.clighting = [ "bitcoind" ]; - # - # TODO-EXTERNAL: - # Although negligible for our purposes, this calculation's runtime - # is in the order of (number of connections * number of services), - # because attrsets and lists are fully copied on each update with '//' or '++'. - # This can only be improved with an update in the nix language. - # - availableNetns = let - # base = { clightning = [ "bitcoind" ]; ... } - base = builtins.mapAttrs (n: v: - builtins.filter isEnabled v.connections - ) enabledServices; - in - foldl (xs: s1: - foldl (xs: s2: - xs // { "${s2}" = xs.${s2} ++ [ s1 ]; } - ) xs cfg.services.${s1}.connections - ) base (builtins.attrNames base); - - enabledServices = filterAttrs (n: v: isEnabled n) cfg.services; - isEnabled = x: config.services.${x}.enable; - - ip = "${pkgs.iproute2}/bin/ip"; - iptables = "${config.networking.firewall.package}/bin/iptables"; - - bridgeIp = "169.254.${toString cfg.addressblock}.10"; - - mkCliExec = service: "exec netns-exec ${netns.${service}.netnsName}"; -in { - inherit options; - - config = mkIf cfg.enable (mkMerge [ - - # Base infrastructure - { - networking.dhcpcd.denyInterfaces = [ "nb-br" "nb-veth*" ]; - services.tor.client.socksListenAddress = { - addr = bridgeIp; - # Default NixOS values. These must be repeated when redefining this option. - port = 9050; - IsolateDestAddr = true; - }; - services.i2pd.proto.sam.address = bridgeIp; - networking.firewall.interfaces.nb-br.allowedTCPPorts = [ - config.services.tor.client.socksListenAddress.port - config.services.i2pd.proto.sam.port - ]; - boot.kernel.sysctl."net.ipv4.ip_forward" = true; - - security.wrappers.netns-exec = { - source = config.nix-bitcoin.pkgs.netns-exec; - capabilities = "cap_sys_admin=ep"; - owner = cfg.allowedUser; - # Don't authorize the group of `owner`. For normal users, this group is - # `users`, which is shared by all normal users. - group = "root"; - permissions = "500"; - }; - - systemd.services = { - # Due to a NixOS bug we can't currently use option `networking.bridges` to - # setup the bridge while `networking.useDHCP` is enabled. - nb-netns-bridge = { - description = "nix-bitcoin netns bridge"; - wantedBy = [ "network-setup.service" ]; - partOf = [ "network-setup.service" ]; - before = [ "network-setup.service" ]; - after = [ "network-pre.target" ]; - serviceConfig = { - Type = "oneshot"; - RemainAfterExit = true; - }; - script = '' - ${ip} link add name nb-br type bridge - ${ip} link set nb-br up - ${ip} addr add ${bridgeIp}/24 brd + dev nb-br - ${iptables} -w -t nat -A POSTROUTING -s 169.254.${toString cfg.addressblock}.0/24 -j MASQUERADE - ''; - preStop = '' - ${iptables} -w -t nat -D POSTROUTING -s 169.254.${toString cfg.addressblock}.0/24 -j MASQUERADE - ${ip} link del nb-br - ''; - }; - - } // - (let - makeNetnsServices = n: v: let - veth = "nb-veth-${toString v.id}"; - peer = "nb-veth-br-${toString v.id}"; - inherit (v) netnsName; - nsenter = "${pkgs.util-linux}/bin/nsenter"; - allowedNetnsAddresses = map (available: netns.${available}.address) v.availableNetns; - allowedAddresses = concatStringsSep "," - ([ "127.0.0.1,${bridgeIp},${v.address}" ] ++ allowedNetnsAddresses); - - setup = '' - ${ip} netns add ${netnsName} - ${ip} link add ${veth} type veth peer name ${peer} - ${ip} link set ${veth} netns ${netnsName} - # The peer link is never used directly, so don't auto-assign an IPv6 address - echo 1 > /proc/sys/net/ipv6/conf/${peer}/disable_ipv6 - ${ip} link set ${peer} up - ${ip} link set ${peer} master nb-br - exec ${nsenter} --net=/run/netns/${netnsName} ${script "in-netns" setupInNetns} - ''; - - setupInNetns = '' - ${ip} link set lo up - ${ip} addr add ${v.address}/24 dev ${veth} - ${ip} link set ${veth} up - ${ip} route add default via ${bridgeIp} - - ${iptables} -w -P INPUT DROP - # allow return traffic to outgoing connections initiated by the service itself - ${iptables} -w -A INPUT -m conntrack --ctstate ESTABLISHED -j ACCEPT - ${iptables} -w -A INPUT -s ${allowedAddresses} -j ACCEPT - '' + optionalString (config.services.${n}.tor.enforce or false) '' - ${iptables} -w -P OUTPUT DROP - ${iptables} -w -A OUTPUT -d ${allowedAddresses} -j ACCEPT - ''; - script = name: src: pkgs.writers.writeDash name '' - set -e - ${src} - ''; - in { - "${n}".serviceConfig.NetworkNamespacePath = "/var/run/netns/${netnsName}"; - - "netns-${n}" = rec { - requires = [ "nb-netns-bridge.service" ]; - after = [ "nb-netns-bridge.service" ]; - requiredBy = [ "${n}.service" ]; - before = requiredBy; - serviceConfig = { - Type = "oneshot"; - RemainAfterExit = true; - ExecStart = script "setup" setup; - }; - # Link deletion is implicit in netns deletion, but it sometimes only happens - # after `netns delete` finishes. Add an extra `link del` to ensure that - # the link is deleted before the service stops, which is needed for service - # restart to succeed. - preStop = '' - ${ip} netns delete ${netnsName} - ${ip} link del ${peer} 2> /dev/null || true - ''; - - }; - }; - in - foldl (services: n: - services // (makeNetnsServices n netns.${n}) - ) {} (builtins.attrNames netns) - ); - } - - # Service-specific config - { - nix-bitcoin.netns-isolation.services = { - bitcoind = { - id = 12; - }; - clightning = { - id = 13; - connections = [ "bitcoind" ]; - }; - lnd = { - id = 14; - connections = [ "bitcoind" ]; - }; - liquidd = { - id = 15; - connections = [ "bitcoind" ]; - }; - electrs = { - id = 16; - connections = [ "bitcoind" ]; - }; - nginx = { - id = 21; - }; - lightning-loop = { - id = 22; - connections = [ "lnd" ]; - }; - nbxplorer = { - id = 23; - connections = [ "bitcoind" ] - ++ optional config.services.btcpayserver.lbtc "liquidd"; - }; - btcpayserver = { - id = 24; - connections = [ "nbxplorer" ] - ++ optional (config.services.btcpayserver.lightningBackend == "lnd") "lnd" - ++ optional config.services.btcpayserver.lbtc "liquidd"; - # communicates with clightning over rpc socket - }; - joinmarket = { - id = 25; - connections = [ "bitcoind" ]; - }; - joinmarket-ob-watcher = { - id = 26; - connections = [ "bitcoind" ]; - }; - lightning-pool = { - id = 27; - connections = [ "lnd" ]; - }; - charge-lnd = { - id = 28; - connections = [ "lnd" "electrs" ]; - }; - rtl = { - id = 29; - connections = let - nodes = config.services.rtl.nodes; - in - optional nodes.lnd.enable "lnd" ++ - optional (nodes.lnd.enable && nodes.lnd.loop) "lightning-loop" ++ - optional nodes.clightning.enable "clightning"; - }; - clightning-rest = { - id = 30; - }; - fulcrum = { - id = 31; - connections = [ "bitcoind" ]; - }; - mempool = { - id = 32; - connections = [ - "bitcoind" - "nginx" - (if (config.services.mempool.electrumServer == "electrs") then "electrs" else "fulcrum") - ]; - }; - }; - - services.bitcoind = { - address = netns.bitcoind.address; - rpc.address = netns.bitcoind.address; - rpc.allowip = [ - bridgeIp # For operator user - netns.bitcoind.address - ] ++ map (n: netns.${n}.address) netns.bitcoind.availableNetns; - }; - - services.clightning.address = netns.clightning.address; - services.clightning.plugins.clnrest.address = netns.clightning.address; - - services.lnd = { - address = netns.lnd.address; - rpcAddress = netns.lnd.address; - restAddress = netns.lnd.address; - }; - - services.liquidd = { - address = netns.liquidd.address; - rpc.address = netns.liquidd.address; - rpcallowip = [ - bridgeIp # For operator user - netns.liquidd.address - ] ++ map (n: netns.${n}.address) netns.liquidd.availableNetns; - }; - - services.electrs.address = netns.electrs.address; - - services.fulcrum.address = netns.fulcrum.address; - - services.lightning-loop.rpcAddress = netns.lightning-loop.address; - - services.nbxplorer.address = netns.nbxplorer.address; - services.btcpayserver.address = netns.btcpayserver.address; - - services.joinmarket = mkIf config.services.joinmarket.enable { - payjoinAddress = netns.joinmarket.address; - messagingAddress = netns.joinmarket.address; - cliExec = mkCliExec "joinmarket"; - }; - systemd.services.joinmarket-yieldgenerator = mkIf config.services.joinmarket.yieldgenerator.enable { - serviceConfig.NetworkNamespacePath = "/var/run/netns/nb-joinmarket"; - }; - - services.joinmarket-ob-watcher.address = netns.joinmarket-ob-watcher.address; - - services.lightning-pool.rpcAddress = netns.lightning-pool.address; - - services.rtl.address = netns.rtl.address; - - services.clightning-rest.address = netns.clightning-rest.address; - - services.mempool.address = netns.mempool.address; - services.mempool.frontend.address = netns.nginx.address; - } - ]); -} diff --git a/modules/nodeinfo.nix b/modules/nodeinfo.nix index 3abeb57..2d59a7d 100644 --- a/modules/nodeinfo.nix +++ b/modules/nodeinfo.nix @@ -130,11 +130,6 @@ in { nix-bitcoin.nodeinfo.services = with nodeinfoLib; { bitcoind = mkInfo ""; - clightning = mkInfo '' - info["nodeid"] = shell("lightning-cli getinfo | jq -r '.id'") - if 'onion_address' in info: - info["id"] = f"{info['nodeid']}@{info['onion_address']}" - ''; lnd = name: cfg: mkInfo ('' info["rest_address"] = "${nbLib.addressWithPort cfg.restAddress cfg.restPort}" '' + mkIfOnionPort "lnd-rest" (onionPort: '' @@ -142,17 +137,7 @@ in { '') + '' info["nodeid"] = shell("lncli getinfo | jq -r '.identity_pubkey'") '') name cfg; - clnrest = name: cfg: mkInfoLong { - inherit name cfg; - systemdServiceName = "clightning"; - }; - clightning-rest = mkInfo ""; electrs = mkInfo ""; - fulcrum = mkInfo ""; - btcpayserver = mkInfo ""; - liquidd = mkInfo ""; - joinmarket-ob-watcher = mkInfo ""; - rtl = mkInfo ""; mempool = mkInfo ""; mempool-frontend = name: cfg: mkInfoLong { inherit name cfg; diff --git a/modules/obsolete-options.nix b/modules/obsolete-options.nix deleted file mode 100644 index 5dda777..0000000 --- a/modules/obsolete-options.nix +++ /dev/null @@ -1,145 +0,0 @@ -{ lib, config, ... }: - -with lib; -let - mkRenamedAnnounceTorOption = service: - # use mkRemovedOptionModule because mkRenamedOptionModule fails with an infinite recursion error - mkRemovedOptionModule [ "services" service "announce-tor" ] '' - Use option `nix-bitcoin.onionServices.${service}.public` instead. - ''; - - mkSplitEnforceTorOption = service: - (mkRemovedOptionModule [ "services" service "enforceTor" ] '' - The option has been split into options `tor.proxy` and `tor.enforce`. - Set `tor.proxy = true` to proxy outgoing connections with Tor. - Set `tor.enforce = true` to only allow connections (incoming and outgoing) through Tor. - ''); - mkRenamedEnforceTorOption = service: - (mkRenamedOptionModule [ "services" service "enforceTor" ] [ "services" service "tor" "enforce" ]); - -in { - imports = [ - (mkRenamedOptionModule [ "services" "bitcoind" "bind" ] [ "services" "bitcoind" "address" ]) - (mkRenamedOptionModule [ "services" "bitcoind" "rpcallowip" ] [ "services" "bitcoind" "rpc" "allowip" ]) - (mkRenamedOptionModule [ "services" "bitcoind" "rpcthreads" ] [ "services" "bitcoind" "rpc" "threads" ]) - (mkRenamedOptionModule [ "services" "clightning" "bind-addr" ] [ "services" "clightning" "address" ]) - (mkRenamedOptionModule [ "services" "clightning" "bindport" ] [ "services" "clightning" "port" ]) - (mkRenamedOptionModule [ "services" "lnd" "rpclisten" ] [ "services" "lnd" "rpcAddress" ]) - (mkRenamedOptionModule [ "services" "lnd" "listen" ] [ "services" "lnd" "address" ]) - (mkRenamedOptionModule [ "services" "lnd" "listenPort" ] [ "services" "lnd" "port" ]) - (mkRenamedOptionModule [ "services" "btcpayserver" "bind" ] [ "services" "btcpayserver" "address" ]) - (mkRenamedOptionModule [ "services" "liquidd" "bind" ] [ "services" "liquidd" "address" ]) - (mkRenamedOptionModule [ "services" "liquidd" "rpcbind" ] [ "services" "liquidd" "rpc" "address" ]) - # 0.0.70 - (mkRenamedOptionModule [ "services" "rtl" "cl-rest" ] [ "services" "clightning-rest" ]) - - (mkRenamedOptionModule [ "nix-bitcoin" "setup-secrets" ] [ "nix-bitcoin" "setupSecrets" ]) - - (mkRenamedAnnounceTorOption "clightning") - (mkRenamedAnnounceTorOption "lnd") - - # 0.0.53 - (mkRemovedOptionModule [ "services" "electrs" "high-memory" ] '' - This option is no longer supported by electrs 0.9.0. Electrs now always uses - bitcoin peer connections for syncing blocks. This performs well on low and high - memory systems. - '') - # 0.0.86 - (mkRemovedOptionModule [ "services" "lnd" "restOnionService" "enable" ] '' - Set the following options instead: - services.lnd.lndconnect = { - enable = true; - onion = true; - } - '') - (mkRemovedOptionModule [ "services" "lnd" "lndconnectOnion" ] '' - Set the following options instead: - services.lnd.lndconnect = { - enable = true; - onion = true; - } - '') - (mkRemovedOptionModule [ "services" "clightning-rest" "lndconnectOnion" ] '' - Set the following options instead: - services.clightning-rest.lndconnect = { - enable = true; - onion = true; - } - '') - ] ++ - # 0.0.59 - (map mkSplitEnforceTorOption [ - "clightning" - "lightning-loop" - "lightning-pool" - "liquid" - "lnd" - "bitcoind" - ]) ++ - (map mkRenamedEnforceTorOption [ - "btcpayserver" - "rtl" - "electrs" - ]) ++ - # 0.0.77 - [ - (mkRemovedOptionModule [ "services" "clightning" "plugins" "commando" ] '' - clightning 0.12.0 ships with a reimplementation of the commando plugin - that is incompatible with the commando module that existed in - nix-bitcoin. The new built-in commando plugin is always enabled. For - information on how to use it, run `lightning-cli help commando` and - `lightning-cli help commando-rune`. - '') - ] ++ - # 0.0.92 - [ - (mkRemovedOptionModule [ "services" "spark-wallet" ] '' - Spark Lightning Wallet is unmaintained and incompatible with clightning - 23.05. Therefore, the spark-wallet module has been removed from - nix-bitcoin. For a replacement, consider using the rtl (Ride The - Lightning) module or the clightning-rest module in combination with the - Zeus mobile wallet. - '') - ] - ++ - # 0.0.98 - [ - (mkRemovedOptionModule [ "services" "clightning" "plugins" "clboss" "acknowledgeDeprecation" ] '' - `clboss` is maintained again and has been un-deprecated. - '') - ] - ++ - # 0.0.106 - (map (plugin: - mkRemovedOptionModule [ "services" "clightning" "plugins" plugin ] '' - This plugin is no longer maintained. - '') - [ "summary" "helpme" "prometheus" ] - ) - ++ - # 0.0.110 - [ - (mkRemovedOptionModule [ "services" "joinmarket" "yieldgenerator" "txfee" ] '' - Option `txfee` has been removed in joinmarket 0.9.3: - https://github.com/JoinMarket-Org/joinmarket-clientserver/blob/v0.9.3/docs/release-notes/release-notes-0.9.3.md - '') - ]; - - config = { - # Migrate old clightning-rest datadir from nix-bitcoin versions < 0.0.70 - systemd.services.clightning-rest-migrate-datadir = let - inherit (config.services) clightning-rest clightning; - in mkIf config.services.clightning-rest.enable { - requiredBy = [ "clightning-rest.service" ]; - before = [ "clightning-rest.service" ]; - script = '' - if [[ -e /var/lib/cl-rest/certs ]]; then - mv /var/lib/cl-rest/* '${clightning-rest.dataDir}' - chown -R ${clightning.user}: '${clightning-rest.dataDir}' - rm -r /var/lib/cl-rest - fi - ''; - serviceConfig.Type = "oneshot"; - }; - }; -} diff --git a/modules/onion-addresses.nix b/modules/onion-addresses.nix index 85193be..ec3ce76 100644 --- a/modules/onion-addresses.nix +++ b/modules/onion-addresses.nix @@ -15,10 +15,10 @@ let description = '' This option controls who is allowed to access onion addresses. For example, the following allows user 'myuser' to access bitcoind - and clightning onion addresses: + and lnd onion addresses: ```nix { - "myuser" = [ "bitcoind" "clightning" ]; + "myuser" = [ "bitcoind" "lnd" ]; }; ``` The onion hostnames can then be read from diff --git a/modules/onion-services.nix b/modules/onion-services.nix index 716ebb5..005cd3e 100644 --- a/modules/onion-services.nix +++ b/modules/onion-services.nix @@ -104,15 +104,6 @@ in { # Set sensible defaults for some services { nix-bitcoin.onionServices = { - btcpayserver = { - externalPort = 80; - }; - joinmarket-ob-watcher = { - externalPort = 80; - }; - rtl = { - externalPort = 80; - }; mempool-frontend = { externalPort = 80; }; diff --git a/modules/presets/enable-tor.nix b/modules/presets/enable-tor.nix index 47766f2..d81fcff 100644 --- a/modules/presets/enable-tor.nix +++ b/modules/presets/enable-tor.nix @@ -19,36 +19,18 @@ in { # and restrict all connections to Tor # bitcoind = defaultEnableTorProxy; - clightning = defaultEnableTorProxy; lnd = defaultEnableTorProxy; - lightning-loop = defaultEnableTorProxy; - liquidd = defaultEnableTorProxy; - # TODO-EXTERNAL: - # disable Tor enforcement until btcpayserver can fetch rates over Tor - # btcpayserver = defaultEnableTorProxy; - lightning-pool = defaultEnableTorProxy; mempool = defaultEnableTorProxy; # These services don't make outgoing connections - # (or use Tor by default in case of joinmarket) # but we restrict them to Tor just to be safe. # electrs = defaultEnforceTor; - fulcrum = defaultEnforceTor; - nbxplorer = defaultEnforceTor; - rtl = defaultEnforceTor; - joinmarket = defaultEnforceTor; - joinmarket-ob-watcher = defaultEnforceTor; - clightning-rest = defaultEnforceTor; }; # Add onion services for incoming connections nix-bitcoin.onionServices = { bitcoind.enable = defaultTrue; - liquidd.enable = defaultTrue; electrs.enable = defaultTrue; - fulcrum.enable = defaultTrue; - joinmarket-ob-watcher.enable = defaultTrue; - rtl.enable = defaultTrue; }; } diff --git a/modules/presets/secure-node.nix b/modules/presets/secure-node.nix index 90ffd43..07ca605 100644 --- a/modules/presets/secure-node.nix +++ b/modules/presets/secure-node.nix @@ -12,11 +12,6 @@ in { ./enable-tor.nix ]; - options = { - # Used by ../versioning.nix - nix-bitcoin.secure-node-preset-enabled = {}; - }; - config = { networking.firewall.enable = true; @@ -41,18 +36,8 @@ in { dbCache = 1000; }; - services.liquidd = { - # Enable `validatepegin` to verify that a transaction sending BTC into - # Liquid exists on Bitcoin. Without it, a malicious liquid federation can - # make the node accept a sidechain that is not fully backed. - validatepegin = true; - listen = true; - }; - nix-bitcoin.nodeinfo.enable = true; - services.backups.frequency = "daily"; - # operator nix-bitcoin.operator.enable = true; users.users.${operatorName} = { diff --git a/modules/rtl.nix b/modules/rtl.nix deleted file mode 100644 index 60a3bca..0000000 --- a/modules/rtl.nix +++ /dev/null @@ -1,239 +0,0 @@ -{ config, lib, pkgs, ... }: - -with lib; -let - options.services.rtl = { - enable = mkEnableOption "Ride The Lightning, a web interface for lnd and clightning"; - address = mkOption { - type = types.str; - default = "127.0.0.1"; - description = "HTTP server address."; - }; - port = mkOption { - type = types.port; - default = 3000; - description = "HTTP server port."; - }; - dataDir = mkOption { - type = types.path; - default = "/var/lib/rtl"; - description = "The data directory for RTL."; - }; - nodes = { - clightning = { - enable = mkOption { - type = types.bool; - default = false; - description = "Enable the clightning node interface."; - }; - extraConfig = mkOption { - type = with types; attrsOf anything; - default = {}; - example = { - Settings.userPersona = "MERCHANT"; - Settings.logLevel = "DEBUG"; - }; - description = '' - Extra clightning node configuration. - See here for all available options: - https://github.com/Ride-The-Lightning/RTL/blob/master/.github/docs/Application_configurations.md - ''; - }; - }; - lnd = { - enable = mkOption { - type = types.bool; - default = false; - description = "Enable the lnd node interface."; - }; - loop = mkOption { - type = types.bool; - default = false; - description = "Enable swaps with lightning-loop."; - }; - extraConfig = mkOption { - type = with types; attrsOf anything; - default = {}; - example = { - Settings.userPersona = "MERCHANT"; - Settings.logLevel = "DEBUG"; - }; - description = '' - Extra lnd node configuration. - See here for all available options: - https://github.com/Ride-The-Lightning/RTL/blob/master/.github/docs/Application_configurations.md - ''; - }; - }; - reverseOrder = mkOption { - type = types.bool; - default = false; - description = '' - Reverse the order of nodes shown in the UI. - By default, clightning is shown before lnd. - ''; - }; - }; - nightTheme = mkOption { - type = types.bool; - default = false; - description = "Enable the Night UI Theme."; - }; - extraCurrency = mkOption { - type = with types; nullOr str; - default = null; - example = "USD"; - description = '' - Currency code (ISO 4217) of the extra currency used for displaying balances. - When set, this option enables online currency rate fetching. - Warning: Rate fetching requires outgoing clearnet connections, so option - {option}`tor.enforce` is automatically disabled. - ''; - }; - user = mkOption { - type = types.str; - default = "rtl"; - description = "The user as which to run RTL."; - }; - group = mkOption { - type = types.str; - default = cfg.user; - description = "The group as which to run RTL."; - }; - tor.enforce = nbLib.tor.enforce; - }; - - cfg = config.services.rtl; - nbLib = config.nix-bitcoin.lib; - nbPkgs = config.nix-bitcoin.pkgs; - secretsDir = config.nix-bitcoin.secretsDir; - runePath = "${cfg.dataDir}/clightning-admin-rune"; - - inherit (nbLib) optionalAttr; - - node = { isLnd, index }: { - inherit index; - lnNode = "Node"; - lnImplementation = if isLnd then "LND" else "CLT"; - Authentication = { - ${optionalAttr (isLnd && lndLoopEnabled) "swapMacaroonPath"} = "${lightning-loop.dataDir}/${bitcoind.network}"; - ${optionalAttr (isLnd) "macaroonPath"} = "${cfg.dataDir}/macaroons"; - ${optionalAttr (!isLnd) "runePath"} = runePath; - }; - Settings = { - userPersona = "OPERATOR"; - themeMode = if cfg.nightTheme then "NIGHT" else "DAY"; - themeColor = "PURPLE"; - ${optionalAttr isLnd "channelBackupPath"} = "${cfg.dataDir}/backup/lnd"; - logLevel = "INFO"; - fiatConversion = cfg.extraCurrency != null; - ${optionalAttr (cfg.extraCurrency != null) "currencyUnit"} = cfg.extraCurrency; - ${optionalAttr (isLnd && lndLoopEnabled) "swapServerUrl"} = - "https://${nbLib.addressWithPort lightning-loop.restAddress lightning-loop.restPort}"; - lnServerUrl = "https://${ - if isLnd - then nbLib.addressWithPort lnd.restAddress lnd.restPort - else nbLib.addressWithPort clightning.plugins.clnrest.address clightning.plugins.clnrest.port - }"; - }; - }; - - nodes' = - optional cfg.nodes.clightning.enable - (recursiveUpdate (node { isLnd = false; index = 1; }) cfg.nodes.clightning.extraConfig) ++ - optional cfg.nodes.lnd.enable - (recursiveUpdate (node { isLnd = true; index = 2; }) cfg.nodes.lnd.extraConfig); - - nodes = if cfg.nodes.reverseOrder then reverseList nodes' else nodes'; - - rtlConfig = { - multiPass = "@multiPass@"; - host = cfg.address; - port = cfg.port; - SSO.rtlSSO = 0; - inherit nodes; - }; - - configFile = builtins.toFile "config" (builtins.toJSON rtlConfig); - - inherit (config.services) - bitcoind - lnd - clightning - lightning-loop; - - lndLoopEnabled = cfg.nodes.lnd.enable && cfg.nodes.lnd.loop; -in { - inherit options; - - config = mkIf cfg.enable { - assertions = [ - { assertion = cfg.nodes.clightning.enable || cfg.nodes.lnd.enable; - message = '' - RTL: At least one of `nodes.lnd.enable` or `nodes.clightning.enable` must be `true`. - ''; - } - ]; - - services.lnd.enable = mkIf cfg.nodes.lnd.enable true; - services.lightning-loop.enable = mkIf lndLoopEnabled true; - services.clightning = mkIf cfg.nodes.clightning.enable { - enable = true; - plugins.clnrest.enable = true; - }; - - systemd.tmpfiles.rules = [ - "d '${cfg.dataDir}' 0770 ${cfg.user} ${cfg.group} - -" - ]; - - services.rtl.tor.enforce = mkIf (cfg.extraCurrency != null) false; - - systemd.services.rtl = rec { - wantedBy = [ "multi-user.target" ]; - wants = optional cfg.nodes.clightning.enable "clightning.service" ++ - optional cfg.nodes.lnd.enable "lnd.service"; - after = wants ++ [ "nix-bitcoin-secrets.target" ]; - environment.RTL_CONFIG_PATH = cfg.dataDir; - environment.DB_DIRECTORY_PATH = cfg.dataDir; - serviceConfig = nbLib.defaultHardening // { - ExecStartPre = [ - (nbLib.script "rtl-setup-config" '' - <${configFile} sed "s|@multiPass@|$(cat ${secretsDir}/rtl-password)|" \ - > '${cfg.dataDir}/RTL-Config.json' - '') - ] - ++ optional cfg.nodes.lnd.enable - # The lnd admin macaroon is not readable by group `lnd`, so copy it - (nbLib.rootScript "rtl-copy-macaroon" '' - install --compare -m 640 -o ${cfg.user} -g ${cfg.group} -D ${lnd.networkDir}/admin.macaroon \ - '${cfg.dataDir}/macaroons/admin.macaroon' - '') - ++ optional cfg.nodes.clightning.enable - (nbLib.rootScript "rtl-create-clnrest-rune-file" '' - rune=$(cat '${clightning.networkDir}/admin-rune') - install --compare -m 640 -o ${cfg.user} -g ${cfg.group} <(printf 'LIGHTNING_RUNE="%s"\n' "$rune") '${runePath}' - ''); - ExecStart = "${nbPkgs.rtl}/bin/rtl"; - # Show "rtl" instead of "node" in the journal - SyslogIdentifier = "rtl"; - User = cfg.user; - Restart = "on-failure"; - RestartSec = "10s"; - ReadWritePaths = [ cfg.dataDir ]; - } // nbLib.allowedIPAddresses cfg.tor.enforce - // nbLib.nodejs; - }; - - users.users.${cfg.user} = { - isSystemUser = true; - group = cfg.group; - extraGroups = optional lndLoopEnabled lnd.group; - }; - users.groups.${cfg.group} = {}; - - nix-bitcoin.secrets.rtl-password.user = cfg.user; - nix-bitcoin.generateSecretsCmds.rtl = '' - makePasswordSecret rtl-password - ''; - }; -} diff --git a/modules/secrets/secrets.nix b/modules/secrets/secrets.nix index 944c92b..fa8cbb9 100644 --- a/modules/secrets/secrets.nix +++ b/modules/secrets/secrets.nix @@ -35,14 +35,6 @@ let ''; }; - # Currently, this is used only by ../deployment/nixops.nix - deployment.secretsDir = mkOption { - type = types.path; - description = '' - Directory of local secrets that are transferred to the nix-bitcoin node on deployment - ''; - }; - secrets = mkOption { default = {}; type = with types; attrsOf (submodule ( diff --git a/modules/versioning.nix b/modules/versioning.nix deleted file mode 100644 index 8476709..0000000 --- a/modules/versioning.nix +++ /dev/null @@ -1,292 +0,0 @@ -{ config, pkgs, lib, ... }: - -# Workflow for releasing a new nix-bitcoin version with incompatible changes: -# Let V be the version of the upcoming, incompatible release. -# 1. Add change descriptions with `version = V` at the end of the `changes` list below. -# 2. Set `nix-bitcoin.configVersion = V` in ../examples/configuration.nix. - -with lib; -let - options = { - nix-bitcoin.configVersion = mkOption { - type = with types; nullOr str; - default = null; - example = "0.0.92"; - description = '' - The nix-bitcoin release version that your config is compatible with. - - When upgrading to a backwards-incompatible release, nix-bitcoin will throw an - error during evaluation and provide instructions for migrating your config to - the new release. - - Once set, you only need to update this option when explicitly told to in an - error message during evaluation. - ''; - }; - }; - - # Sorted by increasing version numbers - changes = [ - { - version = "0.0.26"; - condition = config.services.joinmarket.enable; - message = let - inherit (config.services.joinmarket) dataDir; - in '' - JoinMarket 0.8.0 moves from wrapped segwit wallets to native segwit wallets. - - If you have an existing wrapped segwit wallet, you have to manually migrate - your funds to a new native segwit wallet. - - To migrate, you first have to deploy the new JoinMarket version: - 1. Set `nix-bitcoin.configVersion = "0.0.26";` in your configuration.nix - 2. Deploy the new configuration - - Then run the following on your nix-bitcoin node: - 1. Move your wallet: - mv ${dataDir}/wallets/wallet.jmdat ${dataDir}/wallets/old.jmdat - 2. Autogenerate a new p2wpkh wallet: - systemctl restart joinmarket - 3. Transfer your funds manually by doing sweeps for each mixdepth: - jm-sendpayment -m -N 0 old.jmdat 0 - - Run this command for every available mixdepth (`-m 0`, `-m 1`, ...). - IMPORTANT: Use a different for every run. - - Explanation of the options: - -m : spend from given mixdepth. - -N 0: don't coinjoin on this spend - old.jmdat: spend from old wallet - 0: set amount to zero to do a sweep, i.e. transfer all funds at given mixdepth - : destination p2wpkh address from wallet.jmdat with mixdepth 0 - - Privacy Notes: - - This method transfers all funds to the same mixdepth 0. - Because wallet inputs at the same mixdepth can be considered to be linked, this undoes - the unlinking effects of previous coinjoins and resets all funds to mixdepth 0. - This only applies in case that the inputs to the new wallet are used for further coinjoins. - When inputs are instead kept separate in future transactions, the unlinking effects of - different mixdepths are preserved. - - A different should be used for every transaction. - - You might want to time stagger the transactions. - - Additionally, you can use coin-freezing to exclude specific inputs from the sweep. - - More information at - https://github.com/JoinMarket-Org/joinmarket-clientserver/blob/v0.8.0/docs/NATIVE-SEGWIT-UPGRADE.md - ''; - } - (mkOnionServiceChange "clightning") - (mkOnionServiceChange "lnd") - (mkOnionServiceChange "btcpayserver") - { - version = "0.0.41"; - condition = config.services.lnd.enable || config.services.joinmarket.enable; - message = let - secretsDir = config.nix-bitcoin.secretsDir; - lnd = config.services.lnd; - jm = config.services.joinmarket; - in '' - Secret files generated by services at runtime are now stored in the service - data dirs instead of the global secrets dir. - - To migrate, run the following Bash script as root on your nix-bitcoin node: - - if [[ -e ${secretsDir}/lnd-seed-mnemonic ]]; then - install -o ${lnd.user} -g ${lnd.group} -m400 "${secretsDir}/lnd-seed-mnemonic" "${lnd.dataDir}" - fi - if [[ -e ${secretsDir}/jm-wallet-seed ]]; then - install -o ${jm.user} -g ${jm.group} -m400 "${secretsDir}/jm-wallet-seed" "${jm.dataDir}" - fi - rm -f "${secretsDir}"/{lnd-seed-mnemonic,jm-wallet-seed} - ''; - } - { - version = "0.0.49"; - condition = config.services.joinmarket.enable; - message = '' - Starting with 0.21.0, bitcoind no longer automatically creates and loads a - default wallet named `wallet.dat` [1]. - The joinmarket service now automatically creates a watch-only bitcoind wallet - (named by option `services.joinmarket.rpcWalletFile`) when creating a joinmarket wallet. - - If you've used JoinMarket before, add the following to your configuration to - continue using the default `wallet.dat` wallet: - services.joinmarket.rpcWalletFile = null; - - [1] https://github.com/bitcoin/bitcoin/pull/15454 - ''; - } - { - version = "0.0.51"; - condition = config.services.joinmarket.enable; - message = let - jmDataDir = config.services.joinmarket.dataDir; - in '' - Joinmarket 0.9.1 has added support for Fidelity Bonds [1]. - - If you've used joinmarket before, do the following to enable Fidelity Bonds in your existing wallet. - Enabling Fidelity Bonds has no effect if you don't use them. - - 1. Deploy the new system config to your node - 2. Run the following on your node: - # Ensure that the wallet seed exists and rename the wallet - ls ${jmDataDir}/jm-wallet-seed && mv ${jmDataDir}/wallets/wallet.jmdat{,.bak} - # This automatically recreates the wallet with Fidelity Bonds support - systemctl restart joinmarket - # Remove wallet backup if update was successful - rm ${jmDataDir}/wallets/wallet.jmdat.bak - - [1] https://github.com/JoinMarket-Org/joinmarket-clientserver/blob/master/docs/fidelity-bonds.md - ''; - } - { - version = "0.0.53"; - condition = config.services.electrs.enable; - message = let - dbPath = "${config.services.electrs.dataDir}/mainnet"; - in '' - Electrs 0.9.0 has switched to a new, more space efficient database format, - reducing storage demands by ~60% [1]. - When started, electrs will automatically reindex the bitcoin blockchain. - This can take a few hours, depending on your hardware. The electrs server is - inactive during reindexing. - - To upgrade, do the following: - - - If you have less than 40 GB of free space [2] on the electrs data dir volume: - 1. Delete the database: - systemctl stop electrs - rm -r '${dbPath}' - 2. Deploy the new system config to your node - - - Otherwise: - 1. Deploy the new system config to your node - 2. Check that electrs works as expected and delete the old database: - rm -r '${dbPath}' - - [1] https://github.com/romanz/electrs/blob/557911e3baf9a000f883a6f619f0518945a7678d/doc/usage.md#upgrading - [2] This is based on the bitcoin blockchain size as of 2021-09. - The general formula is, approximately, size_of(${dbPath}) * 0.6 - This includes the final database size (0.4) plus some extra storage (0.2). - ''; - } - { - version = "0.0.57"; - condition = config.nix-bitcoin ? secure-node-preset-enabled && config.services.liquidd.enable; - message = '' - The `secure-node.nix` preset does _not_ set `liquidd.prune = 1000` anymore. - - - If you want to keep the same behavior as before, manually set - `services.liquidd.prune = 1000;` in your configuration.nix. - - Otherwise, if you want to turn off pruning, you must instruct liquidd - to reindex by setting `services.liquidd.extraConfig = "reindex=1";`. - This can be removed after having started liquidd with that option - once. - ''; - } - { - version = "0.0.65"; - condition = config.nix-bitcoin ? secure-node-preset-enabled && - config.nix-bitcoin.secretsDir == "/etc/nix-bitcoin-secrets"; - message = '' - The `secure-node.nix` preset does not set the secrets directory - to "/secrets" anymore. - Instead, the default location "/etc/nix-bitcoin-secrets" is used. - - To upgrade, choose one of the following: - - - Continue using "/secrets": - Add `nix-bitcoin.secretsDir = "/secrets";` to your configuration.nix. - - - Move your secrets to the default location: - Run the following command as root on your node: - `rsync -a /secrets/ /etc/nix-bitcoin-secrets`. - You can delete the old "/secrets" directory after deploying the new system - config to your node. - ''; - } - { - version = "0.0.70"; - condition = config.services.nbxplorer.enable; - message = '' - The nbxplorer database backend has changed from DBTrie to Postgresql. - The new `services.postgresql` database name is `nbxplorer`. - The migration happens automatically after deploying. - Migration time for a large server with a 5GB DBTrie database takes about 40 minutes. - See also: https://github.com/dgarage/NBXplorer/blob/master/docs/Postgres-Migration.md - ''; - } - { - version = "0.0.70"; - condition = config.services.clightning-rest.enable; - message = '' - The `cl-rest` service has been renamed to `clightning-rest`. - and is now available as a standalone service (`services.clightning-rest`). - Its data dir has moved to `${config.services.clightning-rest.dataDir}`, - and the service now runs under the clightning user and group. - The data dir migration happens automatically after deploying. - ''; - } - { - version = "0.0.70"; - condition = config.services.lnd.lndconnectOnion.enable; - message = '' - The `lndconnect-rest-onion` binary has been renamed to `lndconnect`. - ''; - } - { - version = "0.0.85"; - condition = config.services.fulcrum.enable; - message = '' - Fulcrum 1.9.0 has changed its database format. - The database update happens automatically and instantly on deployment, - but you can't switch back to an older Fulcrum version afterwards. - ''; - } - ]; - - mkOnionServiceChange = service: { - version = "0.0.30"; - condition = config.services.${service}.enable; - message = '' - The onion service for ${service} has been disabled in the default - configuration (`secure-node.nix`). - - To enable the onion service, add the following to your configuration: - nix-bitcon.onionServices.${service}.enable = true; - ''; - }; - - version = config.nix-bitcoin.configVersion; - - incompatibleChanges = optionals - (version != null && versionOlder lastChange) - (builtins.filter (change: versionOlder change && (change.condition or true)) changes); - - errorMsg = '' - - This version of nix-bitcoin contains the following changes - that are incompatible with your config (version ${version}): - - ${concatMapStringsSep "\n" (change: '' - - ${change.message}(This change was introduced in version ${change.version}) - '') incompatibleChanges} - After addressing the above changes, set nix-bitcoin.configVersion = "${lastChange.version}"; - in your nix-bitcoin configuration. - ''; - - versionOlder = change: (builtins.compareVersions change.version version) > 0; - lastChange = builtins.elemAt changes (builtins.length changes - 1); -in -{ - imports = [ - ./obsolete-options.nix - ]; - - inherit options; - - config = { - # Force evaluation. An actual option value is never assigned - system = optionalAttrs (builtins.length incompatibleChanges > 0) (builtins.throw errorMsg); - }; -} diff --git a/pkgs/bitcoind_29/default.nix b/pkgs/bitcoind_29/default.nix deleted file mode 100644 index 1b1a7d7..0000000 --- a/pkgs/bitcoind_29/default.nix +++ /dev/null @@ -1,214 +0,0 @@ -{ - lib, - stdenv, - fetchurl, - fetchFromGitHub, - cmake, - pkg-config, - installShellFiles, - wrapQtAppsHook ? null, - boost, - libevent, - zeromq, - zlib, - db48, - sqlite, - qrencode, - libsystemtap, - qtbase ? null, - qttools ? null, - python3, - versionCheckHook, - nixosTests, - withGui ? false, - withWallet ? true, - enableTracing ? stdenv.hostPlatform.isLinux && !stdenv.hostPlatform.isStatic, - gnupg, - # Signatures from the following GPG public keys checked during verification of the source code. - # The list can be found at https://github.com/bitcoin-core/guix.sigs/tree/main/builder-keys - builderKeys ? [ - "152812300785C96444D3334D17565732E08E5E41" # achow101.gpg - "9EDAFF80E080659604F4A76B2EBB056FD847F8A7" # Emzy.gpg - "71A3B16735405025D447E8F274810B012346C9A6" # laanwj.gpg - "6B002C6EA3F91B1B0DF0C9BC8F617F1200A6D25C" # glozow.gpg - "D1DBF2C4B96F2DEBF4C16654410108112E7EA81F" # hebasto.gpg - ], -}: - -let - desktop = fetchurl { - # c2e5f3e is the last commit when the debian/bitcoin-qt.desktop file was changed - url = "https://raw.githubusercontent.com/bitcoin-core/packaging/c2e5f3e20a8093ea02b73cbaf113bc0947b4140e/debian/bitcoin-qt.desktop"; - sha256 = "0cpna0nxcd1dw3nnzli36nf9zj28d2g9jf5y0zl9j18lvanvniha"; - }; -in -stdenv.mkDerivation (finalAttrs: { - pname = if withGui then "bitcoin" else "bitcoind"; - version = "29.2"; - - src = fetchurl { - urls = [ - "https://bitcoincore.org/bin/bitcoin-core-${finalAttrs.version}/bitcoin-${finalAttrs.version}.tar.gz" - ]; - # hash retrieved from signed SHA256SUMS - sha256 = "sha256-pSnXXQUSMX1jNLuf10y23co7HrNF0unjG2YTZYPswEU="; - }; - - nativeBuildInputs = [ - cmake - pkg-config - installShellFiles - gnupg - ] - ++ lib.optionals withGui [ wrapQtAppsHook ]; - - buildInputs = [ - boost - libevent - zeromq - zlib - ] - ++ lib.optionals enableTracing [ libsystemtap ] - ++ lib.optionals withWallet [ sqlite ] - # building with db48 (for legacy descriptor wallet support) is broken on Darwin - ++ lib.optionals (withWallet && !stdenv.hostPlatform.isDarwin) [ db48 ] - ++ lib.optionals withGui [ - qrencode - qtbase - qttools - ]; - - preUnpack = - let - publicKeys = fetchFromGitHub { - owner = "bitcoin-core"; - repo = "guix.sigs"; - rev = "a788388207bd244d5ab07b31ecd6c126f213a6c6"; - sha256 = "sha256-gbenuEWP6pqY9ywPd/yZy6QfWI7jvSObwto27DRXjGI="; - }; - - checksums = fetchurl { - url = "https://bitcoincore.org/bin/bitcoin-core-${finalAttrs.version}/SHA256SUMS"; - hash = "sha256-siFBow5riZNg6LsMXpJc3u0txCGKJJCy24Cmm0TbvDM="; - }; - - signatures = fetchurl { - url = "https://bitcoincore.org/bin/bitcoin-core-${finalAttrs.version}/SHA256SUMS.asc"; - hash = "sha256-pUBsfT9BvsTIqxAA9CSp1Z8K8RQpi1e00ssEa2il8CQ="; - }; - - verifyBuilderKeys = - let - script = publicKey: '' - echo "Checking if public key ${publicKey} signed the checksum file..." - grep "^\[GNUPG:\] VALIDSIG .* ${publicKey}$" verify.log > /dev/null - echo "OK" - ''; - in - builtins.concatStringsSep "\n" (map script builderKeys); - in - '' - pushd $(mktemp -d) - export GNUPGHOME=$PWD/gnupg - mkdir -m 700 -p $GNUPGHOME - gpg --no-autostart --batch --import ${publicKeys}/builder-keys/* - ln -s ${checksums} ./SHA256SUMS - ln -s ${signatures} ./SHA256SUMS.asc - ln -s $src ./bitcoin-${finalAttrs.version}.tar.gz - gpg --no-autostart --batch --verify --status-fd 1 SHA256SUMS.asc SHA256SUMS > verify.log - ${verifyBuilderKeys} - echo "Checking ${checksums} for bitcoin-${finalAttrs.version}.tar.gz..." - grep bitcoin-${finalAttrs.version}.tar.gz SHA256SUMS > SHA256SUMS.filtered - echo "Verifying the checksum of bitcoin-${finalAttrs.version}.tar.gz..." - sha256sum -c SHA256SUMS.filtered - popd - ''; - - postInstall = '' - cd .. - installShellCompletion --bash contrib/completions/bash/bitcoin-cli.bash - installShellCompletion --bash contrib/completions/bash/bitcoind.bash - installShellCompletion --bash contrib/completions/bash/bitcoin-tx.bash - - installShellCompletion --fish contrib/completions/fish/bitcoin-cli.fish - installShellCompletion --fish contrib/completions/fish/bitcoind.fish - installShellCompletion --fish contrib/completions/fish/bitcoin-tx.fish - installShellCompletion --fish contrib/completions/fish/bitcoin-util.fish - installShellCompletion --fish contrib/completions/fish/bitcoin-wallet.fish - '' - + lib.optionalString withGui '' - installShellCompletion --fish contrib/completions/fish/bitcoin-qt.fish - - install -Dm644 ${desktop} $out/share/applications/bitcoin-qt.desktop - substituteInPlace $out/share/applications/bitcoin-qt.desktop --replace "Icon=bitcoin128" "Icon=bitcoin" - install -Dm644 share/pixmaps/bitcoin256.png $out/share/pixmaps/bitcoin.png - ''; - - cmakeFlags = [ - (lib.cmakeBool "BUILD_BENCH" false) - (lib.cmakeBool "WITH_ZMQ" true) - # building with db48 (for legacy wallet support) is broken on Darwin - (lib.cmakeBool "WITH_BDB" (withWallet && !stdenv.hostPlatform.isDarwin)) - (lib.cmakeBool "WITH_USDT" enableTracing) - ] - ++ lib.optionals (!finalAttrs.doCheck) [ - (lib.cmakeBool "BUILD_TESTS" false) - (lib.cmakeBool "BUILD_FUZZ_BINARY" false) - (lib.cmakeBool "BUILD_GUI_TESTS" false) - ] - ++ lib.optionals (!withWallet) [ - (lib.cmakeBool "ENABLE_WALLET" false) - ] - ++ lib.optionals withGui [ - (lib.cmakeBool "BUILD_GUI" true) - ]; - - NIX_LDFLAGS = lib.optionals ( - stdenv.hostPlatform.isLinux && stdenv.hostPlatform.isStatic - ) "-levent_core"; - - nativeCheckInputs = [ python3 ]; - - doCheck = true; - - checkFlags = [ - "LC_ALL=en_US.UTF-8" - ] - # QT_PLUGIN_PATH needs to be set when executing QT, which is needed when testing Bitcoin's GUI. - # See also https://github.com/NixOS/nixpkgs/issues/24256 - ++ lib.optional withGui "QT_PLUGIN_PATH=${qtbase}/${qtbase.qtPluginPrefix}"; - - enableParallelBuilding = true; - - __darwinAllowLocalNetworking = true; - - nativeInstallCheckInputs = [ - versionCheckHook - ]; - versionCheckProgram = "${placeholder "out"}/bin/bitcoin-cli"; - versionCheckProgramArg = "--version"; - doInstallCheck = true; - - passthru.tests = { - smoke-test = nixosTests.bitcoind; - }; - - meta = { - description = "Peer-to-peer electronic cash system"; - longDescription = '' - Bitcoin is a free open source peer-to-peer electronic cash system that is - completely decentralized, without the need for a central server or trusted - parties. Users hold the crypto keys to their own money and transact directly - with each other, with the help of a P2P network to check for double-spending. - ''; - homepage = "https://bitcoin.org/en/"; - downloadPage = "https://bitcoincore.org/bin/bitcoin-core-${finalAttrs.version}/"; - changelog = "https://bitcoincore.org/en/releases/${finalAttrs.version}/"; - maintainers = with lib.maintainers; [ - prusnak - roconnor - ]; - license = lib.licenses.mit; - platforms = lib.platforms.unix; - }; -}) diff --git a/pkgs/clightning-plugins/default.nix b/pkgs/clightning-plugins/default.nix deleted file mode 100644 index 0886fd1..0000000 --- a/pkgs/clightning-plugins/default.nix +++ /dev/null @@ -1,76 +0,0 @@ -pkgs: nbPython3Packages: - -let - inherit (pkgs) lib; - - src = pkgs.fetchFromGitHub { - owner = "lightningd"; - repo = "plugins"; - rev = "c0ba9dc3273923c427053eec0c343776793a81c0"; - sha256 = "1hdiikm8m3azd16fpgcbj7fcg1d7f8l4kvj1763vikg85khzlrcv"; - }; - - version = builtins.substring 0 7 src.rev; - - plugins = with nbPython3Packages; { - currencyrate = { - description = "Currency rate fetcher and converter"; - extraPkgs = [ requests cachetools ]; - }; - feeadjuster = { - description = "Dynamically changes channel fees to keep your channels more balanced"; - }; - monitor = { - description = "Helps you analyze the health of your peers and channels"; - extraPkgs = [ packaging ]; - }; - rebalance = { - description = "Keeps your channels balanced"; - }; - zmq = { - description = "Publishes notifications via ZeroMQ to configured endpoints"; - scriptName = "cl-zmq"; - extraPkgs = [ twisted txzmq ]; - }; - }; - - basePkgs = [ nbPython3Packages.pyln-client ]; - - mkPlugin = name: plugin: let - python = pkgs.python3.withPackages (_: basePkgs ++ (plugin.extraPkgs or [])); - script = "${plugin.scriptName or name}.py"; - drv = pkgs.stdenv.mkDerivation { - pname = "clightning-plugin-${name}"; - inherit version; - - buildInputs = [ python ]; - - buildCommand = '' - cp --no-preserve=mode -r '${src}/${name}' "$out" - cd "$out" - ${lib.optionalString (plugin ? patchRequirements) '' - substituteInPlace requirements.txt ${plugin.patchRequirements} - ''} - - # Check that requirements are met - PYTHONPATH='${toString python}/${python.sitePackages}' \ - ${pkgs.python3Packages.pip}/bin/pip install -r requirements.txt --no-cache --no-index --break-system-packages - - chmod +x '${script}' - patchShebangs '${script}' - ''; - - passthru.path = "${drv}/${script}"; - - meta = with lib; { - inherit (plugin) description; - homepage = "https://github.com/lightningd/plugins"; - license = licenses.bsd3; - maintainers = with maintainers; [ nixbitcoin erikarvstedt ]; - platforms = platforms.unix; - }; - }; - in drv; - -in - builtins.mapAttrs mkPlugin plugins diff --git a/pkgs/clightning-plugins/get-sha256.sh b/pkgs/clightning-plugins/get-sha256.sh deleted file mode 100755 index b66906f..0000000 --- a/pkgs/clightning-plugins/get-sha256.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail -. "${BASH_SOURCE[0]%/*}/../../helper/run-in-nix-env" "git" "$@" - -archive_hash () { - repo=$1 - rev=$2 - nix-prefetch-url --unpack "https://github.com/${repo}/archive/${rev}.tar.gz" 2> /dev/null | tail -n 1 -} - -echo "Fetching latest lightningd/plugins release" -latest=$(git ls-remote https://github.com/lightningd/plugins master | cut -f 1) -echo "rev = \"${latest}\";" -echo "sha256 = \"$(archive_hash lightningd/plugins "$latest")\";" diff --git a/pkgs/clightning-rest/default.nix b/pkgs/clightning-rest/default.nix deleted file mode 100644 index 8d9256b..0000000 --- a/pkgs/clightning-rest/default.nix +++ /dev/null @@ -1,55 +0,0 @@ -{ lib -, stdenvNoCC -, nodejs_22 -, nodejs-slim_22 -, fetchNodeModules -, fetchurl -, makeWrapper -, rsync -}: -let self = stdenvNoCC.mkDerivation { - pname = "clightning-rest"; - version = "0.10.7"; - - src = fetchurl { - url = "https://github.com/Ride-The-Lightning/c-lightning-REST/archive/refs/tags/v${self.version}.tar.gz"; - hash = "sha256-m/djMQk+g994GaTW/yysD/eVgWcqY8cap41tot0UElI="; - }; - - passthru = { - nodejs = nodejs_22; - nodejsRuntime = nodejs-slim_22; - - nodeModules = fetchNodeModules { - inherit (self) src nodejs; - hash = "sha256-Dz4/kR4X34idfuPFFQJYE8yGIR3OSseDnkAhqbZ6iEI="; - }; - }; - - nativeBuildInputs = [ - makeWrapper - ]; - - 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; { - description = "REST API for C-Lightning"; - homepage = "https://github.com/Ride-The-Lightning/c-lightning-REST"; - license = licenses.mit; - maintainers = with maintainers; [ nixbitcoin erikarvstedt ]; - platforms = platforms.unix; - }; -}; in self diff --git a/pkgs/clightning-rest/generate.sh b/pkgs/clightning-rest/generate.sh deleted file mode 100755 index 51f62fd..0000000 --- a/pkgs/clightning-rest/generate.sh +++ /dev/null @@ -1,40 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail -. "${BASH_SOURCE[0]%/*}/../../helper/run-in-nix-env" "gnupg wget gnused" "$@" - -version="0.10.7" -repo=https://github.com/Ride-The-Lightning/c-lightning-REST - -scriptDir=$(cd "${BASH_SOURCE[0]%/*}" && pwd) - -updateSrc() { - TMPDIR=$(mktemp -d /tmp/clightning-rest.XXX) - trap 'rm -rf $TMPDIR' EXIT - - # 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}") - - sed -i " - s|\bversion = .*;|version = \"$version\";| - s|\bhash = .*;|hash = \"$hash\";| - " default.nix -} - -updateNodeModulesHash() { - "$scriptDir/../../helper/update-fixed-output-derivation.sh" ./default.nix clightning-rest.nodeModules nodeModules -} - -if [[ $# == 0 ]]; then - # Each of these can be run separately - updateSrc - updateNodeModulesHash -else - "$@" -fi diff --git a/pkgs/clnrest/default.nix b/pkgs/clnrest/default.nix deleted file mode 100644 index 8848472..0000000 --- a/pkgs/clnrest/default.nix +++ /dev/null @@ -1,50 +0,0 @@ -{ - lib, - rustPlatform, - clightning, - unzip, - protobuf, -}: -rustPlatform.buildRustPackage rec { - pname = "clnrest"; - version = "0.2.0"; - - inherit (clightning) src; - - cargoHash = "sha256-0rpr941QkDeNLQ6Se9+DbbVBCmGyU721a27XNzylpPw="; - - depsExtraArgs = { - nativeBuildInputs = [ unzip ]; - # Don't run `configure` of the main project build - dontConfigure = true; - }; - - nativeBuildInputs = [ - # For unpacking the src - unzip - ]; - - cargoBuildFlags = [ "--package clnrest" ]; - - nativeCheckInputs = [ - # Required by lightning/cln-grpc/build.rs - protobuf - ]; - - # `core::lsps2::htlc::tests::polls_until_channel_ready` (in the `cln-lsps` - # workspace member) is timing-dependent: it spawns a polling task, sleeps a - # real 10 ms, then asserts the loop ran more than once. Under the parallel - # test load in CI the spawned task gets starved and the assertion fails. - # Skip this single upstream test; the remaining workspace tests still run. - checkFlags = [ "--skip=polls_until_channel_ready" ]; - - meta = with lib; { - description = "REST plugin for clightning"; - homepage = "https://github.com/ElementsProject/lightning/tree/master/plugins/rest-plugin"; - license = licenses.mit; - maintainers = with maintainers; [ - erikarvstedt - ]; - mainProgram = "clnrest"; - }; -} diff --git a/pkgs/default.nix b/pkgs/default.nix index 74e89ce..877e1ed 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -15,39 +15,15 @@ in } }: let self = { - clightning-rest = pkgs.callPackage ./clightning-rest { inherit (self) fetchNodeModules; }; - clightning-plugins = pkgs.lib.recurseIntoAttrs (import ./clightning-plugins pkgs self.nbPython3Packages); - clnrest = pkgs.callPackage ./clnrest { inherit (self.pinned) clightning; }; - joinmarket = pkgs.callPackage ./joinmarket { inherit (self) nbPython3PackagesJoinmarket; }; lndinit = pkgs.callPackage ./lndinit { }; - liquid-swap = pkgs.python3Packages.callPackage ./liquid-swap { }; - nbxplorer = pkgs.callPackage ./nbxplorer { }; - rtl = pkgs.callPackage ./rtl { inherit (self) fetchNodeModules; }; inherit (pkgs.callPackage ./mempool { inherit (self) fetchNodeModules; }) mempool-backend mempool-frontend mempool-rust-gbt mempool-nginx-conf; - trustedcoin = pkgs.callPackage ./trustedcoin { }; - - bitcoind_29 = pkgs.callPackage ./bitcoind_29 {}; - inherit (self.pyPkgs.nbPython3PackagesWithUnlockedEcdsa) hwi; - - pyPkgs = import ./python-packages self pkgs.python3; - inherit (self.pyPkgs) - nbPython3Packages - nbPython3PackagesJoinmarket; fetchNodeModules = pkgs.callPackage ./build-support/fetch-node-modules.nix { }; - # Internal pkgs - netns-exec = pkgs.callPackage ./netns-exec { }; - krops = import ./krops { inherit pkgs; }; - - # Deprecated pkgs - generate-secrets = import ./generate-secrets-deprecated.nix; - nixops19_09 = pkgs.callPackage ./nixops { }; - pinned = import ./pinned.nix pkgs pkgsUnstable pkgs-25_05; modulesPkgs = self // self.pinned; diff --git a/pkgs/generate-secrets-deprecated.nix b/pkgs/generate-secrets-deprecated.nix deleted file mode 100644 index c54ff59..0000000 --- a/pkgs/generate-secrets-deprecated.nix +++ /dev/null @@ -1,25 +0,0 @@ -throw '' - Please update the `shell.nix` of your node configuration. - - To update, do the following: - 1. Switch to the directory containing your `configuration.nix` and `shell.nix`. - 2. Run the following Bash expression (Warning: This overwrites your `shell.nix`): - - # Only update nix-bitcoin-release.nix if it contains a release hash - if grep -q sha256 nix-bitcoin-release.nix; then - ${toString ../helper/fetch-release} > nix-bitcoin-release.nix && cp ${toString ../examples/shell.nix} . - else - cp ${toString ../examples/shell.nix} . - fi - - Note to NixOps users: - - After updating `shell.nix`, secrets are no longer auto-generated - when starting the shell. Please manually run shell command `generate-secrets` - before deploying. - - NixOps version 19.09 that shipped with nix-bitcoin is deprecated and is no longer - available in the shell. - Instead, you can add a current NixOps version to your shell PATH via `extraShellInitCmds` - or migrate to the krops deployment method. - See here for a migration guide: - ${toString ../docs/nixops-krops-migration.md} -'' diff --git a/pkgs/joinmarket/default.nix b/pkgs/joinmarket/default.nix deleted file mode 100644 index 05e2555..0000000 --- a/pkgs/joinmarket/default.nix +++ /dev/null @@ -1,68 +0,0 @@ -{ stdenv, lib, fetchFromGitHub, nbPython3PackagesJoinmarket }: - -let - # Note: - # After updating this pkg, also update the following items in ../../modules/joinmarket.nix: - # - The `MESSAGING:*` sections in the config value of option `settings`. - # Copy the values from `jmclient/configure.py`. - version = "0.9.11"; - src = fetchFromGitHub { - owner = "joinmarket-org"; - repo = "joinmarket-clientserver"; - rev = "v${version}"; - hash = "sha256-sYHhhp9BZz8udJuVAfwdt474OQPiye2ae5DOn5v5yEQ="; - }; - - runtimePackages = with nbPython3PackagesJoinmarket; [ - joinmarket - matplotlib # for ob-watcher - ]; - - pythonEnv = nbPython3PackagesJoinmarket.python.withPackages (_: runtimePackages); -in -stdenv.mkDerivation { - pname = "joinmarket"; - inherit version src; - - buildInputs = [ pythonEnv ]; - - installPhase = '' - mkdir -p "$out/bin" - - # add-utxo.py -> bin/jm-add-utxo - cpBin() { - cp "scripts/$1" "$out/bin/jm-''${1%.py}" - } - - cp scripts/joinmarketd.py "$out/bin/joinmarketd" - cpBin add-utxo.py - cpBin receive-payjoin.py - cpBin sendpayment.py - cpBin sendtomany.py - cpBin tumbler.py - cpBin wallet-tool.py - cpBin yg-privacyenhanced.py - cpBin genwallet.py - cpBin bond-calculator.py - - chmod +x -R "$out/bin" - patchShebangs "$out/bin" - - ## ob-watcher - obw=$out/libexec/joinmarket-ob-watcher - install -D scripts/obwatch/ob-watcher.py "$obw/ob-watcher" - patchShebangs "$obw/ob-watcher" - ln -s "$obw/ob-watcher" "$out/bin/jm-ob-watcher" - - # These files must be placed in the same dir as ob-watcher - cp -r scripts/obwatch/{orderbook.html,sybil_attack_calculations.py,vendor} "$obw" - ''; - - meta = with lib; { - description = "Bitcoin CoinJoin implementation"; - homepage = "https://github.com/JoinMarket-Org/joinmarket-clientserver"; - license = licenses.gpl3Only; - maintainers = with maintainers; [ seberm nixbitcoin ]; - platforms = platforms.unix; - }; -} diff --git a/pkgs/joinmarket/get-sha256.sh b/pkgs/joinmarket/get-sha256.sh deleted file mode 100755 index 6314778..0000000 --- a/pkgs/joinmarket/get-sha256.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env nix-shell -#!nix-shell -i bash -p git gnupg jq - -set -euo pipefail -newVersion=$(curl -s "https://api.github.com/repos/joinmarket-org/joinmarket-clientserver/releases" | jq -r '.[0].tag_name') - -# Fetch release and GPG-verify the content hash -tmpdir=$(mktemp -d /tmp/joinmarket-verify-gpg.XXX) -repo=$tmpdir/repo -git clone --depth 1 --branch "${newVersion}" -c advice.detachedHead=false https://github.com/joinmarket-org/joinmarket-clientserver "$repo" -export GNUPGHOME=$tmpdir -echo "Fetching Adam Gibson's key" -gpg --keyserver hkps://keyserver.ubuntu.com --recv-keys 2B6FC204D9BF332D062B461A141001A1AF77F20B 2> /dev/null -echo "Fetch Kristaps Kaupe's key" -gpg --keyserver hkps://keyserver.ubuntu.com --recv-keys 70A1D47DD44F59DF8B22244333E472FE870C7E5D 2> /dev/null -echo -echo "Verifying commit" -git -C "$repo" verify-commit HEAD -rm -rf "$repo"/.git -newHash=$(nix hash path "$repo") -rm -rf "$tmpdir" -echo - -echo "tag: $newVersion" -echo "hash: $newHash" diff --git a/pkgs/krops/default.nix b/pkgs/krops/default.nix deleted file mode 100644 index 8f11a3c..0000000 --- a/pkgs/krops/default.nix +++ /dev/null @@ -1,15 +0,0 @@ -{ pkgs ? import {} }: - -let - src = pkgs.fetchgit { - url = "https://cgit.krebsco.de/krops"; - rev = "1.26.2"; - sha256 = "0mzn213dh3pklvdzfpwi4nin4lncdap447zvl11j81r809jll76j"; - }; -in { - lib = import "${src}/lib"; - pkgs = rec { - krops = pkgs.callPackage "${src}/pkgs/krops" { inherit populate; }; - populate = pkgs.callPackage "${src}/pkgs/populate" {}; - }; -} diff --git a/pkgs/krops/fetch-release.sh b/pkgs/krops/fetch-release.sh deleted file mode 100755 index 44a56b9..0000000 --- a/pkgs/krops/fetch-release.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail -. "${BASH_SOURCE[0]%/*}/../../helper/run-in-nix-env" "git" "$@" - -archive_hash () { - repo=$1 - rev=$2 - nix-prefetch-url --unpack "https://github.com/${repo}/archive/${rev}.tar.gz" 2> /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/lib.nix b/pkgs/lib.nix index 5bfb639..e4f92e0 100644 --- a/pkgs/lib.nix +++ b/pkgs/lib.nix @@ -87,13 +87,6 @@ let self = { # Used for ExecStart* rootScript = name: src: "+${self.script name src}"; - cliExec = mkOption { - # Used by netns-isolation to execute the cli in the service's private netns - internal = true; - type = types.str; - default = "exec"; - }; - mkOnionService = map: { map = [ map ]; version = 3; diff --git a/pkgs/liquid-swap/default.nix b/pkgs/liquid-swap/default.nix deleted file mode 100644 index f1fa022..0000000 --- a/pkgs/liquid-swap/default.nix +++ /dev/null @@ -1,26 +0,0 @@ -{ lib, buildPythonPackage, fetchurl, click }: - -buildPythonPackage rec { - pname = "liquid-swap"; - version = "0.0.2"; - format = "setuptools"; - - propagatedBuildInputs = [ click ]; - - src = fetchurl { - urls = [ "https://github.com/Blockstream/liquid-swap/archive/release_${version}.tar.gz" ]; - sha256 = "9fa920ee7d03d1af8252131cd7d5a825bb66b8ad536403b4f5437ff6c91a68b1"; - }; - # Not sure if this does anything, but it should - 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/nbxplorer/default.nix b/pkgs/nbxplorer/default.nix deleted file mode 100644 index a920e9c..0000000 --- a/pkgs/nbxplorer/default.nix +++ /dev/null @@ -1,39 +0,0 @@ -{ - lib, - buildDotnetModule, - fetchFromGitHub, - dotnetCorePackages, -}: -buildDotnetModule rec { - pname = "nbxplorer"; - version = "2.6.7"; - - src = fetchFromGitHub { - owner = "dgarage"; - repo = "NBXplorer"; - tag = "v${version}"; - hash = "sha256-fA8Gv0Qc/+a8trLchXsawNk/4AdWjJCnzrwd8+rrJbw="; - }; - - projectFile = "NBXplorer/NBXplorer.csproj"; - nugetDeps = ./deps.json; - - dotnet-sdk = dotnetCorePackages.sdk_10_0; - dotnet-runtime = dotnetCorePackages.aspnetcore_10_0; - - # macOS has a case-insensitive filesystem, so these two can be the same file - postFixup = '' - mv $out/bin/{NBXplorer,nbxplorer} || : - ''; - - meta = with lib; { - description = "Minimalist UTXO tracker for HD Cryptocurrency Wallets"; - maintainers = with maintainers; [ - kcalvinalvin - erikarvstedt - ]; - license = licenses.mit; - platforms = platforms.linux ++ platforms.darwin; - mainProgram = "nbxplorer"; - }; -} diff --git a/pkgs/nbxplorer/deps.json b/pkgs/nbxplorer/deps.json deleted file mode 100644 index 270d786..0000000 --- a/pkgs/nbxplorer/deps.json +++ /dev/null @@ -1,82 +0,0 @@ -[ - { - "pname": "Dapper", - "version": "2.1.72", - "hash": "sha256-9CKyz72/Vp5/GIoxJzl7RAXTj4MvKTgFi/7fGyhRqf4=" - }, - { - "pname": "Microsoft.AspNetCore.JsonPatch", - "version": "10.0.6", - "hash": "sha256-yHK65u+3vBf3mxXuRybwuZN2CXhvN7lIdi/uDh7T/Lw=" - }, - { - "pname": "Microsoft.AspNetCore.Mvc.NewtonsoftJson", - "version": "10.0.6", - "hash": "sha256-hfL+FsI6CU2d6Z+Q1a1c+6gBgF4iV66fq25k8tEZQvs=" - }, - { - "pname": "Microsoft.Extensions.Logging.Abstractions", - "version": "1.0.0", - "hash": "sha256-asIXVFsAK7ELd/f+vLwhxYDdazqRTmf+fGJ4WFtcCeo=" - }, - { - "pname": "NBitcoin", - "version": "10.0.1", - "hash": "sha256-LdxZgCZNaVKpc5aZXVoM63LIzNM+zvf+Cg2c0nxjtCE=" - }, - { - "pname": "NBitcoin", - "version": "10.0.3", - "hash": "sha256-jX5gKpVucJiIAs42UtbCl8Qt05WN/NVBQFWg85nIa5M=" - }, - { - "pname": "NBitcoin.Altcoins", - "version": "6.0.3", - "hash": "sha256-U6xigLzDH9TpA6XkLTJRVBsL2OsaYjTD5evaVJ9NP7g=" - }, - { - "pname": "NETStandard.Library.Ref", - "version": "2.1.0", - "hash": "sha256-Ruovy9EKgXaFuFr3zgw5fRKUS9yBIJ4nLeHgXv0zx4o=" - }, - { - "pname": "Newtonsoft.Json", - "version": "12.0.1", - "hash": "sha256-4Xf3RZrJomAh3jaZrEAJX3oPmOowGV8yDB9Y3h0Dw4U=" - }, - { - "pname": "Newtonsoft.Json", - "version": "13.0.1", - "hash": "sha256-K2tSVW4n4beRPzPu3rlVaBEMdGvWSv/3Q1fxaDh4Mjo=" - }, - { - "pname": "Newtonsoft.Json", - "version": "13.0.3", - "hash": "sha256-hy/BieY4qxBWVVsDqqOPaLy1QobiIapkbrESm6v2PHc=" - }, - { - "pname": "Newtonsoft.Json.Bson", - "version": "1.0.2", - "hash": "sha256-ZUj6YFSMZp5CZtXiamw49eZmbp1iYBuNsIKNnjxcRzA=" - }, - { - "pname": "NicolasDorier.CommandLine", - "version": "2.0.0", - "hash": "sha256-LizYyIMx6I17jZd52duYcGWNgcPs88c/zWxo/ADd3D8=" - }, - { - "pname": "NicolasDorier.CommandLine.Configuration", - "version": "2.0.0", - "hash": "sha256-fDpDOVdt7xCDXXqaBnbaFvUOPaE0Sl4cLWjNkU0Cz7I=" - }, - { - "pname": "NicolasDorier.StandardConfiguration", - "version": "2.0.1", - "hash": "sha256-PdNopObnA2hOiHomejN/ZYK2CK1aGXMuOnsjHyS2Mco=" - }, - { - "pname": "Npgsql", - "version": "10.0.2", - "hash": "sha256-hW03ZWoW7y16vvScwsjZNyqFybGy+s6hQYQXebo78yQ=" - } -] diff --git a/pkgs/netns-exec/default.nix b/pkgs/netns-exec/default.nix deleted file mode 100644 index 6365c97..0000000 --- a/pkgs/netns-exec/default.nix +++ /dev/null @@ -1,10 +0,0 @@ -{ stdenv, pkgs }: - -stdenv.mkDerivation { - name = "netns-exec"; - buildInputs = [ pkgs.libcap ]; - src = ./src; - installPhase = '' - cp main "$out" - ''; -} diff --git a/pkgs/netns-exec/src/Makefile b/pkgs/netns-exec/src/Makefile deleted file mode 100644 index 8fa3e95..0000000 --- a/pkgs/netns-exec/src/Makefile +++ /dev/null @@ -1,2 +0,0 @@ -main: main.c - gcc -lcap -o main main.c diff --git a/pkgs/netns-exec/src/main.c b/pkgs/netns-exec/src/main.c deleted file mode 100644 index e86e6af..0000000 --- a/pkgs/netns-exec/src/main.c +++ /dev/null @@ -1,79 +0,0 @@ -/* This program requires CAP_SYS_ADMIN */ - -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include -#include - -static char *allowed_netns[] = { - "nb-joinmarket" -}; - -int is_netns_allowed(char *netns) { - int n_allowed_netns = sizeof(allowed_netns) / sizeof(allowed_netns[0]); - for (int i = 0; i < n_allowed_netns; i++) { - if (strcmp(allowed_netns[i], netns) == 0) { - return 1; - } - } - return 0; -} - -void print_capabilities() { - cap_t caps = cap_get_proc(); - printf("Capabilities: %s\n", cap_to_text(caps, NULL)); - cap_free(caps); -} - -void drop_capabilities() { - cap_t caps = cap_get_proc(); - cap_clear(caps); - cap_set_proc(caps); - cap_free(caps); -} - -int main(int argc, char **argv) { - char netns_path[256]; - - if (argc < 3) { - printf("usage: %s \n", argv[0]); - return 1; - } - - if (!is_netns_allowed(argv[1])) { - printf("%s is not an allowed netns.\n", argv[1]); - return 1; - } - - if(snprintf(netns_path, sizeof(netns_path), "/var/run/netns/%s", argv[1]) < 0) { - printf("Path length exceeded for netns %s.\n", argv[1]); - return 1; - } - - int fd = open(netns_path, O_RDONLY); - if (fd < 0) { - printf("Failed opening netns %s: %d, %s \n", netns_path, errno, strerror(errno)); - return 1; - } - - if (setns(fd, CLONE_NEWNET) < 0) { - printf("Failed setns %d, %s \n", errno, strerror(errno)); - return 1; - } - - /* Drop capabilities */ - #ifdef DEBUG - print_capabilities(); - #endif - drop_capabilities(); - #ifdef DEBUG - print_capabilities(); - #endif - - execvp(argv[2], &argv[2]); - return 0; -} diff --git a/pkgs/nixops/default.nix b/pkgs/nixops/default.nix deleted file mode 100644 index e7857c7..0000000 --- a/pkgs/nixops/default.nix +++ /dev/null @@ -1,48 +0,0 @@ -# An updated version of nixops that's compatible with machines running NixOS 19.09. -# 19.09 demands a suitable base image (defined in nixops-vbox/nix/virtualbox.nix) to -# start the virtualbox guest service during system activation. - -{ pkgs, stdenv, runCommand, fetchFromGitHub }: - -let - pluginData = { - aws = { - owner = "nixos"; - repo = "nixops-aws"; - rev= "v1.0.0"; - sha256 = "1if6spscsgd6ckivgvbqza5fvvn5hbafi1n8q0fw98s3xpz2hjfm"; - }; - hetzner = { - owner = "nixos"; - repo = "nixops-hetzner"; - rev = "v1.0.0"; - sha256 = "0cxfjpk2daczv3m7q5bsgfvd30qgmm1y7dnvz6nd7s7l7l0gsvas"; - }; - vbox = { - owner = "nix-community"; - repo = "nixops-vbox"; - rev = "bff6054ce9e7f5f9aa830617577f1a511a461063"; - sha256 = "0j0lbi8rqmw17ji367zh94lvlb062iiyavl4l7m851v40wqr8a5i"; - }; - }; - - origSrc = fetchFromGitHub { - owner = "NixOS"; - repo = "nixops"; - rev = "2434bf26e0bba49441041ffce36dc324f049bc00"; - sha256 = "0ag05pjwwqdw8in49hr8m8bdg31xsgqs1cawcqyh6a5lsys7f6zg"; - }; - - src = runCommand "src" {} '' - cp --no-preserve=mode -r '${origSrc}' "$out" - cd "$out" - patch -p1 < ${./release.nix.patch} - ''; - - nixopsRelease = import "${src}/release.nix" { - nixpkgs = pkgs.path; - inherit pluginData; - p = (p: with p; [ aws hetzner vbox ]); - }; -in -nixopsRelease.build.${builtins.currentSystem} diff --git a/pkgs/nixops/release.nix.patch b/pkgs/nixops/release.nix.patch deleted file mode 100644 index 940073e..0000000 --- a/pkgs/nixops/release.nix.patch +++ /dev/null @@ -1,67 +0,0 @@ ---- a/release.nix -+++ b/release.nix -@@ -1,6 +1,7 @@ - { nixopsSrc ? { outPath = ./.; revCount = 0; shortRev = "abcdef"; rev = "HEAD"; } - , officialRelease ? false - , nixpkgs ? -+, pluginData - , p ? (p: [ ]) - }: - -@@ -10,11 +11,10 @@ let - - allPlugins = let - plugins = let -- allPluginVers = import ./data.nix; -+ allPluginVers = pluginData; - fetch = v: - pkgs.fetchFromGitHub { -- inherit (v) owner repo sha256; -- rev = "v${v.version}"; -+ inherit (v) owner repo sha256 rev; - }; - srcDrv = v: (fetch v) + "/release.nix"; - in self: let -@@ -83,7 +83,7 @@ -# Remove annoying debug message that's shown in nix-shell while evaluating this file - pysqlite - typing - pluggy -- ] ++ pkgs.lib.traceValFn (x: "Using plugins: " + builtins.toJSON x) (map (d: d.build.${system}) (p allPlugins)); -+ ] ++ (map (d: d.build.${system}) (p allPlugins)); - - - # For "nix-build --run-env". - ---- a/nixops/backends/__init__.py -+++ b/nixops/backends/__init__.py -@@ -24,6 +24,7 @@ class MachineDefinition(nixops.resources.ResourceDefinition): - opts = {} - for (key, xmlType) in (('text', 'string'), - ('keyFile', 'path'), -+ ('keyFile', 'string'), - ('destDir', 'string'), - ('user', 'string'), - ('group', 'string'), ---- a/nixops/ssh_util.py -+++ b/nixops/ssh_util.py -@@ -278,6 +278,7 @@ class SSH(object): - - 'timeout' specifies the SSH connection timeout. - """ -+ flags = shlex.split(os.getenv('NIXOPS_SSH_OPTS', '')) + flags - master = self.get_master(flags, timeout, user) - flags = flags + self._get_flags() - if logged: - ---- a/nixops/deployment.py -+++ b/nixops/deployment.py -@@ -748,6 +748,6 @@ - if res == 100 or force_reboot or m.state == m.RESCUE: - if not allow_reboot and not force_reboot: - raise Exception("the new configuration requires a " -- "reboot to take effect (hint: use " -+ "reboot of '{}' to take effect (hint: use " - "‘--allow-reboot’)".format(m.name)) - m.reboot_sync() - res = 0 \ No newline at end of file diff --git a/pkgs/python-packages/bencoderpyx/default.nix b/pkgs/python-packages/bencoderpyx/default.nix deleted file mode 100644 index 68dc67d..0000000 --- a/pkgs/python-packages/bencoderpyx/default.nix +++ /dev/null @@ -1,23 +0,0 @@ -{ lib, buildPythonPackage, fetchurl, cython, pytest, coverage }: - -buildPythonPackage rec { - pname = "bencoder.pyx"; - version = "3.0.1"; - format = "setuptools"; - - src = fetchurl { - url = "https://github.com/whtsky/bencoder.pyx/archive/9a47768f3ceba9df9e6fbaa7c445f59960889009.tar.gz"; - sha256 = "1yh565xjbbhn49xjfms80ac8psjbzn66n8dcx0x8mn7zzjv06clz"; - }; - - nativeBuildInputs = [ cython ]; - - checkInputs = [ pytest coverage ]; - - meta = with lib; { - description = "A fast bencode implementation in Cython"; - homepage = "https://github.com/whtsky/bencoder.pyx"; - maintainers = with maintainers; [ seberm nixbitcoin ]; - license = licenses.bsd3; - }; -} diff --git a/pkgs/python-packages/chromalog/default.nix b/pkgs/python-packages/chromalog/default.nix deleted file mode 100644 index 1522a42..0000000 --- a/pkgs/python-packages/chromalog/default.nix +++ /dev/null @@ -1,25 +0,0 @@ -{ lib, buildPythonPackage, fetchFromGitHub, colorama, future, six }: -buildPythonPackage rec { - pname = "chromalog"; - version = "1.0.5"; - format = "setuptools"; - - src = fetchFromGitHub { - owner = "freelan-developers"; - repo = "chromalog"; - rev = version; - sha256 = "0pj4s52rgwlvwkzrj85y92c5r9c84pz8gga45jl5spysrv41y9p0"; - }; - - propagatedBuildInputs = [ colorama future six ]; - - # enable when https://github.com/freelan-developers/chromalog/issues/6 is resolved - doCheck = false; - - meta = with lib; { - description = "Enhance Python with colored logging"; - homepage = "https://github.com/freelan-developers/chromalog"; - maintainers = with maintainers; [ seberm nixbitcoin ]; - license = licenses.mit; - }; -} diff --git a/pkgs/python-packages/default.nix b/pkgs/python-packages/default.nix deleted file mode 100644 index e254bea..0000000 --- a/pkgs/python-packages/default.nix +++ /dev/null @@ -1,73 +0,0 @@ -nbPkgs: python3: -rec { - pyPkgsOverrides = self: super: let - inherit (self) callPackage; - clightningPkg = pkg: callPackage pkg { inherit (nbPkgs.pinned) clightning; }; - in - { - txzmq = callPackage ./txzmq {}; - pyln-client = clightningPkg ./pyln-client; - pyln-proto = clightningPkg ./pyln-proto; - pyln-bolt7 = clightningPkg ./pyln-bolt7; - pylightning = clightningPkg ./pylightning; - # TODO: Remove after 2026-05-09 - clnrest = throw "`nbPython3Packages.clnrest` has been replaced with nix-bitcoin pkg `clnrest` (Rust rewrite)"; - - # Packages only used by joinmarket - bencoderpyx = callPackage ./bencoderpyx {}; - chromalog = callPackage ./chromalog {}; - python-bitcointx = callPackage ./python-bitcointx { inherit (self.pkgs) secp256k1; }; - runes = callPackage ./runes {}; - sha256 = callPackage ./sha256 {}; - - joinmarket = callPackage ./joinmarket { inherit (nbPkgs.joinmarket) version src; }; - }; - - nbPython3Packages = (python3.override { - packageOverrides = pyPkgsOverrides; - }).pkgs; - - # joinmarket requires cython 3.0 via pkg bencoder.pyx. - # The python pkgs from nixpkgs-25.11 default to cython 3.1. - # Downgrading to 3.0 causes mass rebuilds, so we use python pkgs from nixpkgs-25.05 for joinmarket. - # The nixpkgs-25.05 dependency will be removed with the next joinmarket update. - # https://github.com/JoinMarket-Org/joinmarket-clientserver/issues/1787 - nbPython3PackagesJoinmarket = - (nbPkgs.pinned.pkgs-25_05.python3.override { - packageOverrides = self: super: - (pyPkgsOverrides self super) // { - ## Specific versions of packages that already exist in nixpkgs - - # autobahn 20.12.3, required by joinmarketclient - autobahn = self.callPackage ./specific-versions/autobahn.nix {}; - }; - }).pkgs; - - # Re-enable pkgs `hwi`, `trezor` that are unaffected by `CVE-2024-23342` because - # they don't use python pkg `ecdsa` for signing. - # These packages no longer evaluate in nixpkgs after `ecdsa` was tagged with this CVE. - nbPython3PackagesWithUnlockedEcdsa = let - python3PackagesWithUnlockedEcdsa = (python3.override { - packageOverrides = self: super: { - ecdsa = super.ecdsa.overrideAttrs (old: { - meta = old.meta // { - knownVulnerabilities = builtins.filter (x: x != "CVE-2024-23342") old.meta.knownVulnerabilities; - }; - }); - }; - }).pkgs; - in { - hwi = with python3PackagesWithUnlockedEcdsa; toPythonApplication hwi; - - # nixpkgs has keyring 25.6.0, but trezor 0.20.0 requires >= 25.7.0. - # 25.7.0 only adds KWallet 6 support and removes Python 3.8 cruft, - # so 25.6.0 is functionally equivalent for trezor's use. - # Relax the constraint until nixpkgs updates keyring. - trezor = python3PackagesWithUnlockedEcdsa.trezor.overridePythonAttrs (old: { - nativeBuildInputs = (old.nativeBuildInputs or []) ++ [ - python3PackagesWithUnlockedEcdsa.pythonRelaxDepsHook - ]; - pythonRelaxDeps = [ "keyring" ]; - }); - }; -} diff --git a/pkgs/python-packages/joinmarket/default.nix b/pkgs/python-packages/joinmarket/default.nix deleted file mode 100644 index 1a318fd..0000000 --- a/pkgs/python-packages/joinmarket/default.nix +++ /dev/null @@ -1,113 +0,0 @@ -{ version -, src -, lib -, buildPythonPackage -, pythonOlder -, pythonAtLeast -, pytestCheckHook -, setuptools -, fetchurl -, chromalog -, cryptography -, service-identity -, twisted -, txtorcon -, python-bitcointx -, argon2-cffi -, autobahn -, bencoderpyx -, klein -, mnemonic -, pyjwt -, werkzeug -, libnacl -, pyopenssl -}: - -buildPythonPackage rec { - pname = "joinmarket"; - inherit version src; - format = "pyproject"; - - # Since v0.9.11, Python older than v3.8 is not supported. - disabled = pythonOlder "3.8"; - - nativeBuildInputs = [ - setuptools - ]; - - propagatedBuildInputs = [ - # base jm packages - chromalog - cryptography - service-identity - twisted - txtorcon - - # jmbitcoin - python-bitcointx - - # jmclient - argon2-cffi - autobahn - bencoderpyx - klein - mnemonic - pyjwt - werkzeug - - # jmdaemon - libnacl - pyopenssl - ]; - - # TODO-EXTERNAL: - # Remove this when fixed upstream. - # - # Fix the following error during checkPhase: - # File "/nix/store/...-python3.11-pytest-8.1.1/lib/python3.11/site-packages/_pytest/config/argparsing.py", line 133, in _getparser - # arggroup.add_argument(*n, **a) - # File "/nix/store/...-python3-3.11.9/lib/python3.11/argparse.py", line 1460, in add_argument - # raise ValueError('%r is not callable' % (type_func,)) - # ValueError: 'int' is not callable - patches = [ ./fix-conftest-arg-type-error.patch ]; - - postPatch = '' - substituteInPlace pyproject.toml \ - --replace-fail 'twisted==23.10.0' 'twisted==24.11.0' \ - --replace-fail 'service-identity==21.1.0' 'service-identity==24.2.0' \ - --replace-fail 'cryptography==41.0.6' 'cryptography==44.0.2' \ - --replace-fail 'txtorcon==23.11.0' 'txtorcon==24.8.0' \ - - # Modify pyproject.toml to include only specific modules. Do not include 'jmqtui'. - sed -i '/^\[tool.setuptools.packages.find\]/a include = ["jmbase", "jmbitcoin", "jmclient", "jmdaemon"]' pyproject.toml - ''; - - nativeCheckInputs = [ - pytestCheckHook - ]; - - pytestFlagsArray = [ - "test/jmbase/" - "test/jmbitcoin/" - "test/jmdaemon/test_enc_wrapper.py" - - # Other tests require preconfigured bitcoind and miniircd - # https://github.com/JoinMarket-Org/joinmarket-clientserver/blob/master/docs/TESTING.md - # "test/jmclient/" - # "test/jmdaemon/" - ]; - - pythonImportsCheck = [ - "jmbase" - "jmbitcoin" - "jmclient" - "jmdaemon" - ]; - - meta = with lib; { - homepage = "https://github.com/Joinmarket-Org/joinmarket-clientserver"; - maintainers = with maintainers; [ seberm nixbitcoin ]; - license = licenses.gpl3; - }; -} diff --git a/pkgs/python-packages/joinmarket/fix-conftest-arg-type-error.patch b/pkgs/python-packages/joinmarket/fix-conftest-arg-type-error.patch deleted file mode 100644 index a8f2743..0000000 --- a/pkgs/python-packages/joinmarket/fix-conftest-arg-type-error.patch +++ /dev/null @@ -1,17 +0,0 @@ -diff --git a/conftest.py b/conftest.py -index 1cc56d5..54b0a4c 100644 ---- a/conftest.py -+++ b/conftest.py -@@ -74,12 +74,6 @@ def pytest_addoption(parser: Any) -> None: - action="store", - default='bitcoinrpc', - help="the RPC username for your test bitcoin instance (default=bitcoinrpc)") -- parser.addoption("--nirc", -- type="int", -- action="store", -- default=1, -- help="the number of local miniircd instances") -- - - @pytest.fixture(scope="session", autouse=True) - def setup_early_if_needed(request) -> None: diff --git a/pkgs/python-packages/pylightning/default.nix b/pkgs/python-packages/pylightning/default.nix deleted file mode 100644 index 2c4b59c..0000000 --- a/pkgs/python-packages/pylightning/default.nix +++ /dev/null @@ -1,13 +0,0 @@ -{ buildPythonPackage, clightning, pyln-client }: - -buildPythonPackage rec { - pname = "pylightning"; - version = "0.10.1"; # defined in ${src}/contrib/pyln-client/pyln/client/__init__.py - - inherit (clightning) src; - - propagatedBuildInputs = [ pyln-client ]; - - postUnpack = "sourceRoot=$sourceRoot/contrib/${pname}"; - -} diff --git a/pkgs/python-packages/pyln-bolt7/default.nix b/pkgs/python-packages/pyln-bolt7/default.nix deleted file mode 100644 index 90a508a..0000000 --- a/pkgs/python-packages/pyln-bolt7/default.nix +++ /dev/null @@ -1,19 +0,0 @@ -{ buildPythonPackage, hatchling, pytestCheckHook, clightning, pyln-proto }: - -buildPythonPackage rec { - pname = "pyln-bolt7"; - # The version is defined here: - # https://github.com/ElementsProject/lightning/blob/master/contrib/pyln-spec/bolt7/pyproject.toml - version = "1.0.4.246"; - format = "pyproject"; - - inherit (clightning) src; - - nativeBuildInputs = [ hatchling ]; - propagatedBuildInputs = [ pyln-proto ]; - checkInputs = [ pytestCheckHook ]; - - pythonNamespaces = [ "pyln" ]; - - postUnpack = "sourceRoot=$sourceRoot/contrib/pyln-spec/bolt7"; -} diff --git a/pkgs/python-packages/pyln-client/default.nix b/pkgs/python-packages/pyln-client/default.nix deleted file mode 100644 index 6cd9564..0000000 --- a/pkgs/python-packages/pyln-client/default.nix +++ /dev/null @@ -1,22 +0,0 @@ -{ buildPythonPackage, hatchling, pytestCheckHook, clightning, pyln-bolt7, pyln-proto }: - -buildPythonPackage rec { - pname = "pyln-client"; - version = clightning.version; - format = "pyproject"; - - inherit (clightning) src; - - nativeBuildInputs = [ hatchling ]; - - propagatedBuildInputs = [ - pyln-bolt7 - pyln-proto - ]; - - checkInputs = [ pytestCheckHook ]; - - pythonNamespaces = [ "pyln" ]; - - postUnpack = "sourceRoot=$sourceRoot/contrib/${pname}"; -} diff --git a/pkgs/python-packages/pyln-proto/default.nix b/pkgs/python-packages/pyln-proto/default.nix deleted file mode 100644 index b35b2e9..0000000 --- a/pkgs/python-packages/pyln-proto/default.nix +++ /dev/null @@ -1,39 +0,0 @@ -{ buildPythonPackage -, clightning -, hatchling -, pytestCheckHook -, bitstring -, cryptography -, coincurve -, base58 -, pysocks -}: - -buildPythonPackage rec { - pname = "pyln-proto"; - version = clightning.version; - format = "pyproject"; - - inherit (clightning) src; - - postPatch = '' - substituteInPlace pyproject.toml \ - --replace-fail 'coincurve==20.0.0' 'coincurve==21.0.0' - ''; - - nativeBuildInputs = [ hatchling ]; - - propagatedBuildInputs = [ - bitstring - cryptography - coincurve - base58 - pysocks - ]; - - checkInputs = [ pytestCheckHook ]; - - pythonNamespaces = [ "pyln" ]; - - postUnpack = "sourceRoot=$sourceRoot/contrib/pyln-proto"; -} diff --git a/pkgs/python-packages/python-bitcointx/default.nix b/pkgs/python-packages/python-bitcointx/default.nix deleted file mode 100644 index 8f407c0..0000000 --- a/pkgs/python-packages/python-bitcointx/default.nix +++ /dev/null @@ -1,32 +0,0 @@ -{ lib, buildPythonPackage, fetchFromGitHub, secp256k1 }: - -buildPythonPackage rec { - pname = "python-bitcointx"; - version = "1.1.5"; - format = "setuptools"; - - src = fetchFromGitHub { - owner = "Simplexum"; - repo = "python-bitcointx"; - rev = "python-bitcointx-v${version}"; - hash = "sha256-KXndYEsJ8JRTiGojrKXmAEeGDlHrNGs5MtYs9XYiqMo="; - }; - - patchPhase = '' - for path in core/secp256k1.py tests/test_load_secp256k1.py; do - substituteInPlace "bitcointx/$path" \ - --replace-fail "ctypes.util.find_library('secp256k1')" "'${secp256k1}/lib/libsecp256k1.so'" - done - ''; - - pythonImportCheck = [ - "bitcointx" - ]; - - meta = with lib; { - description = "Interface to Bitcoin transaction data structures"; - homepage = "https://github.com/Simplexum/python-bitcointx"; - maintainers = with maintainers; [ seberm nixbitcoin ]; - license = licenses.gpl3; - }; -} diff --git a/pkgs/python-packages/python-bitcointx/get-sha256.sh b/pkgs/python-packages/python-bitcointx/get-sha256.sh deleted file mode 100755 index a625280..0000000 --- a/pkgs/python-packages/python-bitcointx/get-sha256.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail -. "${BASH_SOURCE[0]%/*}/../../../helper/run-in-nix-env" "git gnupg jq" "$@" - -latest=$(curl -s "https://api.github.com/repos/Simplexum/python-bitcointx/tags" | jq -r '.[0].name') -echo "Latest release is $latest" - -tmpdir=$(mktemp -d /tmp/python-bitcointx-verify-gpg.XXX) -trap 'rm -rf $tmpdir' EXIT -repo=$tmpdir/repo -git clone --depth 1 --branch "$latest" -c advice.detachedHead=false https://github.com/Simplexum/python-bitcointx "$repo" - -# GPG verification -export GNUPGHOME=$tmpdir -echo "Fetching Dimitry Pethukov's Key" -gpg --keyserver hkps://keyserver.ubuntu.com --recv-keys B17A35BBA187395784E2A6B32301D26BDC15160D 2> /dev/null -echo -echo "Verifying commit" -git -C "$repo" checkout -q "tags/$latest" -git -C "$repo" verify-commit HEAD -rm -rf "$repo"/.git -hash=$(nix hash path "$repo") - -echo -echo "tag: $latest" -echo "hash: $hash" diff --git a/pkgs/python-packages/runes/default.nix b/pkgs/python-packages/runes/default.nix deleted file mode 100644 index 125c0bb..0000000 --- a/pkgs/python-packages/runes/default.nix +++ /dev/null @@ -1,22 +0,0 @@ -{ sha256, lib, buildPythonPackage, fetchFromGitHub }: - -buildPythonPackage { - pname = "runes"; - version = "0.4.0"; - - src = fetchFromGitHub { - repo = "runes"; - owner = "rustyrussell"; - rev = "7e3d7648db844ce2c78cc3e9e4f872f827252251"; - sha256 = "sha256-e0iGLV/57gCpqA7vrW6JMFM0R6iAq5oFwUpZoGySwfs="; - }; - - propagatedBuildInputs = [ sha256 ]; - - meta = with lib; { - description = "Runes for authentication (like macaroons only simpler)"; - homepage = "https://github.com/rustyrussell/runes"; - maintainers = with maintainers; [ jb55 ]; - license = licenses.mit; - }; -} diff --git a/pkgs/python-packages/sha256/default.nix b/pkgs/python-packages/sha256/default.nix deleted file mode 100644 index 50fd0c7..0000000 --- a/pkgs/python-packages/sha256/default.nix +++ /dev/null @@ -1,32 +0,0 @@ -{ lib, buildPythonPackage, fetchFromGitHub, cython }: - -buildPythonPackage rec { - pname = "sha256"; - version = builtins.substring 0 8 src.rev; - - # The version from pypi is old/broken - src = fetchFromGitHub { - repo = "sha256"; - owner = "cloudtools"; - rev = "e0645d118f7296dde45397a755261f78d421bdee"; - sha256 = "sha256-gEctMgF5qZiWelVHVCl3zazRNuaQ7lJP8ExI5xWEBVI="; - }; - - nativeBuildInputs = [ cython ]; - - doCheck = false; - - configurePhase = '' - python setup.py sdist - ''; - - meta = with lib; { - description = '' - SHA-256 implementation that allows for setting and getting the mid-state - information. - ''; - homepage = "https://github.com/cloudtools/sha256"; - maintainers = with maintainers; [ jb55 ]; - license = licenses.mit; - }; -} diff --git a/pkgs/python-packages/specific-versions/autobahn.nix b/pkgs/python-packages/specific-versions/autobahn.nix deleted file mode 100644 index e880605..0000000 --- a/pkgs/python-packages/specific-versions/autobahn.nix +++ /dev/null @@ -1,37 +0,0 @@ -# Like nixpkgs revision 8d668463b0883b2e21ba2e2635cd5f9bbc409b18 -# but without Python 2 support - -{ lib, buildPythonPackage, fetchPypi, - six, txaio, twisted, zope-interface, cffi, - mock, pytest, cryptography, pynacl -}: -buildPythonPackage rec { - pname = "autobahn"; - version = "20.12.3"; - format = "setuptools"; - - src = fetchPypi { - inherit pname version; - sha256 = "15b8zm7jalwisfwc08szxy3bh2bnn0hd41dbsnswi0lqwbh962j1"; - }; - - propagatedBuildInputs = [ six txaio twisted zope-interface cffi cryptography pynacl ]; - - checkInputs = [ mock pytest ]; - checkPhase = '' - runHook preCheck - USE_TWISTED=true py.test "$out" - runHook postCheck - ''; - - # Tests do no seem to be compatible yet with pytest 5.1 - # https://github.com/crossbario/autobahn-python/issues/1235 - doCheck = false; - - meta = with lib; { - description = "WebSocket and WAMP in Python for Twisted and asyncio."; - homepage = "https://crossbar.io/autobahn"; - license = licenses.mit; - maintainers = with maintainers; [ nand0p ]; - }; -} diff --git a/pkgs/python-packages/txzmq/default.nix b/pkgs/python-packages/txzmq/default.nix deleted file mode 100644 index 920e552..0000000 --- a/pkgs/python-packages/txzmq/default.nix +++ /dev/null @@ -1,30 +0,0 @@ -{ lib -, buildPythonPackage -, fetchPypi -, pyzmq -, setuptools -, twisted -}: - -buildPythonPackage rec { - pname = "txzmq"; - version = "0.8.2"; - format = "setuptools"; - - src = fetchPypi { - pname = "txZMQ"; - inherit version; - sha256 = "07a9a480e58d4d732eef9efd7e264f2348cbf27ee82b338ec818a8504006e1c0"; - }; - - propagatedBuildInputs = [ - pyzmq - twisted - ]; - - meta = with lib; { - description = "Twisted bindings for ZeroMQ"; - homepage = https://github.com/smira/txZMQ; - license = licenses.gpl2; - }; -} diff --git a/pkgs/rtl/default.nix b/pkgs/rtl/default.nix deleted file mode 100644 index 5fd009d..0000000 --- a/pkgs/rtl/default.nix +++ /dev/null @@ -1,65 +0,0 @@ -{ lib -, stdenvNoCC -, nodejs_22 -, nodejs-slim_22 -, fetchNodeModules -, fetchpatch -, fetchurl -, makeWrapper -}: -let self = stdenvNoCC.mkDerivation { - pname = "rtl"; - version = "0.15.8"; - - src = fetchurl { - url = "https://github.com/Ride-The-Lightning/RTL/archive/refs/tags/v${self.version}.tar.gz"; - hash = "sha256-8XdGyORxB2dkZRB/Yl7zh+Quqo4L/Y0VmC6Brbr/hqU="; - }; - - passthru = { - nodejs = nodejs_22; - nodejsRuntime = nodejs-slim_22; - - nodeModules = fetchNodeModules { - inherit (self) src nodejs; - # TODO-EXTERNAL: Remove `npmFlags` when no longer required - # See: https://github.com/Ride-The-Lightning/RTL/issues/1182 - npmFlags = "--legacy-peer-deps"; - hash = "sha256-oMqd6nLzS6iQ9w4z2yzpR2unA5qhOq5YdvfoS8IgYLY="; - }; - }; - - nativeBuildInputs = [ - makeWrapper - ]; - - phases = "unpackPhase patchPhase installPhase"; - - # `src` already contains the precompiled frontend and backend. - # Copy all files required for packaging, like in - # https://github.com/Ride-The-Lightning/RTL/blob/master/dockerfiles/Dockerfile - installPhase = '' - dest=$out/lib/node_modules/rtl - mkdir -p $dest - cp -r \ - rtl.js \ - package.json \ - frontend \ - backend \ - ${self.nodeModules}/lib/node_modules \ - $dest - - makeWrapper ${self.nodejsRuntime}/bin/node "$out/bin/rtl" \ - --add-flags "$dest/rtl.js" - - runHook postInstall - ''; - - 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 erikarvstedt ]; - platforms = platforms.unix; - }; -}; in self diff --git a/pkgs/rtl/generate.sh b/pkgs/rtl/generate.sh deleted file mode 100755 index 2ae8317..0000000 --- a/pkgs/rtl/generate.sh +++ /dev/null @@ -1,41 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail -. "${BASH_SOURCE[0]%/*}/../../helper/run-in-nix-env" "gnupg wget gnused" "$@" - -version="0.15.8" -repo=https://github.com/Ride-The-Lightning/RTL - -scriptDir=$(cd "${BASH_SOURCE[0]%/*}" && pwd) - -updateSrc() { - TMPDIR=$(mktemp -d /tmp/rtl.XXX) - trap 'rm -rf $TMPDIR' EXIT - - # 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") - - sed -i " - s|\bversion = .*;|version = \"$version\";| - s|\bhash = .*;|hash = \"$hash\";| - " default.nix -} - -updateNodeModulesHash() { - "$scriptDir/../../helper/update-fixed-output-derivation.sh" ./default.nix rtl.nodeModules nodeModules -} - -if [[ $# == 0 ]]; then - # Each of these can be run separately - updateSrc - updateNodeModulesHash -else - "$@" -fi diff --git a/pkgs/trustedcoin/default.nix b/pkgs/trustedcoin/default.nix deleted file mode 100644 index 13017a4..0000000 --- a/pkgs/trustedcoin/default.nix +++ /dev/null @@ -1,28 +0,0 @@ -{ lib, buildGoModule, fetchFromGitHub }: - -buildGoModule rec { - pname = "trustedcoin"; - version = "0.8.6"; - - src = fetchFromGitHub { - owner = "nbd-wtf"; - repo = pname; - rev = "v${version}"; - hash = "sha256-b+Icq/9qMF+Zvh7RuG9RxU8/U07Tl8ymZvNKWsZzatw="; - }; - - vendorHash = "sha256-fW+EoNPC0mH8C06Q6GXNwFdzE7oQT+qd+B7hGGml+hc="; - - subPackages = [ "." ]; - - preCheck = '' - ln -s $TMP/go/bin/trustedcoin . - ''; - - meta = with lib; { - description = "Light bitcoin node implementation"; - homepage = "https://github.com/nbd-wtf/trustedcoin"; - maintainers = with maintainers; [ seberm fort-nix ]; - platforms = platforms.linux; - }; -} diff --git a/pkgs/trustedcoin/get-sha256.sh b/pkgs/trustedcoin/get-sha256.sh deleted file mode 100755 index 212b671..0000000 --- a/pkgs/trustedcoin/get-sha256.sh +++ /dev/null @@ -1,20 +0,0 @@ -#! /usr/bin/env nix-shell -#! nix-shell -i bash -p git gnupg curl jq -set -euo pipefail - - -TMPDIR="$(mktemp -d -p /tmp)" -trap 'rm -rf $TMPDIR' EXIT -cd "$TMPDIR" - -echo "Fetching latest release" -repo='nbd-wtf/trustedcoin' -latest=$(curl --location --silent --show-error https://api.github.com/repos/${repo}/releases/latest | jq -r .tag_name) -echo "Latest release is $latest" -git clone --depth 1 --branch "$latest" "https://github.com/${repo}" 2>/dev/null -cd trustedcoin - -echo "tag: $latest" -git checkout -q "tags/$latest" -rm -rf .git -nix --extra-experimental-features nix-command hash path .