2018-11-19 15:09:57 -08:00
|
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
|
|
let
|
2018-11-20 14:21:45 -08:00
|
|
|
|
cfg = config.services.nixbitcoin;
|
2018-11-19 15:09:57 -08:00
|
|
|
|
in {
|
2018-11-22 10:32:26 -08:00
|
|
|
|
imports =
|
|
|
|
|
[
|
|
|
|
|
./tor.nix
|
2018-12-01 08:36:07 -08:00
|
|
|
|
./bitcoind.nix
|
2018-11-22 10:32:26 -08:00
|
|
|
|
./clightning.nix
|
2018-12-01 08:36:07 -08:00
|
|
|
|
./lightning-charge.nix
|
2018-12-01 12:48:58 -08:00
|
|
|
|
./nanopos.nix
|
2018-12-01 13:38:08 -08:00
|
|
|
|
./nixbitcoin-webindex.nix
|
2018-11-22 10:32:26 -08:00
|
|
|
|
];
|
|
|
|
|
|
2018-11-20 14:21:45 -08:00
|
|
|
|
options.services.nixbitcoin = {
|
2018-11-19 15:09:57 -08:00
|
|
|
|
enable = mkOption {
|
|
|
|
|
type = types.bool;
|
|
|
|
|
default = false;
|
|
|
|
|
description = ''
|
2018-11-20 14:21:45 -08:00
|
|
|
|
If enabled, the nix-bitcoin service will be installed.
|
2018-11-19 15:09:57 -08:00
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2018-11-28 15:54:19 -08:00
|
|
|
|
# Add bitcoinrpc group
|
2018-11-28 14:58:36 -08:00
|
|
|
|
users.groups.bitcoinrpc = {};
|
|
|
|
|
|
2018-11-22 10:32:26 -08:00
|
|
|
|
# Tor
|
2018-11-19 15:09:57 -08:00
|
|
|
|
services.tor.enable = true;
|
|
|
|
|
services.tor.client.enable = true;
|
2018-11-19 16:22:16 -08:00
|
|
|
|
services.tor.hiddenServices.bitcoind = {
|
|
|
|
|
map = [{
|
2018-11-22 16:46:56 -08:00
|
|
|
|
port = config.services.bitcoind.port;
|
2018-11-19 16:22:16 -08:00
|
|
|
|
}];
|
|
|
|
|
version = 3;
|
2018-11-19 15:09:57 -08:00
|
|
|
|
};
|
2018-11-22 10:32:26 -08:00
|
|
|
|
|
2018-11-22 16:46:56 -08:00
|
|
|
|
# bitcoind
|
|
|
|
|
services.bitcoind.enable = true;
|
|
|
|
|
services.bitcoind.listen = true;
|
|
|
|
|
services.bitcoind.proxy = config.services.tor.client.socksListenAddress;
|
|
|
|
|
services.bitcoind.port = 8333;
|
|
|
|
|
services.bitcoind.rpcuser = "bitcoinrpc";
|
2018-11-23 12:37:50 -08:00
|
|
|
|
services.bitcoind.extraConfig = ''
|
|
|
|
|
assumevalid=0000000000000000000726d186d6298b5054b9a5c49639752294b322a305d240
|
|
|
|
|
addnode=ecoc5q34tmbq54wl.onion
|
|
|
|
|
discover=0
|
|
|
|
|
'';
|
|
|
|
|
services.bitcoind.prune = 2000;
|
2018-11-22 10:32:26 -08:00
|
|
|
|
|
|
|
|
|
# clightning
|
2018-12-01 12:48:58 -08:00
|
|
|
|
services.clightning = {
|
|
|
|
|
enable = true;
|
|
|
|
|
bitcoin-rpcuser = config.services.bitcoind.rpcuser;
|
|
|
|
|
};
|
|
|
|
|
services.tor.hiddenServices.clightning = {
|
|
|
|
|
map = [{
|
|
|
|
|
port = 9375; toPort = 9375;
|
|
|
|
|
}];
|
|
|
|
|
version = 3;
|
|
|
|
|
};
|
|
|
|
|
|
2018-11-22 10:32:26 -08:00
|
|
|
|
|
2018-12-01 08:36:07 -08:00
|
|
|
|
services.lightning-charge.enable = true;
|
2018-12-01 12:48:58 -08:00
|
|
|
|
services.nanopos.enable = true;
|
2018-12-01 13:38:08 -08:00
|
|
|
|
services.nixbitcoin-webindex.enable = true;
|
2018-12-01 08:36:07 -08:00
|
|
|
|
|
2018-11-22 10:32:26 -08:00
|
|
|
|
# nodeinfo
|
2018-11-20 14:21:45 -08:00
|
|
|
|
systemd.services.nodeinfo = {
|
|
|
|
|
description = "Get node info";
|
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
2018-11-23 07:49:13 -08:00
|
|
|
|
after = [ "clightning.service" "tor.service" ];
|
2018-11-22 10:32:26 -08:00
|
|
|
|
path = [ pkgs.clightning pkgs.jq pkgs.sudo ];
|
2018-11-20 14:21:45 -08:00
|
|
|
|
serviceConfig = {
|
2018-12-01 12:48:58 -08:00
|
|
|
|
ExecStart="${pkgs.bash}/bin/bash ${pkgs.nodeinfo}/bin/nodeinfo > /var/lib/nodeinfo.sh";
|
2018-11-23 07:49:13 -08:00
|
|
|
|
User = "root";
|
|
|
|
|
Type = "simple";
|
|
|
|
|
RemainAfterExit="yes";
|
|
|
|
|
Restart = "on-failure";
|
|
|
|
|
RestartSec = "10s";
|
|
|
|
|
};
|
|
|
|
|
};
|
2018-11-23 12:37:50 -08:00
|
|
|
|
|
2018-11-23 07:49:13 -08:00
|
|
|
|
# Define a user account. Don't forget to set a password with ‘passwd’.
|
2018-11-28 15:54:19 -08:00
|
|
|
|
users.users.operator = {
|
2018-11-23 07:49:13 -08:00
|
|
|
|
isNormalUser = true;
|
2018-11-28 15:54:19 -08:00
|
|
|
|
extraGroups = [ "clightning" config.services.bitcoind.group ];
|
|
|
|
|
|
2018-11-23 07:49:13 -08:00
|
|
|
|
};
|
2018-11-28 15:54:19 -08:00
|
|
|
|
environment.interactiveShellInit = ''
|
|
|
|
|
alias bitcoin-cli='bitcoin-cli -datadir=${config.services.bitcoind.dataDir}'
|
|
|
|
|
alias lightning-cli='sudo -u clightning lightning-cli --lightning-dir=${config.services.clightning.dataDir}'
|
|
|
|
|
'';
|
|
|
|
|
# Unfortunately c-lightning doesn't allow setting the permissions of the rpc socket
|
|
|
|
|
# https://github.com/ElementsProject/lightning/issues/1366
|
|
|
|
|
security.sudo.configFile = ''
|
|
|
|
|
operator ALL=(clightning) NOPASSWD: ALL
|
|
|
|
|
'';
|
|
|
|
|
|
|
|
|
|
# Give root ssh access to the operator account
|
2018-11-23 07:49:13 -08:00
|
|
|
|
systemd.services.copy-root-authorized-keys = {
|
|
|
|
|
description = "Copy root authorized keys";
|
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
|
path = [ ];
|
|
|
|
|
serviceConfig = {
|
2018-11-28 15:54:19 -08:00
|
|
|
|
ExecStart = "${pkgs.bash}/bin/bash -c \"mkdir -p ${config.users.users.operator.home}/.ssh && cp ${config.users.users.root.home}/.vbox-nixops-client-key ${config.users.users.operator.home}/.ssh/authorized_keys && chown -R operator ${config.users.users.operator.home}/.ssh\"";
|
2018-11-20 14:21:45 -08:00
|
|
|
|
user = "root";
|
|
|
|
|
type = "oneshot";
|
|
|
|
|
};
|
|
|
|
|
};
|
2018-11-23 07:49:13 -08:00
|
|
|
|
|
2018-11-19 16:22:16 -08:00
|
|
|
|
};
|
2018-11-19 15:09:57 -08:00
|
|
|
|
}
|