From 827a1274d625ca604f2d0d7997e73fa31e18ecff Mon Sep 17 00:00:00 2001 From: William Casarin Date: Sat, 17 Nov 2018 14:24:23 -0800 Subject: [PATCH] nixos/clightning: init module Signed-off-by: William Casarin --- nixos/modules/module-list.nix | 1 + .../services/networking/clightning.nix | 108 ++++++++++++++++++ 2 files changed, 109 insertions(+) create mode 100644 nixos/modules/services/networking/clightning.nix diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix index 0f8a7ba7904..63132d4ed15 100644 --- a/nixos/modules/module-list.nix +++ b/nixos/modules/module-list.nix @@ -617,6 +617,7 @@ ./services/networking/bitlbee.nix ./services/networking/blockbook-frontend.nix ./services/networking/charybdis.nix + ./services/networking/clightning.nix ./services/networking/cjdns.nix ./services/networking/cntlm.nix ./services/networking/connman.nix diff --git a/nixos/modules/services/networking/clightning.nix b/nixos/modules/services/networking/clightning.nix new file mode 100644 index 00000000000..29d73bbeabb --- /dev/null +++ b/nixos/modules/services/networking/clightning.nix @@ -0,0 +1,108 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + cfg = config.services.clightning; + + mkLightningNode = cfg: network: + let + configFile = pkgs.writeText "clightning-${network}.conf" cfg.config; + in + { + description = "clightning ${network} node"; + + # clightning requires bitcoin-cli to talk to either spruned or bitcoind + path = [ pkgs.bitcoind ]; + + after = [ "network.target" ]; + wantedBy = optional cfg.autoStart "multi-user.target"; + + serviceConfig.ExecStart = "${pkgs.clightning}/bin/lightningd --lightning-dir=${cfg.dataDir} --conf=${configFile}"; + serviceConfig.Restart = "on-abort"; + }; +in +{ + options = { + services.clightning = { + networks = mkOption { + default = {}; + + description = '' + Each attribute of this option defines a systemd user service that runs a + clightning node. The name of each systemd service is + clightning-network.service, + where network is the corresponding attribute + name. + ''; + + example = '' + { + mainnet = { + dataDir = "/home/user/.lightning-bitcoin"; + config = ''' + fee-per-satoshi=9000 + lightning-dir=/home/user/.lightning-bitcoin + network=bitcoin + log-level=info + alias=mynode + rgb=ff0000 + '''; + }; + + testnet = { + dataDir = "/home/user/.lightning-testnet"; + config = ''' + fee-per-satoshi=1000 + network=testnet + log-level=debug + alias=my-testnet-node + rgb=00ff00 + '''; + }; + } + ''; + + + + type = types.attrsOf (types.submodule { + options = { + + dataDir = mkOption { + type = types.path; + description = '' + clightning data directory + ''; + }; + + config = mkOption { + type = types.lines; + description = '' + Configuration of this clightning node. + ''; + }; + + autoStart = mkOption { + default = true; + type = types.bool; + description = "Whether this clightning instance should be started automatically."; + }; + }; + }); + + }; + + }; + + }; + + config = mkIf (cfg.networks != {}) { + + systemd.user.services = + listToAttrs (mapAttrsFlatten (name: value: nameValuePair "clightning-${name}" (mkLightningNode value name)) cfg.networks); + + environment.systemPackages = [ pkgs.clightning ]; + + }; + +} -- 2.30.0