From 4c55b8395c4c6e9878602c677d507b7fbda71a7e Mon Sep 17 00:00:00 2001 From: Jonas Nick Date: Mon, 3 Dec 2018 15:31:44 +0000 Subject: [PATCH] Add 'minimal' and 'all' profiles --- configuration.nix | 4 +++- modules/bitcoind.nix | 1 + modules/nixbitcoin.nix | 48 ++++++++++++++++++++++++++---------------- 3 files changed, 34 insertions(+), 19 deletions(-) diff --git a/configuration.nix b/configuration.nix index 95c4b77..bbe0621 100644 --- a/configuration.nix +++ b/configuration.nix @@ -16,7 +16,7 @@ in { ./modules/nixbitcoin.nix ]; - # turn off binary cache by setting binaryCaches to empty list + # Turn off binary cache by setting binaryCaches to empty list # nix.binaryCaches = []; networking.hostName = "nix-bitcoin"; # Define your hostname. @@ -35,6 +35,8 @@ in { services.openssh.enable = true; networking.firewall.enable = true; services.nixbitcoin.enable = true; + # Install and use minimal or all modules + services.nixbitcoin.modules = "all"; # This value determines the NixOS release with which your system is to be # compatible, in order to avoid breaking some software such as database diff --git a/modules/bitcoind.nix b/modules/bitcoind.nix index 234846e..414c33c 100644 --- a/modules/bitcoind.nix +++ b/modules/bitcoind.nix @@ -188,6 +188,7 @@ in { fi cp '${configFile}' '${cfg.dataDir}/bitcoin.conf' chmod o-rw '${cfg.dataDir}/bitcoin.conf' + chown '${cfg.user}:${cfg.group}' '${cfg.dataDir}/bitcoin.conf' echo "rpcpassword=$(cat /secrets/bitcoin-rpcpassword)" >> '${cfg.dataDir}/bitcoin.conf' ''; serviceConfig = { diff --git a/modules/nixbitcoin.nix b/modules/nixbitcoin.nix index 02fdfc7..6c87630 100644 --- a/modules/nixbitcoin.nix +++ b/modules/nixbitcoin.nix @@ -4,6 +4,18 @@ with lib; let cfg = config.services.nixbitcoin; + minimalPackages = with pkgs; [ + bitcoin + clightning + nodeinfo + jq + ]; + allPackages = with pkgs; [ + lightning-charge.package + nanopos.package + nodejs-8_x + nginx + ]; in { imports = [ @@ -24,22 +36,16 @@ in { If enabled, the nix-bitcoin service will be installed. ''; }; + modules = mkOption { + type = types.enum [ "minimal" "all" ]; + default = "minimal"; + description = '' + If enabled, the nix-bitcoin service will be installed. + ''; + }; }; config = mkIf cfg.enable { - environment.systemPackages = with pkgs; [ - vim tmux clightning bitcoin - nodeinfo - jq - lightning-charge.package - nanopos.package - nodejs-8_x - nginx - ]; - - # Add bitcoinrpc group - users.groups.bitcoinrpc = {}; - # Tor services.tor.enable = true; services.tor.client.enable = true; @@ -63,6 +69,9 @@ in { version = 3; }; + # Add bitcoinrpc group + users.groups.bitcoinrpc = {}; + # clightning services.clightning = { enable = true; @@ -75,11 +84,6 @@ in { version = 3; }; - - services.lightning-charge.enable = true; - services.nanopos.enable = true; - services.nixbitcoin-webindex.enable = true; - # Create user operator which can use bitcoin-cli and lightning-cli users.users.operator = { isNormalUser = true; @@ -107,6 +111,14 @@ in { type = "oneshot"; }; }; + # This is required to have the deployment keys copied and chowned even if + # nanopos is not enabled + users.users.nanopos = {}; + users.groups.nanopos = {}; + services.lightning-charge.enable = cfg.modules == "all"; + services.nanopos.enable = cfg.modules == "all"; + services.nixbitcoin-webindex.enable = cfg.modules == "all"; + environment.systemPackages = if (cfg.modules == "all") then (minimalPackages ++ allPackages) else minimalPackages; }; }