nix-bitcoin/modules/clightning.nix

73 lines
2.0 KiB
Nix
Raw Normal View History

2018-11-22 10:49:53 -08:00
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.services.clightning;
home = "/var/lib/clightning";
configFile = pkgs.writeText "config" ''
autolisten=false
network=bitcoin
bitcoin-rpcuser=${cfg.bitcoin-rpcuser}
'';
in {
options.services.clightning = {
enable = mkOption {
type = types.bool;
default = false;
description = ''
If enabled, the clightning service will be installed.
'';
};
autolisten = mkOption {
type = types.bool;
default = false;
description = ''
If enabled, the clightning service will listen.
'';
};
bitcoin-rpcuser = mkOption {
type = types.string;
description = ''
Bitcoin RPC user
'';
};
};
config = mkIf cfg.enable {
users.users.clightning =
{
description = "clightning User";
createHome = true;
2018-11-28 14:58:36 -08:00
extraGroups = [ "bitcoinrpc" "keys" ];
2018-11-22 10:49:53 -08:00
inherit home;
};
systemd.services.clightning =
{ description = "Run clightningd";
2018-11-28 14:58:36 -08:00
path = [ pkgs.bash pkgs.clightning pkgs.bitcoin ];
2018-11-22 10:49:53 -08:00
wantedBy = [ "multi-user.target" ];
requires = [ "bitcoind.service" ];
after = [ "bitcoind.service" ];
2018-11-22 10:49:53 -08:00
preStart = ''
mkdir -p ${home}/.lightning
2018-11-28 14:58:36 -08:00
rm -f ${home}/.lightning/config
cp ${configFile} ${home}/.lightning/config
chmod +w ${home}/.lightning/config
echo "bitcoin-rpcpassword=$(cat /secrets/bitcoin-rpcpassword)" >> '${home}/.lightning/config'
2018-11-22 10:49:53 -08:00
'';
serviceConfig =
{
ExecStart = "${pkgs.clightning}/bin/lightningd";
User = "clightning";
Restart = "on-failure";
RestartSec = "10s";
2018-11-22 10:49:53 -08:00
PrivateTmp = "true";
ProtectSystem = "full";
NoNewPrivileges = "true";
PrivateDevices = "true";
MemoryDenyWriteExecute = "true";
};
};
};
}