From 9d3588e1de8e3fd516859f3beb7be3b0b628793f Mon Sep 17 00:00:00 2001 From: Jonas Nick Date: Sun, 23 Feb 2020 19:22:07 +0000 Subject: [PATCH 1/3] Convert nix-bitcoin extraConfig options to regular options --- modules/bitcoind.nix | 33 +++++++++++++++++++++++++++++++++ modules/nix-bitcoin.nix | 11 ++++------- 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/modules/bitcoind.nix b/modules/bitcoind.nix index b2a6bf3..725e164 100644 --- a/modules/bitcoind.nix +++ b/modules/bitcoind.nix @@ -12,11 +12,16 @@ let ${optionalString (cfg.prune != null) "prune=${toString cfg.prune}"} ${optionalString (cfg.sysperms != null) "sysperms=${if cfg.sysperms then "1" else "0"}"} ${optionalString (cfg.disablewallet != null) "disablewallet=${if cfg.disablewallet then "1" else "0"}"} + ${optionalString (cfg.assumevalid != null) "assumevalid=${cfg.assumevalid}"} + # Connection options ${optionalString (cfg.port != null) "port=${toString cfg.port}"} ${optionalString (cfg.proxy != null) "proxy=${cfg.proxy}"} listen=${if cfg.listen then "1" else "0"} + ${optionalString (cfg.discover != null) "discover=${if cfg.discover then "1" else "0"}"} + ${optionalString (cfg.addnode != null) "addnode=${cfg.addnode}"} + # RPC server options rpcport=${toString cfg.rpc.port} @@ -27,6 +32,9 @@ let ${optionalString (cfg.rpcuser != null) "rpcuser=${cfg.rpcuser}"} ${optionalString (cfg.rpcpassword != null) "rpcpassword=${cfg.rpcpassword}"} + # Wallet options + ${optionalString (cfg.addresstype != null) "addresstype=${cfg.addresstype}"} + # ZMQ options ${optionalString (cfg.zmqpubrawblock != null) "zmqpubrawblock=${cfg.zmqpubrawblock}"} ${optionalString (cfg.zmqpubrawtx != null) "zmqpubrawtx=${cfg.zmqpubrawtx}"} @@ -209,6 +217,31 @@ in { example = "tcp://127.0.0.1:28333"; description = "ZMQ address for zmqpubrawtx notifications"; }; + assumevalid = mkOption { + type = types.nullOr types.str; + default = null; + example = "00000000000000000000e5abc3a74fe27dc0ead9c70ea1deb456f11c15fd7bc6"; + description = "If this block is in the chain assume that it and its ancestors are valid and potentially skip their script verification"; + }; + addnode = mkOption { + type = types.nullOr types.str; + default = null; + example = "ecoc5q34tmbq54wl.onion"; + description = "Add a node to connect to and attempt to keep the connection open"; + }; + discover = mkOption { + type = types.nullOr types.bool; + default = null; + description = '' + Discover own IP addresses + ''; + }; + addresstype = mkOption { + type = types.nullOr types.str; + default = null; + example = "bech32"; + description = "What type of addresses to use"; + }; cli = mkOption { type = types.package; readOnly = true; diff --git a/modules/nix-bitcoin.nix b/modules/nix-bitcoin.nix index 753e146..0239954 100644 --- a/modules/nix-bitcoin.nix +++ b/modules/nix-bitcoin.nix @@ -57,13 +57,10 @@ in { services.bitcoind.rpcuser = "bitcoinrpc"; services.bitcoind.zmqpubrawblock = "tcp://127.0.0.1:28332"; services.bitcoind.zmqpubrawtx = "tcp://127.0.0.1:28333"; - services.bitcoind.extraConfig = '' - assumevalid=00000000000000000000e5abc3a74fe27dc0ead9c70ea1deb456f11c15fd7bc6 - addnode=ecoc5q34tmbq54wl.onion - discover=0 - addresstype=bech32 - changetype=bech32 - ''; + services.bitcoind.assumevalid = "00000000000000000000e5abc3a74fe27dc0ead9c70ea1deb456f11c15fd7bc6"; + services.bitcoind.addnode = "ecoc5q34tmbq54wl.onion"; + services.bitcoind.discover = false; + services.bitcoind.addresstype = "bech32"; services.bitcoind.prune = 0; services.bitcoind.dbCache = 1000; services.tor.hiddenServices.bitcoind = { From ed6511c96e6a83e4f856fb6a7bd5bf21d8239aaa Mon Sep 17 00:00:00 2001 From: Jonas Nick Date: Sun, 23 Feb 2020 19:30:32 +0000 Subject: [PATCH 2/3] Document how to override attributes in configuration.nix --- configuration.nix | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/configuration.nix b/configuration.nix index 66451b6..8fe2714 100644 --- a/configuration.nix +++ b/configuration.nix @@ -2,7 +2,7 @@ # your system. Help is available in the configuration.nix(5) man page # and in the NixOS manual (accessible by running ‘nixos-help’). -{ config, pkgs, ... }: { +{ config, pkgs, lib, ... }: { imports = [ ./modules/nix-bitcoin.nix @@ -22,6 +22,17 @@ # you are doing. services.nix-bitcoin.enable = true; + ### BITCOIND + # Bitcoind is enabled by default if nix-bitcoin is enabled + # + # You can override default settings from nix-bitcoin.nix as follows + # services.bitcoind.prune = lib.mkForce 100000; + # + # You can add options that are not defined in modules/bitcoind.nix as follows + # services.bitcoind.extraConfig = '' + # maxorphantx=110 + # ''; + ### CLIGHTNING # Enable this module to use clightning, a Lightning Network implementation # in C. From 323b2a7f17da7f2717ecfecb3fe1cc8d75be11de Mon Sep 17 00:00:00 2001 From: Jonas Nick Date: Tue, 25 Feb 2020 22:00:27 +0000 Subject: [PATCH 3/3] Allow adding multiple nodes to bitcoind with the addnodes option and improve bitcoin module option descriptions --- modules/bitcoind.nix | 21 +++++++++++---------- modules/nix-bitcoin.nix | 2 +- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/modules/bitcoind.nix b/modules/bitcoind.nix index 725e164..e6c44fa 100644 --- a/modules/bitcoind.nix +++ b/modules/bitcoind.nix @@ -20,7 +20,7 @@ let ${optionalString (cfg.proxy != null) "proxy=${cfg.proxy}"} listen=${if cfg.listen then "1" else "0"} ${optionalString (cfg.discover != null) "discover=${if cfg.discover then "1" else "0"}"} - ${optionalString (cfg.addnode != null) "addnode=${cfg.addnode}"} + ${lib.concatMapStrings (node: "addnode=${node}\n") cfg.addnodes} # RPC server options @@ -221,20 +221,21 @@ in { type = types.nullOr types.str; default = null; example = "00000000000000000000e5abc3a74fe27dc0ead9c70ea1deb456f11c15fd7bc6"; - description = "If this block is in the chain assume that it and its ancestors are valid and potentially skip their script verification"; + description = '' + If this block is in the chain assume that it and its ancestors are + valid and potentially skip their script verification. + ''; }; - addnode = mkOption { - type = types.nullOr types.str; - default = null; - example = "ecoc5q34tmbq54wl.onion"; - description = "Add a node to connect to and attempt to keep the connection open"; + addnodes = mkOption { + type = types.listOf types.str; + default = []; + example = [ "ecoc5q34tmbq54wl.onion" ]; + description = "Add nodes to connect to and attempt to keep the connections open"; }; discover = mkOption { type = types.nullOr types.bool; default = null; - description = '' - Discover own IP addresses - ''; + description = "Discover own IP addresses"; }; addresstype = mkOption { type = types.nullOr types.str; diff --git a/modules/nix-bitcoin.nix b/modules/nix-bitcoin.nix index 0239954..7fec571 100644 --- a/modules/nix-bitcoin.nix +++ b/modules/nix-bitcoin.nix @@ -58,7 +58,7 @@ in { services.bitcoind.zmqpubrawblock = "tcp://127.0.0.1:28332"; services.bitcoind.zmqpubrawtx = "tcp://127.0.0.1:28333"; services.bitcoind.assumevalid = "00000000000000000000e5abc3a74fe27dc0ead9c70ea1deb456f11c15fd7bc6"; - services.bitcoind.addnode = "ecoc5q34tmbq54wl.onion"; + services.bitcoind.addnodes = [ "ecoc5q34tmbq54wl.onion" ]; services.bitcoind.discover = false; services.bitcoind.addresstype = "bech32"; services.bitcoind.prune = 0;