From b9a7a71873475deca779029f5377b117ad8cc57d Mon Sep 17 00:00:00 2001 From: nixbitcoin Date: Tue, 2 Jun 2020 13:12:04 +0000 Subject: [PATCH 1/6] example config: document enabling pruning --- examples/configuration.nix | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/examples/configuration.nix b/examples/configuration.nix index e050c45..d6b6709 100644 --- a/examples/configuration.nix +++ b/examples/configuration.nix @@ -23,7 +23,11 @@ ### BITCOIND # Bitcoind is enabled by default if nix-bitcoin is enabled # - # You can override default settings from secure-node.nix as follows + # Enable this option to set pruning to a specified MiB value. + # clightning is compatible with pruning. See + # https://github.com/ElementsProject/lightning/#pruning for more information. + # LND and electrs are not compatible with pruning. + # Note: You can override default settings from secure-node.nix as follows # services.bitcoind.prune = lib.mkForce 100000; # # You can add options that are not defined in modules/bitcoind.nix as follows From 0fd99c4cc0f3da94ba6d65671c23f7b32b27b740 Mon Sep 17 00:00:00 2001 From: nixbitcoin Date: Sun, 7 Jun 2020 11:40:25 +0000 Subject: [PATCH 2/6] bitcoind: simplify pruning Remove the possible null value for bitcoind.prune and set prune = 0 in bitcoind as a default. Remove prune = 0 in secure-node.nix and the mkForce in configuration.nix (bitcoind.prune = lib.mkForce ). --- examples/configuration.nix | 3 +-- modules/bitcoind.nix | 10 +++------- modules/presets/secure-node.nix | 1 - 3 files changed, 4 insertions(+), 10 deletions(-) diff --git a/examples/configuration.nix b/examples/configuration.nix index d6b6709..e556765 100644 --- a/examples/configuration.nix +++ b/examples/configuration.nix @@ -27,8 +27,7 @@ # clightning is compatible with pruning. See # https://github.com/ElementsProject/lightning/#pruning for more information. # LND and electrs are not compatible with pruning. - # Note: You can override default settings from secure-node.nix as follows - # services.bitcoind.prune = lib.mkForce 100000; + # services.bitcoind.prune = 100000; # # You can add options that are not defined in modules/bitcoind.nix as follows # services.bitcoind.extraConfig = '' diff --git a/modules/bitcoind.nix b/modules/bitcoind.nix index 14d972b..653c52b 100644 --- a/modules/bitcoind.nix +++ b/modules/bitcoind.nix @@ -12,7 +12,7 @@ let ${optionalString cfg.testnet "testnet=1"} ${optionalString (cfg.dbCache != null) "dbcache=${toString cfg.dbCache}"} - ${optionalString (cfg.prune != null) "prune=${toString cfg.prune}"} + "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}"} @@ -179,12 +179,8 @@ in { 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; + type = types.ints.unsigned; + default = 0; example = 10000; description = '' Reduce storage requirements by enabling pruning (deleting) of old diff --git a/modules/presets/secure-node.nix b/modules/presets/secure-node.nix index f2a35a7..ca4ab6a 100644 --- a/modules/presets/secure-node.nix +++ b/modules/presets/secure-node.nix @@ -64,7 +64,6 @@ in { addnodes = [ "ecoc5q34tmbq54wl.onion" ]; discover = false; addresstype = "bech32"; - prune = 0; dbCache = 1000; }; services.tor.hiddenServices.bitcoind = mkHiddenService { port = cfg.bitcoind.port; }; From c16924b8506889c118b6a380d4a7024e5d5422f8 Mon Sep 17 00:00:00 2001 From: nixbitcoin Date: Tue, 2 Jun 2020 13:12:48 +0000 Subject: [PATCH 3/6] example config: change hwi excluding dependency to high-memory HWI can be enabled if electrs is enabled as long as electrs.high-memory is disabled. --- examples/configuration.nix | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/examples/configuration.nix b/examples/configuration.nix index e556765..4eb8e42 100644 --- a/examples/configuration.nix +++ b/examples/configuration.nix @@ -63,11 +63,10 @@ ### ELECTRS # Enable this module to use electrs, an efficient re-implementation of - # Electrum Server in Rust. Only enable this if hardware wallets are - # disabled. + # Electrum Server in Rust. # services.electrs.enable = true; # If you have more than 8GB memory, enable this option so electrs will - # sync faster. + # sync faster. Only available if hardware wallets are disabled. # services.electrs.high-memory = true; ### LIQUIDD @@ -110,7 +109,7 @@ ### Hardware wallets # Enable this module to allow using hardware wallets. See https://github.com/bitcoin-core/HWI - # for more information. Only enable this if electrs is disabled. + # for more information. Only available if electrs.high-memory is disabled. # Ledger must be initialized through the official ledger live app and the Bitcoin app must # be installed and running on the device. # services.hardware-wallets.ledger = true; From 0ad524ca2d4125909b40b0661a20f126ab85c056 Mon Sep 17 00:00:00 2001 From: nixbitcoin Date: Sun, 7 Jun 2020 11:19:31 +0000 Subject: [PATCH 4/6] example config: clarify nix-bitcoin will auto-detect invalid settings --- examples/configuration.nix | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/configuration.nix b/examples/configuration.nix index 4eb8e42..fa12f8c 100644 --- a/examples/configuration.nix +++ b/examples/configuration.nix @@ -58,7 +58,7 @@ ### SPARK WALLET # Enable this module to use spark-wallet, a minimalistic wallet GUI for # c-lightning, accessible over the web or through mobile and desktop apps. - # Only enable this if clightning is enabled. + # Only available if clightning is enabled. # services.spark-wallet.enable = true; ### ELECTRS @@ -78,25 +78,25 @@ ### LIGHTNING CHARGE # Enable this module to use lightning-charge, a simple drop-in solution for - # accepting lightning payments. Only enable this if clightning is enabled. + # accepting lightning payments. Only available if clightning is enabled. # services.lightning-charge.enable = true; ### NANOPOS # Enable this module to use nanopos, a simple Lightning point-of-sale - # system, powered by Lightning Charge. Only enable this if clightning and + # system, powered by Lightning Charge. Only available if clightning and # lightning-charge are enabled. # services.nanopos.enable = true; ### WEBINDEX # Enable this module to use the nix-bitcoin-webindex, a simple website - # displaying your node information and link to nanopos store. Only enable - # this if clightning, lightning-charge, and nanopos are enabled. + # displaying your node information and link to nanopos store. Only available + # if clightning, lightning-charge, and nanopos are enabled. # services.nix-bitcoin-webindex.enable = true; ### RECURRING-DONATIONS # Enable this module to send recurring donations. This is EXPERIMENTAL; it's # not guaranteed that payments are succeeding or that you will notice payment - # failure. Only enable this if clightning is enabled. + # failure. Only available if clightning is enabled. # services.recurring-donations.enable = true; # Specify the receivers of the donations. By default donations are every # Monday at a randomized time. Check `journalctl -eu recurring-donations` or From 23cd323ad12cabe4c3921234de480a2f94e50661 Mon Sep 17 00:00:00 2001 From: nixbitcoin Date: Mon, 15 Jun 2020 10:21:18 +0000 Subject: [PATCH 5/6] assertions: add lnd, clightning exclusivity --- examples/configuration.nix | 2 +- modules/modules.nix | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/examples/configuration.nix b/examples/configuration.nix index fa12f8c..7d4ff87 100644 --- a/examples/configuration.nix +++ b/examples/configuration.nix @@ -45,7 +45,7 @@ ### LND # Disable clightning and uncomment the following line in order to enable lnd, # a lightning implementation written in Go. - # services.lnd.enable = assert (!config.services.clightning.enable); true; + # services.lnd.enable = true; ## WARNING # If you use lnd, you should manually backup your wallet mnemonic # seed. This will allow you to recover on-chain funds. You can run the diff --git a/modules/modules.nix b/modules/modules.nix index faf12a7..93774c4 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -26,6 +26,15 @@ }; config = { + assertions = [ + # lnd.wantedBy == [] needed for `test/tests.nix` in which both clightning and lnd are enabled + { assertion = config.services.lnd.enable -> (!config.services.clightning.enable || config.systemd.services.lnd.wantedBy == []); + message = '' + LND and clightning can't be run in parallel because they both bind to lightning port 9735. + ''; + } + ]; + nixpkgs.overlays = [ (self: super: { nix-bitcoin = let pkgs = import ../pkgs { pkgs = super; }; From f280d54bb88e2d0e9603f9cc4214ff536c9944b8 Mon Sep 17 00:00:00 2001 From: nixbitcoin Date: Mon, 15 Jun 2020 10:34:11 +0000 Subject: [PATCH 6/6] add module assertions --- modules/electrs.nix | 6 ++++++ modules/hardware-wallets.nix | 9 +++++++++ modules/lightning-charge.nix | 6 ++++++ modules/lnd.nix | 6 ++++++ modules/nanopos.nix | 6 ++++++ modules/nix-bitcoin-webindex.nix | 6 ++++++ modules/recurring-donations.nix | 6 ++++++ modules/spark-wallet.nix | 6 ++++++ 8 files changed, 51 insertions(+) diff --git a/modules/electrs.nix b/modules/electrs.nix index bf81cd7..13b886a 100644 --- a/modules/electrs.nix +++ b/modules/electrs.nix @@ -61,6 +61,12 @@ in { }; config = mkIf cfg.enable (mkMerge [{ + assertions = [ + { assertion = config.services.bitcoind.prune == 0; + message = "electrs does not support bitcoind pruning."; + } + ]; + environment.systemPackages = [ pkgs.nix-bitcoin.electrs ]; systemd.tmpfiles.rules = [ diff --git a/modules/hardware-wallets.nix b/modules/hardware-wallets.nix index 8337e5c..4d53884 100644 --- a/modules/hardware-wallets.nix +++ b/modules/hardware-wallets.nix @@ -33,6 +33,15 @@ in { 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. + Note that this option is active when enabling electrs.high-memory. + ''; + } + ]; + environment.systemPackages = with pkgs; [ nix-bitcoin.hwi # Provides lsusb for debugging diff --git a/modules/lightning-charge.nix b/modules/lightning-charge.nix index d5d1d67..e2d4ce5 100644 --- a/modules/lightning-charge.nix +++ b/modules/lightning-charge.nix @@ -24,6 +24,12 @@ in { }; config = mkIf cfg.enable { + assertions = [ + { assertion = config.services.clightning.enable; + message = "lightning-charge requires clightning."; + } + ]; + users.users.lightning-charge = { description = "lightning-charge User"; group = "lightning-charge"; diff --git a/modules/lnd.nix b/modules/lnd.nix index 8f60a16..ef60dcb 100644 --- a/modules/lnd.nix +++ b/modules/lnd.nix @@ -83,6 +83,12 @@ in { }; config = mkIf cfg.enable { + assertions = [ + { assertion = config.services.bitcoind.prune == 0; + message = "lnd does not support bitcoind pruning."; + } + ]; + environment.systemPackages = [ cfg.package (hiPrio cfg.cli) ]; systemd.tmpfiles.rules = [ diff --git a/modules/nanopos.nix b/modules/nanopos.nix index 2f30446..91af50c 100644 --- a/modules/nanopos.nix +++ b/modules/nanopos.nix @@ -52,6 +52,12 @@ in { }; config = mkIf cfg.enable { + assertions = [ + { assertion = config.services.lightning-charge.enable; + message = "nanopos requires lightning-charge."; + } + ]; + environment.systemPackages = [ pkgs.nix-bitcoin.nanopos ]; systemd.services.nanopos = { description = "Run nanopos"; diff --git a/modules/nix-bitcoin-webindex.nix b/modules/nix-bitcoin-webindex.nix index a857ffb..39ba9b9 100644 --- a/modules/nix-bitcoin-webindex.nix +++ b/modules/nix-bitcoin-webindex.nix @@ -47,6 +47,12 @@ in { }; config = mkIf cfg.enable { + assertions = [ + { assertion = config.services.nanopos.enable; + message = "nix-bitcoin-webindex requires nanopos."; + } + ]; + systemd.tmpfiles.rules = [ "d /var/www 0755 nginx nginx - -" ]; diff --git a/modules/recurring-donations.nix b/modules/recurring-donations.nix index 659891a..901c8f7 100644 --- a/modules/recurring-donations.nix +++ b/modules/recurring-donations.nix @@ -78,6 +78,12 @@ in { }; config = mkIf cfg.enable { + assertions = [ + { assertion = config.services.clightning.enable; + message = "recurring-donations requires clightning."; + } + ]; + users.users.recurring-donations = { description = "recurring-donations User"; group = "recurring-donations"; diff --git a/modules/spark-wallet.nix b/modules/spark-wallet.nix index a329def..477bdfd 100644 --- a/modules/spark-wallet.nix +++ b/modules/spark-wallet.nix @@ -46,6 +46,12 @@ in { }; config = mkIf cfg.enable { + assertions = [ + { assertion = config.services.clightning.enable; + message = "spark-wallet requires clightning."; + } + ]; + environment.systemPackages = [ pkgs.nix-bitcoin.spark-wallet ]; users.users.spark-wallet = { description = "spark-wallet User";