nix-bitcoin/modules/nixbitcoin.nix

82 lines
2.3 KiB
Nix
Raw Normal View History

{ config, lib, pkgs, ... }:
with lib;
let
2018-11-20 14:21:45 -08:00
cfg = config.services.nixbitcoin;
2018-11-22 15:51:16 -08:00
secrets = import ../load-secrets.nix;
in {
2018-11-22 10:32:26 -08:00
imports =
[
./bitcoind.nix
./tor.nix
./clightning.nix
];
2018-11-20 14:21:45 -08:00
options.services.nixbitcoin = {
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.
'';
};
};
config = mkIf cfg.enable {
2018-11-22 10:32:26 -08:00
# Tor
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-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";
services.bitcoind.rpcpassword = secrets.bitcoinrpcpassword;
2018-11-22 10:32:26 -08:00
# clightning
services.clightning.enable = true;
2018-11-22 16:46:56 -08:00
services.clightning.bitcoin-rpcuser = config.services.bitcoind.rpcuser;
services.clightning.bitcoin-rpcpassword = config.services.bitcoind.rpcpassword;
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" ];
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 = {
ExecStart="${pkgs.bash}/bin/bash ${pkgs.nodeinfo}/bin/nodeinfo";
User = "root";
Type = "simple";
RemainAfterExit="yes";
Restart = "on-failure";
RestartSec = "10s";
};
};
# Define a user account. Don't forget to set a password with passwd.
users.users.guest = {
isNormalUser = true;
};
systemd.services.copy-root-authorized-keys = {
description = "Copy root authorized keys";
wantedBy = [ "multi-user.target" ];
path = [ ];
serviceConfig = {
ExecStart = "${pkgs.bash}/bin/bash -c \"mkdir -p ${config.users.users.guest.home}/.ssh && cp ${config.users.users.root.home}/.vbox-nixops-client-key ${config.users.users.guest.home}/.ssh/authorized_keys && chown -R guest ${config.users.users.guest.home}/.ssh\"";
2018-11-20 14:21:45 -08:00
user = "root";
type = "oneshot";
};
};
2018-11-19 16:22:16 -08:00
};
}