2018-12-01 19:36:07 +03:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.lightning-charge;
|
2019-11-27 16:04:23 +03:00
|
|
|
inherit (config) nix-bitcoin-services;
|
2018-12-01 19:36:07 +03:00
|
|
|
in {
|
|
|
|
options.services.lightning-charge = {
|
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
If enabled, the lightning-charge service will be installed.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
clightning-datadir = mkOption {
|
2019-10-15 10:37:32 +03:00
|
|
|
type = types.str;
|
2018-12-01 19:36:07 +03:00
|
|
|
default = "/var/lib/clighting/";
|
|
|
|
description = ''
|
|
|
|
Data directory of the clightning service
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2019-01-02 18:17:57 +03:00
|
|
|
systemd.services.lightning-charge = {
|
|
|
|
description = "Run lightning-charge";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
requires = [ "clightning.service" ];
|
|
|
|
after = [ "clightning.service" ];
|
|
|
|
serviceConfig = {
|
2020-01-12 22:52:39 +03:00
|
|
|
EnvironmentFile = "${config.nix-bitcoin.secretsDir}/lightning-charge-env";
|
2020-01-09 16:27:46 +03:00
|
|
|
ExecStart = "${pkgs.nix-bitcoin.lightning-charge}/bin/charged -l ${config.services.clightning.dataDir}/bitcoin -d ${config.services.clightning.dataDir}/lightning-charge.db";
|
2019-01-02 18:17:57 +03:00
|
|
|
# Unfortunately c-lightning doesn't allow setting the permissions of the rpc socket,
|
|
|
|
# so this must run as the clightning user
|
|
|
|
# https://github.com/ElementsProject/lightning/issues/1366
|
|
|
|
User = "clightning";
|
|
|
|
Restart = "on-failure";
|
|
|
|
RestartSec = "10s";
|
2019-04-28 02:53:26 +03:00
|
|
|
} // nix-bitcoin-services.defaultHardening
|
2019-05-03 13:44:16 +03:00
|
|
|
// nix-bitcoin-services.nodejs
|
2019-04-28 02:53:26 +03:00
|
|
|
// nix-bitcoin-services.allowTor;
|
2018-12-01 19:36:07 +03:00
|
|
|
};
|
2020-01-12 22:52:38 +03:00
|
|
|
nix-bitcoin.secrets.lightning-charge-env.user = "clightning";
|
2019-01-02 18:17:57 +03:00
|
|
|
};
|
2018-12-01 19:36:07 +03:00
|
|
|
}
|