From f0a36fe0c7415272db92f772733dc4d97b57cc58 Mon Sep 17 00:00:00 2001 From: Erik Arvstedt Date: Wed, 27 Nov 2019 14:04:23 +0100 Subject: [PATCH] add 'nix-bitcoin-services' option 1. Makes the content easily accessible for module users 2. Avoids needlessly recalculating the attrset in every client module --- modules/bitcoind.nix | 2 +- modules/clightning.nix | 2 +- modules/electrs.nix | 2 +- modules/lightning-charge.nix | 2 +- modules/liquid.nix | 2 +- modules/lnd.nix | 2 +- modules/modules.nix | 17 +++++++++++++---- modules/nanopos.nix | 2 +- modules/nix-bitcoin-services.nix | 2 +- modules/nix-bitcoin-webindex.nix | 2 +- modules/onion-chef.nix | 2 +- modules/recurring-donations.nix | 2 +- modules/spark-wallet.nix | 2 +- 13 files changed, 25 insertions(+), 16 deletions(-) diff --git a/modules/bitcoind.nix b/modules/bitcoind.nix index 55840c9..eab5b40 100644 --- a/modules/bitcoind.nix +++ b/modules/bitcoind.nix @@ -3,8 +3,8 @@ with lib; let - nix-bitcoin-services = pkgs.callPackage ./nix-bitcoin-services.nix { }; cfg = config.services.bitcoind; + inherit (config) nix-bitcoin-services; pidFile = "${cfg.dataDir}/bitcoind.pid"; configFile = pkgs.writeText "bitcoin.conf" '' ${optionalString cfg.testnet "testnet=1"} diff --git a/modules/clightning.nix b/modules/clightning.nix index 4e68d8b..07457b5 100644 --- a/modules/clightning.nix +++ b/modules/clightning.nix @@ -3,8 +3,8 @@ with lib; let - nix-bitcoin-services = pkgs.callPackage ./nix-bitcoin-services.nix { }; cfg = config.services.clightning; + inherit (config) nix-bitcoin-services; configFile = pkgs.writeText "config" '' autolisten=${if cfg.autolisten then "true" else "false"} network=bitcoin diff --git a/modules/electrs.nix b/modules/electrs.nix index 1ad1f09..fcb87db 100644 --- a/modules/electrs.nix +++ b/modules/electrs.nix @@ -3,8 +3,8 @@ with lib; let - nix-bitcoin-services = pkgs.callPackage ./nix-bitcoin-services.nix { }; cfg = config.services.electrs; + inherit (config) nix-bitcoin-services; index-batch-size = "${if cfg.high-memory then "" else "--index-batch-size=10"}"; jsonrpc-import = "${if cfg.high-memory then "" else "--jsonrpc-import"}"; in { diff --git a/modules/lightning-charge.nix b/modules/lightning-charge.nix index d22e7ac..e3eeafc 100644 --- a/modules/lightning-charge.nix +++ b/modules/lightning-charge.nix @@ -3,8 +3,8 @@ with lib; let - nix-bitcoin-services = pkgs.callPackage ./nix-bitcoin-services.nix { }; cfg = config.services.lightning-charge; + inherit (config) nix-bitcoin-services; in { options.services.lightning-charge = { enable = mkOption { diff --git a/modules/liquid.nix b/modules/liquid.nix index 0298413..042db0e 100644 --- a/modules/liquid.nix +++ b/modules/liquid.nix @@ -3,8 +3,8 @@ with lib; let - nix-bitcoin-services = pkgs.callPackage ./nix-bitcoin-services.nix { }; cfg = config.services.liquidd; + inherit (config) nix-bitcoin-services; pidFile = "${cfg.dataDir}/liquidd.pid"; configFile = pkgs.writeText "elements.conf" '' chain=liquidv1 diff --git a/modules/lnd.nix b/modules/lnd.nix index f7794de..b41c21e 100644 --- a/modules/lnd.nix +++ b/modules/lnd.nix @@ -3,8 +3,8 @@ with lib; let - nix-bitcoin-services = pkgs.callPackage ./nix-bitcoin-services.nix { }; cfg = config.services.lnd; + inherit (config) nix-bitcoin-services; configFile = pkgs.writeText "lnd.conf" '' datadir=${cfg.dataDir} logdir=${cfg.dataDir}/logs diff --git a/modules/modules.nix b/modules/modules.nix index 1955528..9509e5b 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -1,4 +1,4 @@ -{ config, pkgs, ... }: +{ config, pkgs, lib, ... }: let nixpkgs-pinned = import ../pkgs/nixpkgs-pinned.nix; unstable = import nixpkgs-pinned.nixpkgs-unstable {}; @@ -27,7 +27,16 @@ in { disabledModules = [ "services/networking/bitcoind.nix" ]; - nixpkgs.overlays = [ (self: super: { - nix-bitcoin = allPackages super; - }) ]; + options = { + nix-bitcoin-services = lib.mkOption { + readOnly = true; + default = import ./nix-bitcoin-services.nix lib; + }; + }; + + config = { + nixpkgs.overlays = [ (self: super: { + nix-bitcoin = allPackages super; + }) ]; + }; } diff --git a/modules/nanopos.nix b/modules/nanopos.nix index f21b1a0..cbfdc0c 100644 --- a/modules/nanopos.nix +++ b/modules/nanopos.nix @@ -3,8 +3,8 @@ with lib; let - nix-bitcoin-services = pkgs.callPackage ./nix-bitcoin-services.nix { }; cfg = config.services.nanopos; + inherit (config) nix-bitcoin-services; defaultItemsFile = pkgs.writeText "items.yaml" '' tea: price: 0.02 # denominated in the currency specified by --currency diff --git a/modules/nix-bitcoin-services.nix b/modules/nix-bitcoin-services.nix index e25311d..c04e14c 100644 --- a/modules/nix-bitcoin-services.nix +++ b/modules/nix-bitcoin-services.nix @@ -1,7 +1,7 @@ # See `man systemd.exec` and `man systemd.resource-control` for an explanation # of the various systemd options available through this module. -{ config, lib, pkgs, ... }: +lib: with lib; { diff --git a/modules/nix-bitcoin-webindex.nix b/modules/nix-bitcoin-webindex.nix index b69e1ff..1f2815b 100644 --- a/modules/nix-bitcoin-webindex.nix +++ b/modules/nix-bitcoin-webindex.nix @@ -3,8 +3,8 @@ with lib; let - nix-bitcoin-services = pkgs.callPackage ./nix-bitcoin-services.nix { }; cfg = config.services.nix-bitcoin-webindex; + inherit (config) nix-bitcoin-services; indexFile = pkgs.writeText "index.html" '' diff --git a/modules/onion-chef.nix b/modules/onion-chef.nix index c222015..0ec05c0 100644 --- a/modules/onion-chef.nix +++ b/modules/onion-chef.nix @@ -8,8 +8,8 @@ with lib; let - nix-bitcoin-services = pkgs.callPackage ./nix-bitcoin-services.nix { }; cfg = config.services.onion-chef; + inherit (config) nix-bitcoin-services; dataDir = "/var/lib/onion-chef/"; onion-chef-script = pkgs.writeScript "onion-chef.sh" '' # wait until tor is up diff --git a/modules/recurring-donations.nix b/modules/recurring-donations.nix index c258bff..f1ef5f9 100644 --- a/modules/recurring-donations.nix +++ b/modules/recurring-donations.nix @@ -3,8 +3,8 @@ with lib; let - nix-bitcoin-services = pkgs.callPackage ./nix-bitcoin-services.nix { }; cfg = config.services.recurring-donations; + inherit (config) nix-bitcoin-services; recurring-donations-script = pkgs.writeScript "recurring-donations.sh" '' LNCLI="lightning-cli --lightning-dir=${config.services.clightning.dataDir}" pay_tallycoin() { diff --git a/modules/spark-wallet.nix b/modules/spark-wallet.nix index 3de3249..7717404 100644 --- a/modules/spark-wallet.nix +++ b/modules/spark-wallet.nix @@ -3,8 +3,8 @@ with lib; let - nix-bitcoin-services = pkgs.callPackage ./nix-bitcoin-services.nix { }; cfg = config.services.spark-wallet; + inherit (config) nix-bitcoin-services; dataDir = "/var/lib/spark-wallet/"; onion-chef-service = (if cfg.onion-service then [ "onion-chef.service" ] else []); run-spark-wallet = pkgs.writeScript "run-spark-wallet" ''