2018-12-01 16:36:07 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.lightning-charge;
|
2019-11-27 13:04:23 +00:00
|
|
|
inherit (config) nix-bitcoin-services;
|
2020-05-18 14:32:17 +00:00
|
|
|
user = config.users.users.lightning-charge.name;
|
|
|
|
group = config.users.users.lightning-charge.group;
|
2018-12-01 16:36:07 +00:00
|
|
|
in {
|
|
|
|
options.services.lightning-charge = {
|
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
If enabled, the lightning-charge service will be installed.
|
|
|
|
'';
|
|
|
|
};
|
2020-05-18 14:32:17 +00:00
|
|
|
dataDir = mkOption {
|
|
|
|
type = types.path;
|
|
|
|
default = "/var/lib/lightning-charge";
|
|
|
|
description = "The data directory for lightning-charge.";
|
2018-12-01 16:36:07 +00:00
|
|
|
};
|
2020-06-10 14:43:03 +00:00
|
|
|
host = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "127.0.0.1";
|
|
|
|
description = "http server listen address";
|
|
|
|
};
|
|
|
|
extraArgs = mkOption {
|
|
|
|
type = types.separatedString " ";
|
|
|
|
default = "";
|
|
|
|
description = "Extra command line arguments passed to lightning-charge.";
|
|
|
|
};
|
|
|
|
enforceTor = nix-bitcoin-services.enforceTor;
|
2018-12-01 16:36:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2020-09-22 14:05:51 +00:00
|
|
|
warnings = [''
|
|
|
|
The lightning-charge module is deprecated and will be removed soon.
|
|
|
|
''];
|
2020-06-15 10:34:11 +00:00
|
|
|
assertions = [
|
|
|
|
{ assertion = config.services.clightning.enable;
|
|
|
|
message = "lightning-charge requires clightning.";
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2020-05-18 14:32:17 +00:00
|
|
|
users.users.lightning-charge = {
|
|
|
|
description = "lightning-charge User";
|
|
|
|
group = "lightning-charge";
|
|
|
|
extraGroups = [ "clightning" ];
|
|
|
|
};
|
|
|
|
users.groups.lightning-charge = {};
|
|
|
|
|
|
|
|
systemd.tmpfiles.rules = [
|
|
|
|
"d '${cfg.dataDir}' 0700 ${user} ${group} - -"
|
|
|
|
];
|
|
|
|
|
2020-04-07 20:47:45 +00:00
|
|
|
environment.systemPackages = [ pkgs.nix-bitcoin.lightning-charge ];
|
2019-01-02 15:17:57 +00:00
|
|
|
systemd.services.lightning-charge = {
|
|
|
|
description = "Run lightning-charge";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
requires = [ "clightning.service" ];
|
|
|
|
after = [ "clightning.service" ];
|
2020-05-18 14:32:17 +00:00
|
|
|
preStart = ''
|
|
|
|
# Move existing lightning-charge.db
|
|
|
|
# TODO: Remove eventually
|
|
|
|
if [[ -e ${config.services.clightning.dataDir}/lightning-charge.db ]]; then
|
|
|
|
mv ${config.services.clightning.dataDir}/lightning-charge.db ${cfg.dataDir}/lightning-charge.db
|
|
|
|
chown ${user}: ${cfg.dataDir}/lightning-charge.db
|
|
|
|
chmod 600 ${cfg.dataDir}/lightning-charge.db
|
|
|
|
fi
|
|
|
|
'';
|
2020-05-05 13:18:41 +00:00
|
|
|
serviceConfig = nix-bitcoin-services.defaultHardening // {
|
2020-05-21 16:05:31 +00:00
|
|
|
# Needed to access clightning.dataDir in preStart
|
2020-05-18 14:32:17 +00:00
|
|
|
PermissionsStartOnly = "true";
|
2020-01-12 19:52:39 +00:00
|
|
|
EnvironmentFile = "${config.nix-bitcoin.secretsDir}/lightning-charge-env";
|
2020-06-10 14:43:03 +00:00
|
|
|
ExecStart = "${pkgs.nix-bitcoin.lightning-charge}/bin/charged -l ${config.services.clightning.dataDir}/bitcoin -d ${cfg.dataDir}/lightning-charge.db -i ${cfg.host} ${cfg.extraArgs}";
|
2020-05-18 14:32:17 +00:00
|
|
|
User = user;
|
2019-01-02 15:17:57 +00:00
|
|
|
Restart = "on-failure";
|
|
|
|
RestartSec = "10s";
|
2020-05-05 15:15:16 +00:00
|
|
|
ReadWritePaths = "${cfg.dataDir}";
|
2020-06-10 14:43:03 +00:00
|
|
|
} // (if cfg.enforceTor
|
|
|
|
then nix-bitcoin-services.allowTor
|
|
|
|
else nix-bitcoin-services.allowAnyIP)
|
|
|
|
// nix-bitcoin-services.nodejs;
|
2018-12-01 16:36:07 +00:00
|
|
|
};
|
2020-05-18 14:32:17 +00:00
|
|
|
nix-bitcoin.secrets.lightning-charge-env.user = user;
|
2019-01-02 15:17:57 +00:00
|
|
|
};
|
2018-12-01 16:36:07 +00:00
|
|
|
}
|