Remove unused services and support features
Squirtle runs bitcoind, lnd, electrs and mempool. Remove every other service module and its packages (clightning and plugins, joinmarket, btcpayserver/nbxplorer, rtl, liquid, lndconnect, loop, pool, charge-lnd, fulcrum, hardware-wallets, python-packages, bitcoind_29), plus the support features squirtle doesn't use: netns-isolation, i2p support in bitcoind, backups, versioning, obsolete-options and the krops/nixops deployment modules. mempool loses its electrumServer option and always uses electrs. Squirtle's system is unchanged on 26.05 apart from two blank lines in bitcoin.conf, and it now evaluates on 26.11 without the i2pd patch on branch nixos-26.11. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,127 +0,0 @@
|
||||
{ config, lib, pkgs, ... }:
|
||||
|
||||
with lib;
|
||||
let
|
||||
options.services.backups = {
|
||||
enable = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description = ''
|
||||
Enable backups of node data.
|
||||
This uses the NixOS duplicity service.
|
||||
To further configure the backup, you can set NixOS options `services.duplicity.*`.
|
||||
The `services.duplicity.cleanup.*` options are particularly useful.
|
||||
'';
|
||||
};
|
||||
with-bulk-data = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description = ''
|
||||
Whether to also backup Bitcoin blockchain and other bulk data.
|
||||
'';
|
||||
};
|
||||
destination = mkOption {
|
||||
type = types.str;
|
||||
default = "file:///var/lib/localBackups";
|
||||
description = ''
|
||||
Where to back up to.
|
||||
'';
|
||||
};
|
||||
frequency = mkOption {
|
||||
type = types.nullOr types.str;
|
||||
default = null;
|
||||
description = ''
|
||||
Run backup with the given frequency. If null, do not run automatically.
|
||||
'';
|
||||
};
|
||||
postgresqlDatabases = mkOption {
|
||||
type = types.listOf types.str;
|
||||
default = [];
|
||||
description = "List of database names to backup.";
|
||||
};
|
||||
extraFiles = mkOption {
|
||||
type = types.listOf types.str;
|
||||
default = [];
|
||||
example = [ "/var/lib/nginx" ];
|
||||
description = "Additional files to be appended to filelist.";
|
||||
};
|
||||
};
|
||||
|
||||
cfg = config.services.backups;
|
||||
|
||||
# Potential backup file paths are matched against filelist
|
||||
# entries from top to bottom.
|
||||
# The first match determines inclusion or exclusion.
|
||||
includeFileList = builtins.toFile "filelist.txt" ''
|
||||
${builtins.concatStringsSep "\n" cfg.extraFiles}
|
||||
|
||||
${optionalString (!cfg.with-bulk-data) ''
|
||||
- ${config.services.bitcoind.dataDir}/blocks
|
||||
- ${config.services.bitcoind.dataDir}/chainstate
|
||||
- ${config.services.bitcoind.dataDir}/indexes
|
||||
''}
|
||||
${config.services.bitcoind.dataDir}
|
||||
${config.services.clightning.dataDir}
|
||||
${config.services.clightning-rest.dataDir}
|
||||
${config.services.lnd.dataDir}
|
||||
${optionalString (!cfg.with-bulk-data) ''
|
||||
- ${config.services.liquidd.dataDir}/*/blocks
|
||||
- ${config.services.liquidd.dataDir}/*/chainstate
|
||||
- ${config.services.liquidd.dataDir}/*/indexes
|
||||
''}
|
||||
${config.services.liquidd.dataDir}
|
||||
${optionalString cfg.with-bulk-data "${config.services.electrs.dataDir}"}
|
||||
${config.services.nbxplorer.dataDir}
|
||||
${config.services.btcpayserver.dataDir}
|
||||
${config.services.joinmarket.dataDir}
|
||||
${optionalString config.nix-bitcoin.generateSecrets "${config.nix-bitcoin.secretsDir}"}
|
||||
/var/lib/tor
|
||||
/var/lib/nixos
|
||||
|
||||
${builtins.concatStringsSep "\n" postgresqlBackupPaths}
|
||||
|
||||
# Exclude all unspecified files and directories
|
||||
- /
|
||||
'';
|
||||
|
||||
postgresqlBackupDir = config.services.postgresqlBackup.location;
|
||||
postgresqlBackupPaths = map (db: "${postgresqlBackupDir}/${db}.sql.gz") cfg.postgresqlDatabases;
|
||||
postgresqlBackupServices = map (db: "postgresqlBackup-${db}.service") cfg.postgresqlDatabases;
|
||||
in {
|
||||
inherit options;
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
environment.systemPackages = [ pkgs.duplicity ];
|
||||
|
||||
services.duplicity = {
|
||||
enable = true;
|
||||
inherit includeFileList;
|
||||
fullIfOlderThan = mkDefault "1M";
|
||||
targetUrl = cfg.destination;
|
||||
frequency = cfg.frequency;
|
||||
secretFile = "${config.nix-bitcoin.secretsDir}/backup-encryption-env";
|
||||
};
|
||||
|
||||
systemd.services.duplicity = {
|
||||
wants = postgresqlBackupServices;
|
||||
after = postgresqlBackupServices ++ [ "nix-bitcoin-secrets.target" ];
|
||||
};
|
||||
|
||||
services.postgresqlBackup = {
|
||||
enable = mkIf (cfg.postgresqlDatabases != []) true;
|
||||
databases = cfg.postgresqlDatabases;
|
||||
};
|
||||
|
||||
nix-bitcoin.secrets.backup-encryption-env.user = "root";
|
||||
nix-bitcoin.generateSecretsCmds.backups = ''
|
||||
makePasswordSecret backup-encryption-password
|
||||
if [[ backup-encryption-password -nt backup-encryption-env ]]; then
|
||||
echo "PASSPHRASE=$(cat backup-encryption-password)" > backup-encryption-env
|
||||
fi
|
||||
'';
|
||||
|
||||
services.backups.postgresqlDatabases = mkIf config.services.btcpayserver.enable (
|
||||
[ "btcpaydb" ] ++ optional cfg.with-bulk-data "nbxplorer"
|
||||
);
|
||||
};
|
||||
}
|
||||
@@ -173,14 +173,6 @@ let
|
||||
default = if cfg.tor.proxy then config.nix-bitcoin.torClientAddressWithPort else null;
|
||||
description = "Connect through SOCKS5 proxy";
|
||||
};
|
||||
i2p = mkOption {
|
||||
type = types.enum [ false true "only-outgoing" ];
|
||||
default = false;
|
||||
description = ''
|
||||
Enable peer connections via i2p.
|
||||
With `only-outgoing`, incoming i2p connections are disabled.
|
||||
'';
|
||||
};
|
||||
dataDirReadableByGroup = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
@@ -289,8 +281,6 @@ let
|
||||
nbLib = config.nix-bitcoin.lib;
|
||||
secretsDir = config.nix-bitcoin.secretsDir;
|
||||
|
||||
i2pSAM = config.services.i2pd.proto.sam;
|
||||
|
||||
configFile = builtins.toFile "bitcoin.conf" ''
|
||||
# We're already logging via journald
|
||||
nodebuglogfile=1
|
||||
@@ -318,8 +308,6 @@ let
|
||||
${optionalString cfg.listenWhitelisted
|
||||
"whitebind=${cfg.address}:${toString cfg.whitelistedPort}"}
|
||||
${optionalString (cfg.proxy != null) "proxy=${cfg.proxy}"}
|
||||
${optionalString (cfg.i2p != false) "i2psam=${nbLib.addressWithPort i2pSAM.address i2pSAM.port}"}
|
||||
${optionalString (cfg.i2p == "only-outgoing") "i2pacceptincoming=0"}
|
||||
|
||||
${optionalString (cfg.discover != null) "discover=${if cfg.discover then "1" else "0"}"}
|
||||
${lib.concatMapStrings (node: "addnode=${node}\n") cfg.addnodes}
|
||||
@@ -377,11 +365,6 @@ in {
|
||||
}
|
||||
];
|
||||
|
||||
services.i2pd = mkIf (cfg.i2p != false) {
|
||||
enable = true;
|
||||
proto.sam.enable = true;
|
||||
};
|
||||
|
||||
systemd.tmpfiles.rules = [
|
||||
"d '${cfg.dataDir}' 0770 ${cfg.user} ${cfg.group} - -"
|
||||
];
|
||||
@@ -392,9 +375,6 @@ in {
|
||||
# Use `wants` instead of `requires` for `nix-bitcoin-secrets.target`
|
||||
# so that bitcoind and all dependent services are not restarted when
|
||||
# the secrets target restarts.
|
||||
# The secrets target always restarts when deploying with one of the methods
|
||||
# in ./deployment.
|
||||
#
|
||||
# TODO-EXTERNAL: Instead of `wants`, use a future systemd dependency type
|
||||
# that propagates initial start failures but no restarts
|
||||
"nix-bitcoin-secrets.target"
|
||||
|
||||
@@ -1,287 +0,0 @@
|
||||
{ config, lib, pkgs, ... }:
|
||||
|
||||
with lib;
|
||||
let
|
||||
options.services = {
|
||||
btcpayserver = {
|
||||
enable = mkEnableOption "btcpayserver, a self-hosted Bitcoin payment processor";
|
||||
address = mkOption {
|
||||
type = types.str;
|
||||
default = "127.0.0.1";
|
||||
description = "Address to listen on.";
|
||||
};
|
||||
port = mkOption {
|
||||
type = types.port;
|
||||
default = 23000;
|
||||
description = "Port to listen on.";
|
||||
};
|
||||
package = mkOption {
|
||||
type = types.package;
|
||||
default = if cfg.btcpayserver.lbtc then
|
||||
config.nix-bitcoin.pkgs.btcpayserver.override { altcoinSupport = true; }
|
||||
else
|
||||
config.nix-bitcoin.pkgs.btcpayserver;
|
||||
defaultText = "(See source)";
|
||||
description = "The package providing btcpayserver binaries.";
|
||||
};
|
||||
dataDir = mkOption {
|
||||
type = types.path;
|
||||
default = "/var/lib/btcpayserver";
|
||||
description = "The data directory for btcpayserver.";
|
||||
};
|
||||
lightningBackend = mkOption {
|
||||
type = types.nullOr (types.enum [ "clightning" "lnd" ]);
|
||||
default = null;
|
||||
description = "The lightning node implementation to use.";
|
||||
};
|
||||
lbtc = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description = "Enable liquid support in btcpayserver.";
|
||||
};
|
||||
rootpath = mkOption {
|
||||
type = types.nullOr types.str;
|
||||
default = null;
|
||||
example = "btcpayserver";
|
||||
description = "The prefix for root-relative btcpayserver URLs.";
|
||||
};
|
||||
user = mkOption {
|
||||
type = types.str;
|
||||
default = "btcpayserver";
|
||||
description = "The user as which to run btcpayserver.";
|
||||
};
|
||||
group = mkOption {
|
||||
type = types.str;
|
||||
default = cfg.btcpayserver.user;
|
||||
description = "The group as which to run btcpayserver.";
|
||||
};
|
||||
tor.enforce = nbLib.tor.enforce;
|
||||
};
|
||||
|
||||
nbxplorer = {
|
||||
enable = mkOption {
|
||||
# This option is only used by netns-isolation
|
||||
internal = true;
|
||||
default = cfg.btcpayserver.enable;
|
||||
description = ''
|
||||
nbxplorer is always enabled when btcpayserver is enabled.
|
||||
'';
|
||||
};
|
||||
package = mkOption {
|
||||
type = types.package;
|
||||
default = config.nix-bitcoin.pkgs.nbxplorer;
|
||||
defaultText = "config.nix-bitcoin.pkgs.nbxplorer";
|
||||
description = "The package providing nbxplorer binaries.";
|
||||
};
|
||||
address = mkOption {
|
||||
type = types.str;
|
||||
default = "127.0.0.1";
|
||||
description = "Address to listen on.";
|
||||
};
|
||||
port = mkOption {
|
||||
type = types.port;
|
||||
default = 24444;
|
||||
description = "Port to listen on.";
|
||||
};
|
||||
dataDir = mkOption {
|
||||
type = types.path;
|
||||
default = "/var/lib/nbxplorer";
|
||||
description = "The data directory for nbxplorer.";
|
||||
};
|
||||
user = mkOption {
|
||||
type = types.str;
|
||||
default = "nbxplorer";
|
||||
description = "The user as which to run nbxplorer.";
|
||||
};
|
||||
group = mkOption {
|
||||
type = types.str;
|
||||
default = cfg.nbxplorer.user;
|
||||
description = "The group as which to run nbxplorer.";
|
||||
};
|
||||
tor.enforce = nbLib.tor.enforce;
|
||||
};
|
||||
};
|
||||
|
||||
cfg = config.services;
|
||||
nbLib = config.nix-bitcoin.lib;
|
||||
|
||||
inherit (config.services) bitcoind liquidd;
|
||||
in {
|
||||
inherit options;
|
||||
|
||||
config = mkIf cfg.btcpayserver.enable {
|
||||
services.bitcoind = {
|
||||
enable = true;
|
||||
rpc.users.btcpayserver = {
|
||||
passwordHMACFromFile = true;
|
||||
rpcwhitelist = cfg.bitcoind.rpc.users.public.rpcwhitelist ++ [
|
||||
"setban"
|
||||
"generatetoaddress"
|
||||
];
|
||||
};
|
||||
listenWhitelisted = true;
|
||||
};
|
||||
services.clightning.enable = mkIf (cfg.btcpayserver.lightningBackend == "clightning") true;
|
||||
services.lnd = mkIf (cfg.btcpayserver.lightningBackend == "lnd") {
|
||||
enable = true;
|
||||
macaroons.btcpayserver = {
|
||||
inherit (cfg.btcpayserver) user;
|
||||
permissions = ''{"entity":"info","action":"read"},{"entity":"onchain","action":"read"},{"entity":"offchain","action":"read"},{"entity":"address","action":"read"},{"entity":"message","action":"read"},{"entity":"peers","action":"read"},{"entity":"signer","action":"read"},{"entity":"invoices","action":"read"},{"entity":"invoices","action":"write"},{"entity":"address","action":"write"}'';
|
||||
};
|
||||
};
|
||||
services.liquidd = mkIf cfg.btcpayserver.lbtc {
|
||||
enable = true;
|
||||
listenWhitelisted = true;
|
||||
};
|
||||
services.postgresql = {
|
||||
enable = true;
|
||||
ensureDatabases = [
|
||||
"btcpaydb" # This name is kept for backwards compatibility
|
||||
"nbxplorer"
|
||||
];
|
||||
ensureUsers = [
|
||||
{ name = cfg.btcpayserver.user; }
|
||||
{ name = cfg.nbxplorer.user; }
|
||||
];
|
||||
};
|
||||
systemd.services.postgresql-setup.postStart = ''
|
||||
psql -tAc '
|
||||
ALTER DATABASE "btcpaydb" OWNER TO "${cfg.btcpayserver.user}";
|
||||
ALTER DATABASE "nbxplorer" OWNER TO "${cfg.nbxplorer.user}";
|
||||
'
|
||||
'';
|
||||
|
||||
systemd.tmpfiles.rules = [
|
||||
"d '${cfg.nbxplorer.dataDir}' 0770 ${cfg.nbxplorer.user} ${cfg.nbxplorer.group} - -"
|
||||
"d '${cfg.btcpayserver.dataDir}' 0770 ${cfg.btcpayserver.user} ${cfg.btcpayserver.group} - -"
|
||||
];
|
||||
|
||||
systemd.services.nbxplorer = let
|
||||
configFile = builtins.toFile "config" ''
|
||||
network=${bitcoind.network}
|
||||
btcrpcuser=${cfg.bitcoind.rpc.users.btcpayserver.name}
|
||||
btcrpcurl=http://${nbLib.addressWithPort bitcoind.rpc.address cfg.bitcoind.rpc.port}
|
||||
btcnodeendpoint=${nbLib.addressWithPort bitcoind.address bitcoind.whitelistedPort}
|
||||
bind=${cfg.nbxplorer.address}
|
||||
port=${toString cfg.nbxplorer.port}
|
||||
${optionalString cfg.btcpayserver.lbtc ''
|
||||
chains=btc,lbtc
|
||||
lbtcrpcuser=${liquidd.rpcuser}
|
||||
lbtcrpcurl=http://${nbLib.addressWithPort liquidd.rpc.address liquidd.rpc.port}
|
||||
lbtcnodeendpoint=${nbLib.addressWithPort liquidd.address liquidd.whitelistedPort}
|
||||
''}
|
||||
postgres=User ID=${cfg.nbxplorer.user};Host=/run/postgresql;Database=nbxplorer
|
||||
'';
|
||||
in rec {
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
requires = [ "postgresql.target" ];
|
||||
wants = [ "bitcoind.service" ] ++ optional cfg.btcpayserver.lbtc "liquidd.service";
|
||||
after = requires ++ wants ++ [ "nix-bitcoin-secrets.target" ];
|
||||
preStart = ''
|
||||
install -m 600 ${configFile} '${cfg.nbxplorer.dataDir}/settings.config'
|
||||
{
|
||||
echo "btcrpcpassword=$(cat ${config.nix-bitcoin.secretsDir}/bitcoin-rpcpassword-btcpayserver)"
|
||||
${optionalString cfg.btcpayserver.lbtc ''
|
||||
echo "lbtcrpcpassword=$(cat ${config.nix-bitcoin.secretsDir}/liquid-rpcpassword)"
|
||||
''}
|
||||
} >> '${cfg.nbxplorer.dataDir}/settings.config'
|
||||
'';
|
||||
serviceConfig = nbLib.defaultHardening // {
|
||||
ExecStart = ''
|
||||
${cfg.nbxplorer.package}/bin/nbxplorer --conf=${cfg.nbxplorer.dataDir}/settings.config \
|
||||
--datadir=${cfg.nbxplorer.dataDir}
|
||||
'';
|
||||
User = cfg.nbxplorer.user;
|
||||
Restart = "on-failure";
|
||||
RestartSec = "10s";
|
||||
ReadWritePaths = [ cfg.nbxplorer.dataDir ];
|
||||
MemoryDenyWriteExecute = false;
|
||||
} // nbLib.allowedIPAddresses cfg.nbxplorer.tor.enforce;
|
||||
};
|
||||
|
||||
systemd.services.btcpayserver = let
|
||||
nbExplorerUrl = "http://${nbLib.addressWithPort cfg.nbxplorer.address cfg.nbxplorer.port}/";
|
||||
nbExplorerCookie = "${cfg.nbxplorer.dataDir}/${bitcoind.makeNetworkName "Main" "RegTest"}/.cookie";
|
||||
configFile = builtins.toFile "btcpayserver-config" (''
|
||||
network=${bitcoind.network}
|
||||
bind=${cfg.btcpayserver.address}
|
||||
port=${toString cfg.btcpayserver.port}
|
||||
socksendpoint=${config.nix-bitcoin.torClientAddressWithPort}
|
||||
btcexplorerurl=${nbExplorerUrl}
|
||||
btcexplorercookiefile=${nbExplorerCookie}
|
||||
postgres=User ID=${cfg.btcpayserver.user};Host=/run/postgresql;Database=btcpaydb
|
||||
'' + optionalString (cfg.btcpayserver.rootpath != null) ''
|
||||
rootpath=${cfg.btcpayserver.rootpath}
|
||||
'' + optionalString (cfg.btcpayserver.lightningBackend == "clightning") ''
|
||||
btclightning=type=clightning;server=unix:///${cfg.clightning.dataDir}/${bitcoind.makeNetworkName "bitcoin" "regtest"}/lightning-rpc
|
||||
'' + optionalString (cfg.btcpayserver.lightningBackend == "lnd")
|
||||
(
|
||||
"btclightning=type=lnd-rest;" +
|
||||
"server=https://${nbLib.address cfg.lnd.restAddress}:${toString cfg.lnd.restPort}/;" +
|
||||
"macaroonfilepath=/run/lnd/btcpayserver.macaroon;" +
|
||||
"certfilepath=${config.services.lnd.certPath}" +
|
||||
"\n"
|
||||
)
|
||||
+ optionalString cfg.btcpayserver.lbtc ''
|
||||
chains=btc,lbtc
|
||||
lbtcexplorerurl=${nbExplorerUrl}
|
||||
lbtcexplorercookiefile=${nbExplorerCookie}
|
||||
'');
|
||||
in rec {
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
requires = [ "postgresql.target" ];
|
||||
wants = [ "nbxplorer.service" ]
|
||||
++ optional (cfg.btcpayserver.lightningBackend != null) "${cfg.btcpayserver.lightningBackend}.service";
|
||||
after = requires ++ wants;
|
||||
serviceConfig = nbLib.defaultHardening // {
|
||||
ExecStart = ''
|
||||
${cfg.btcpayserver.package}/bin/btcpayserver --conf=${configFile} \
|
||||
--datadir='${cfg.btcpayserver.dataDir}'
|
||||
'';
|
||||
User = cfg.btcpayserver.user;
|
||||
# Since 2.4.0, btcpayserver uses `Host.CreateDefaultBuilder`, which sets the
|
||||
# ASP.NET content root to the working directory instead of the app directory.
|
||||
# The web root (`wwwroot`) is resolved relative to the content root, so
|
||||
# btcpayserver must be started from its app directory.
|
||||
WorkingDirectory = "${cfg.btcpayserver.package}/lib/btcpayserver";
|
||||
# Also restart after the program has exited successfully.
|
||||
# This is required to support restarting from the web interface after
|
||||
# interactive plugin installation.
|
||||
# Restart rate limiting is implemented via the `startLimit*` options below.
|
||||
Restart = "always";
|
||||
ReadWritePaths = [ cfg.btcpayserver.dataDir ];
|
||||
MemoryDenyWriteExecute = false;
|
||||
} // nbLib.allowedIPAddresses cfg.btcpayserver.tor.enforce;
|
||||
startLimitIntervalSec = 30;
|
||||
startLimitBurst = 10;
|
||||
};
|
||||
|
||||
users.users.${cfg.nbxplorer.user} = {
|
||||
isSystemUser = true;
|
||||
group = cfg.nbxplorer.group;
|
||||
extraGroups = [ "bitcoinrpc-public" ]
|
||||
++ optional cfg.btcpayserver.lbtc liquidd.group;
|
||||
home = cfg.nbxplorer.dataDir;
|
||||
};
|
||||
users.groups.${cfg.nbxplorer.group} = {};
|
||||
users.users.${cfg.btcpayserver.user} = {
|
||||
isSystemUser = true;
|
||||
group = cfg.btcpayserver.group;
|
||||
extraGroups = [ cfg.nbxplorer.group ]
|
||||
++ optional (cfg.btcpayserver.lightningBackend == "clightning") cfg.clightning.user;
|
||||
home = cfg.btcpayserver.dataDir;
|
||||
};
|
||||
users.groups.${cfg.btcpayserver.group} = {};
|
||||
|
||||
nix-bitcoin.secrets = {
|
||||
bitcoin-rpcpassword-btcpayserver = {
|
||||
user = cfg.bitcoind.user;
|
||||
group = cfg.nbxplorer.group;
|
||||
};
|
||||
bitcoin-HMAC-btcpayserver.user = cfg.bitcoind.user;
|
||||
};
|
||||
nix-bitcoin.generateSecretsCmds.btcpayserver = ''
|
||||
makeBitcoinRPCPassword btcpayserver
|
||||
'';
|
||||
};
|
||||
}
|
||||
@@ -1,136 +0,0 @@
|
||||
{ config, lib, pkgs, ... }:
|
||||
|
||||
with lib;
|
||||
let
|
||||
options.services.charge-lnd = with types; {
|
||||
enable = mkEnableOption "charge-lnd, policy-based fee manager";
|
||||
|
||||
extraFlags = mkOption {
|
||||
type = listOf str;
|
||||
default = [];
|
||||
example = [ "--verbose" "--dry-run" ];
|
||||
description = "Extra flags to pass to the charge-lnd command.";
|
||||
};
|
||||
|
||||
interval = mkOption {
|
||||
type = str;
|
||||
default = "*-*-* 04:00:00";
|
||||
example = "hourly";
|
||||
description = ''
|
||||
Systemd calendar expression when to adjust fees.
|
||||
|
||||
See {man}`systemd.time(7)` for possible values.
|
||||
|
||||
Default is once a day.
|
||||
'';
|
||||
};
|
||||
|
||||
randomDelay = mkOption {
|
||||
type = str;
|
||||
default = "1h";
|
||||
description = ''
|
||||
Random delay to add to scheduled time.
|
||||
'';
|
||||
};
|
||||
|
||||
policies = mkOption {
|
||||
type = types.lines;
|
||||
default = "";
|
||||
example = ''
|
||||
[discourage-routing-out-of-balance]
|
||||
chan.max_ratio = 0.1
|
||||
chan.min_capacity = 250000
|
||||
strategy = static
|
||||
base_fee_msat = 10000
|
||||
fee_ppm = 500
|
||||
|
||||
[encourage-routing-to-balance]
|
||||
chan.min_ratio = 0.9
|
||||
chan.min_capacity = 250000
|
||||
strategy = static
|
||||
base_fee_msat = 1
|
||||
fee_ppm = 2
|
||||
|
||||
[default]
|
||||
strategy = ignore
|
||||
'';
|
||||
description = ''
|
||||
Policy definitions in INI format.
|
||||
|
||||
See https://github.com/accumulator/charge-lnd/blob/master/README.md#usage
|
||||
for possible properties and parameters.
|
||||
|
||||
Policies are evaluated from top to bottom.
|
||||
The first matching policy (or `default`) is applied.
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
cfg = config.services.charge-lnd;
|
||||
nbLib = config.nix-bitcoin.lib;
|
||||
|
||||
lnd = config.services.lnd;
|
||||
|
||||
user = "charge-lnd";
|
||||
group = user;
|
||||
dataDir = "/var/lib/charge-lnd";
|
||||
configFile = builtins.toFile "charge-lnd.config" cfg.policies;
|
||||
checkedConfig = pkgs.runCommand "charge-lnd-checked.config" { } ''
|
||||
${config.nix-bitcoin.pkgs.charge-lnd}/bin/charge-lnd --check --config ${configFile}
|
||||
cp ${configFile} $out
|
||||
'';
|
||||
in
|
||||
{
|
||||
inherit options;
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
services.lnd = {
|
||||
enable = true;
|
||||
macaroons.charge-lnd = {
|
||||
user = user;
|
||||
permissions = ''{"entity":"info","action":"read"},{"entity":"onchain","action":"read"},{"entity":"offchain","action":"read"},{"entity":"offchain","action":"write"}'';
|
||||
};
|
||||
};
|
||||
|
||||
systemd.services.charge-lnd = {
|
||||
documentation = [ "https://github.com/accumulator/charge-lnd/blob/master/README.md" ];
|
||||
after = [ "lnd.service" ];
|
||||
requires = [ "lnd.service" ];
|
||||
# lnd's data directory (--lnddir) is not accessible to charge-lnd.
|
||||
# Instead use directory "lnddir-proxy" as lnddir and link relevant files to it.
|
||||
preStart = ''
|
||||
macaroonDir=${dataDir}/lnddir-proxy/data/chain/bitcoin/mainnet
|
||||
mkdir -p $macaroonDir
|
||||
ln -sf /run/lnd/charge-lnd.macaroon $macaroonDir
|
||||
ln -sf ${lnd.certPath} ${dataDir}/lnddir-proxy/tls.cert
|
||||
'';
|
||||
serviceConfig = nbLib.defaultHardening // {
|
||||
ExecStart = ''
|
||||
${config.nix-bitcoin.pkgs.charge-lnd}/bin/charge-lnd \
|
||||
--lnddir ${dataDir}/lnddir-proxy \
|
||||
--grpc ${nbLib.addressWithPort lnd.rpcAddress lnd.rpcPort} \
|
||||
--config ${checkedConfig} \
|
||||
${escapeShellArgs cfg.extraFlags}
|
||||
'';
|
||||
Type = "oneshot";
|
||||
User = user;
|
||||
Group = group;
|
||||
StateDirectory = "charge-lnd";
|
||||
} // nbLib.allowLocalIPAddresses;
|
||||
};
|
||||
|
||||
systemd.timers.charge-lnd = {
|
||||
wantedBy = [ "timers.target" ];
|
||||
timerConfig = {
|
||||
OnCalendar = cfg.interval;
|
||||
RandomizedDelaySec = cfg.randomDelay;
|
||||
};
|
||||
};
|
||||
|
||||
users.users.${user} = {
|
||||
isSystemUser = true;
|
||||
group = group;
|
||||
};
|
||||
users.groups.${group} = {};
|
||||
};
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
{ config, lib, pkgs, ... }:
|
||||
|
||||
with lib;
|
||||
let cfg = config.services.clightning.plugins.clboss; in
|
||||
{
|
||||
options.services.clightning.plugins.clboss = {
|
||||
enable = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description = ''
|
||||
Whether to enable CLBOSS (clightning plugin).
|
||||
See also: https://github.com/ZmnSCPxj/clboss#operating
|
||||
'';
|
||||
};
|
||||
min-onchain = mkOption {
|
||||
type = types.ints.positive;
|
||||
default = 30000;
|
||||
description = ''
|
||||
Target amount (in satoshi) that CLBOSS will leave on-chain.
|
||||
clboss will only open new channels if the funds in your clightning wallet are
|
||||
larger than this amount.
|
||||
'';
|
||||
};
|
||||
min-channel = mkOption {
|
||||
type = types.ints.positive;
|
||||
default = 500000;
|
||||
description = "The minimum size (in satoshi) of channels created by CLBOSS.";
|
||||
};
|
||||
max-channel = mkOption {
|
||||
type = types.ints.positive;
|
||||
default = 16777215;
|
||||
description = "The maximum size (in satoshi) of channels created by CLBOSS.";
|
||||
};
|
||||
zerobasefee = mkOption {
|
||||
type = types.enum [ "require" "allow" "disallow" ];
|
||||
default = "allow";
|
||||
description = ''
|
||||
`require`: set `base_fee` to 0.
|
||||
`allow`: set `base_fee` according to the CLBOSS heuristics, which may include value 0.
|
||||
`disallow`: set `base_fee` to according to the CLBOSS heuristics, with a minimum value of 1.
|
||||
'';
|
||||
};
|
||||
package = mkOption {
|
||||
type = types.package;
|
||||
default = config.nix-bitcoin.pkgs.clboss;
|
||||
defaultText = "config.nix-bitcoin.pkgs.clboss";
|
||||
description = "The package providing clboss binaries.";
|
||||
};
|
||||
};
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
services.clightning.extraConfig = ''
|
||||
plugin=${cfg.package}/bin/clboss
|
||||
clboss-min-onchain=${toString cfg.min-onchain}
|
||||
clboss-min-channel=${toString cfg.min-channel}
|
||||
clboss-max-channel=${toString cfg.max-channel}
|
||||
clboss-zerobasefee=${cfg.zerobasefee}
|
||||
'';
|
||||
|
||||
systemd.services.clightning.path = [
|
||||
pkgs.dnsutils
|
||||
] ++ optional config.services.clightning.tor.proxy (hiPrio config.nix-bitcoin.torify);
|
||||
};
|
||||
}
|
||||
@@ -1,90 +0,0 @@
|
||||
{ config, lib, pkgs, ... }:
|
||||
|
||||
with lib;
|
||||
let
|
||||
options = {
|
||||
services.clightning.plugins.clnrest = {
|
||||
enable = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description = ''
|
||||
Enable clnrest (clightning plugin).
|
||||
|
||||
clnrest provides a clightning REST API, using clightning RPC calls as its backend.
|
||||
It also broadcasts clightning notifications to listeners connected to its websocket server.
|
||||
|
||||
See here for all available options:
|
||||
https://docs.corelightning.org/docs/rest
|
||||
Extra options can be set via `services.clightning.extraConfig`.
|
||||
'';
|
||||
};
|
||||
address = mkOption {
|
||||
type = types.str;
|
||||
default = "127.0.0.1";
|
||||
description = "Address to listen for REST connections.";
|
||||
};
|
||||
port = mkOption {
|
||||
type = types.port;
|
||||
default = 3010;
|
||||
description = "REST server port.";
|
||||
};
|
||||
createAdminRune = mkOption {
|
||||
type = types.bool;
|
||||
default = true;
|
||||
description = ''
|
||||
Create a rune with admin permissions at path `''${config.services.clightning.networkDir}/admin-rune`.
|
||||
'';
|
||||
};
|
||||
package = mkOption {
|
||||
type = types.package;
|
||||
default = config.nix-bitcoin.pkgs.clnrest;
|
||||
defaultText = "config.nix-bitcoin.pkgs.clnrest";
|
||||
description = "The package providing clnrest binaries.";
|
||||
};
|
||||
};
|
||||
|
||||
# Internal read-only options used by `./nodeinfo.nix` and `./onion-services.nix`
|
||||
services.clnrest = let
|
||||
inherit (config.nix-bitcoin.lib) mkAlias;
|
||||
in {
|
||||
enable = mkAlias cfg.enable;
|
||||
address = mkAlias cfg.address;
|
||||
port = mkAlias cfg.port;
|
||||
};
|
||||
};
|
||||
|
||||
cfg = config.services.clightning.plugins.clnrest;
|
||||
nbLib = config.nix-bitcoin.lib;
|
||||
inherit (config.services) clightning;
|
||||
|
||||
runePath = "${clightning.networkDir}/admin-rune";
|
||||
in
|
||||
{
|
||||
inherit options;
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
services.clightning.extraConfig = ''
|
||||
plugin=${cfg.package}/bin/clnrest
|
||||
clnrest-host=${cfg.address}
|
||||
clnrest-port=${toString cfg.port}
|
||||
'';
|
||||
|
||||
systemd.services.clightning.postStart = mkAfter (
|
||||
optionalString cfg.createAdminRune ''
|
||||
if [[ ! -e '${runePath}' ]]; then
|
||||
rune=$(${clightning.cli}/bin/lightning-cli createrune | ${pkgs.jq}/bin/jq -r .rune)
|
||||
install -m 640 <(echo "$rune") '${runePath}'
|
||||
fi
|
||||
'' +
|
||||
# Wait until the clnrest server is listening.
|
||||
# Usually, the server is already listening at this point.
|
||||
# But when clnrest is running for the first time, certificates are generated
|
||||
# before the server starts, which can take a few seconds.
|
||||
''
|
||||
while ! { exec 3>/dev/tcp/${nbLib.address cfg.address}/${toString cfg.port}; } &>/dev/null; do
|
||||
sleep 0.1
|
||||
done
|
||||
''
|
||||
);
|
||||
};
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
{ config, lib, pkgs, ... }:
|
||||
|
||||
with lib;
|
||||
let
|
||||
options.services.clightning.plugins = {
|
||||
currencyrate.enable = mkEnableOption "Currencyrate (clightning plugin)";
|
||||
monitor.enable = mkEnableOption "Monitor (clightning plugin)";
|
||||
rebalance.enable = mkEnableOption "Rebalance (clightning plugin)";
|
||||
};
|
||||
|
||||
cfg = config.services.clightning.plugins;
|
||||
pluginPkgs = config.nix-bitcoin.pkgs.clightning-plugins;
|
||||
in {
|
||||
imports = [
|
||||
./clboss.nix
|
||||
./clnrest.nix
|
||||
./feeadjuster.nix
|
||||
./trustedcoin.nix
|
||||
./zmq.nix
|
||||
];
|
||||
|
||||
inherit options;
|
||||
|
||||
config = {
|
||||
services.clightning.extraConfig = mkMerge [
|
||||
(mkIf cfg.currencyrate.enable "plugin=${pluginPkgs.currencyrate.path}")
|
||||
(mkIf cfg.monitor.enable "plugin=${pluginPkgs.monitor.path}")
|
||||
(mkIf cfg.rebalance.enable "plugin=${pluginPkgs.rebalance.path}")
|
||||
];
|
||||
};
|
||||
}
|
||||
@@ -1,78 +0,0 @@
|
||||
{ config, lib, ... }:
|
||||
|
||||
with lib;
|
||||
let
|
||||
options.services.clightning.plugins.feeadjuster = {
|
||||
enable = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description = ''
|
||||
Enable feeaduster (clightning plugin).
|
||||
This plugin auto-updates channel fees to keep channels balanced.
|
||||
|
||||
See here for all available options:
|
||||
https://github.com/lightningd/plugins/blob/master/feeadjuster/feeadjuster.py
|
||||
Extra options can be set via `services.clightning.extraConfig`.
|
||||
'';
|
||||
};
|
||||
fuzz = mkOption {
|
||||
type = types.bool;
|
||||
default = true;
|
||||
description = "Enable update threshold randomization and hysteresis.";
|
||||
};
|
||||
adjustOnForward = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description = "Automatically update fees on forward events.";
|
||||
};
|
||||
method = mkOption {
|
||||
type = types.enum [ "soft" "default" "hard" ];
|
||||
default = "default";
|
||||
description = ''
|
||||
Adjustment method to calculate channel fees.
|
||||
`soft`: less difference when adjusting fees.
|
||||
`hard`: greater difference when adjusting fees.
|
||||
'';
|
||||
};
|
||||
adjustDaily = mkOption {
|
||||
type = types.bool;
|
||||
default = true;
|
||||
description = "Automatically update fees daily.";
|
||||
};
|
||||
};
|
||||
|
||||
cfg = config.services.clightning.plugins.feeadjuster;
|
||||
inherit (config.services) clightning;
|
||||
in
|
||||
{
|
||||
inherit options;
|
||||
|
||||
config = mkIf (cfg.enable && clightning.enable) {
|
||||
services.clightning.extraConfig = ''
|
||||
plugin=${config.nix-bitcoin.pkgs.clightning-plugins.feeadjuster.path}
|
||||
feeadjuster-adjustment-method="${cfg.method}"
|
||||
'' + optionalString (!cfg.fuzz) ''
|
||||
feeadjuster-deactivate-fuzz
|
||||
'' + optionalString (!cfg.adjustOnForward) ''
|
||||
feeadjuster-deactivate-fee-update
|
||||
'';
|
||||
|
||||
systemd = mkIf cfg.adjustDaily {
|
||||
services.clightning-feeadjuster = {
|
||||
# Only run when clightning is running
|
||||
requisite = [ "clightning.service" ];
|
||||
after = [ "clightning.service" ];
|
||||
serviceConfig = {
|
||||
Type = "oneshot";
|
||||
User = "clightning";
|
||||
ExecStart = "${clightning.package}/bin/lightning-cli --lightning-dir ${clightning.dataDir} feeadjust";
|
||||
};
|
||||
unitConfig.JoinsNamespaceOf = [ "clightning.service" ];
|
||||
startAt = [ "daily" ];
|
||||
};
|
||||
timers.clightning-feeadjuster.timerConfig = {
|
||||
RandomizedDelaySec = "6h";
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
{ config, lib, pkgs, ... }:
|
||||
|
||||
with lib;
|
||||
let cfg = config.services.clightning.plugins.trustedcoin; in
|
||||
{
|
||||
options.services.clightning.plugins.trustedcoin = {
|
||||
enable = mkEnableOption "Trustedcoin (clightning plugin)";
|
||||
|
||||
package = mkOption {
|
||||
type = types.package;
|
||||
default = config.nix-bitcoin.pkgs.trustedcoin;
|
||||
defaultText = "config.nix-bitcoin.pkgs.trustedcoin";
|
||||
description = "The package providing trustedcoin binaries.";
|
||||
};
|
||||
|
||||
tor.proxy = mkOption {
|
||||
type = types.bool;
|
||||
default = config.services.clightning.tor.proxy;
|
||||
description = "Whether to proxy outgoing connections with Tor.";
|
||||
};
|
||||
};
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
services.clightning = {
|
||||
useBcliPlugin = false;
|
||||
extraConfig = ''
|
||||
plugin=${cfg.package}/bin/trustedcoin
|
||||
'';
|
||||
tor.enforce = mkIf (!cfg.tor.proxy) false;
|
||||
};
|
||||
|
||||
systemd.services.clightning.environment = mkIf (cfg.tor.proxy) {
|
||||
HTTPS_PROXY = let
|
||||
clnProxy = config.services.clightning.proxy;
|
||||
proxy = if clnProxy != null then clnProxy else config.nix-bitcoin.torClientAddressWithPort;
|
||||
in
|
||||
"socks5://${proxy}";
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
{ config, lib, ... }:
|
||||
|
||||
with lib;
|
||||
let
|
||||
options.services.clightning.plugins.zmq = {
|
||||
enable = mkEnableOption "ZMQ (clightning plugin)";
|
||||
} // lib.genAttrs endpoints mkEndpointOption;
|
||||
|
||||
cfg = config.services.clightning.plugins.zmq;
|
||||
|
||||
nbLib = config.nix-bitcoin.lib;
|
||||
|
||||
endpoints = [
|
||||
"channel-opened"
|
||||
"connect"
|
||||
"disconnect"
|
||||
"invoice-payment"
|
||||
"warning"
|
||||
"forward-event"
|
||||
"sendpay-success"
|
||||
"sendpay-failure"
|
||||
];
|
||||
|
||||
mkEndpointOption = name:
|
||||
mkOption {
|
||||
type = types.nullOr types.str;
|
||||
default = null;
|
||||
description = "Endpoint for ${name}";
|
||||
};
|
||||
|
||||
setEndpoint = ep:
|
||||
let value = builtins.getAttr ep cfg; in
|
||||
optionalString (value != null) ''
|
||||
zmq-pub-${ep}=${value}
|
||||
'';
|
||||
in
|
||||
{
|
||||
inherit options;
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
services.clightning.extraConfig = ''
|
||||
plugin=${config.nix-bitcoin.pkgs.clightning-plugins.zmq.path}
|
||||
${concatStrings (map setEndpoint endpoints)}
|
||||
'';
|
||||
|
||||
# The zmq server requires AF_NETLINK
|
||||
systemd.services.clightning.serviceConfig.RestrictAddressFamilies =
|
||||
mkForce nbLib.allowNetlink.RestrictAddressFamilies;
|
||||
};
|
||||
}
|
||||
@@ -1,230 +0,0 @@
|
||||
{ config, lib, pkgs, ... }:
|
||||
|
||||
with lib;
|
||||
let
|
||||
options.services.clightning.replication = {
|
||||
enable = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description = ''
|
||||
Enable live replication of the clightning database.
|
||||
This prevents losing off-chain funds when the primary wallet file becomes
|
||||
inaccessible.
|
||||
|
||||
For setting the destination, you can either define option `sshfs.destination`
|
||||
or `local.directory`.
|
||||
|
||||
When `encrypt` is `false`, file `lightningd.sqlite3` is written to the destination.
|
||||
When `encrypt` is `true`, directory `lightningd-db` is written to the destination.
|
||||
It includes the encrypted database and gocryptfs metadata.
|
||||
|
||||
See also: https://github.com/ElementsProject/lightning/blob/master/doc/BACKUP.md
|
||||
'';
|
||||
};
|
||||
sshfs = {
|
||||
destination = mkOption {
|
||||
type = types.nullOr types.str;
|
||||
default = null;
|
||||
example = "user@10.0.0.1:directory";
|
||||
description = ''
|
||||
The SSH destination for which a SSHFS will be mounted.
|
||||
`directory` is relative to the home of `user`.
|
||||
|
||||
A SSH key is automatically generated and stored in file
|
||||
`$secretsDir/clightning-replication-ssh`.
|
||||
The SSH server must allow logins via this key.
|
||||
I.e., the `authorized_keys` file of `user` must contain
|
||||
`$secretsDir/clightning-replication-ssh.pub`.
|
||||
'';
|
||||
};
|
||||
port = mkOption {
|
||||
type = types.port;
|
||||
default = 22;
|
||||
description = "SSH port of the remote server.";
|
||||
};
|
||||
sshOptions = mkOption {
|
||||
type = with types; listOf str;
|
||||
default = [ "reconnect" "ServerAliveInterval=50" ];
|
||||
description = "SSH options used for mounting the SSHFS.";
|
||||
};
|
||||
};
|
||||
local = {
|
||||
directory = mkOption {
|
||||
type = types.nullOr types.path;
|
||||
default = null;
|
||||
example = "/var/backup/clightning";
|
||||
description = ''
|
||||
This option can be specified instead of `sshfs.destination` to enable
|
||||
replication to a local directory.
|
||||
|
||||
If `local.setupDirectory` is disabled, the directory
|
||||
- must already exist when `clightning.service` (or `clightning-replication-mounts.service`
|
||||
if `encrypt` is `true`) starts.
|
||||
- must have write permissions for the `clightning` user.
|
||||
|
||||
This option is also useful if you want to use a custom remote destination,
|
||||
like a NFS or SMB share.
|
||||
'';
|
||||
};
|
||||
setupDirectory = mkOption {
|
||||
type = types.bool;
|
||||
default = true;
|
||||
description = ''
|
||||
Create `local.directory` if it doesn't exist and set write permissions
|
||||
for the `clightning` user.
|
||||
'';
|
||||
};
|
||||
};
|
||||
encrypt = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description = ''
|
||||
Whether to encrypt the replicated database with gocryptfs.
|
||||
The encryption password is automatically generated and stored
|
||||
in file {file}`$secretsDir/clightning-replication-password`.
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
cfg = config.services.clightning.replication;
|
||||
inherit (config.services) clightning;
|
||||
|
||||
secretsDir = config.nix-bitcoin.secretsDir;
|
||||
network = config.services.bitcoind.makeNetworkName "bitcoin" "regtest";
|
||||
user = clightning.user;
|
||||
group = clightning.group;
|
||||
|
||||
useSshfs = cfg.sshfs.destination != null;
|
||||
useMounts = useSshfs || cfg.encrypt;
|
||||
|
||||
localDir = cfg.local.directory;
|
||||
mountsDir = "/var/cache/clightning-replication";
|
||||
sshfsDir = "${mountsDir}/sshfs";
|
||||
plaintextDir = "${mountsDir}/plaintext";
|
||||
destDir =
|
||||
if cfg.encrypt then
|
||||
plaintextDir
|
||||
else if useSshfs then
|
||||
sshfsDir
|
||||
else
|
||||
localDir;
|
||||
in {
|
||||
inherit options;
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
assertions = [
|
||||
{ assertion = useSshfs || (localDir != null);
|
||||
message = ''
|
||||
services.clightning.replication: One of `sshfs.destination` or
|
||||
`local.directory` must be set.
|
||||
'';
|
||||
}
|
||||
{ assertion = !useSshfs || (localDir == null);
|
||||
message = ''
|
||||
services.clightning.replication: Only one of `sshfs.destination` and
|
||||
`local.directory` must be set.
|
||||
'';
|
||||
}
|
||||
];
|
||||
|
||||
environment.systemPackages = optionals cfg.encrypt [ pkgs.gocryptfs ];
|
||||
|
||||
systemd.tmpfiles.rules = optional (localDir != null && cfg.local.setupDirectory)
|
||||
"d '${localDir}' 0770 ${user} ${group} - -";
|
||||
|
||||
services.clightning.wallet = let
|
||||
mainDB = "${clightning.dataDir}/${network}/lightningd.sqlite3";
|
||||
replicaDB = "${destDir}/lightningd.sqlite3";
|
||||
in "sqlite3://${mainDB}:${replicaDB}";
|
||||
|
||||
systemd.services.clightning = {
|
||||
bindsTo = mkIf useMounts [ "clightning-replication-mounts.service" ];
|
||||
serviceConfig.ReadWritePaths = [
|
||||
# We can't simply set `destDir` here because it might point to
|
||||
# a FUSE mount.
|
||||
# FUSE mounts can only be set up as `ReadWritePaths` by systemd when they
|
||||
# are accessible by root.
|
||||
# But FUSE mounts are only accessible by the mounting user and
|
||||
# not by root.
|
||||
# (This could be circumvented by FUSE-mounting `destDir` with option `allow_other`,
|
||||
# but this would grant access to all users.)
|
||||
(if useMounts then mountsDir else localDir)
|
||||
];
|
||||
};
|
||||
|
||||
systemd.services.clightning-replication-mounts = mkIf useMounts {
|
||||
requiredBy = [ "clightning.service" ];
|
||||
before = [ "clightning.service" ];
|
||||
wants = [ "nix-bitcoin-secrets.target" ];
|
||||
after = [ "nix-bitcoin-secrets.target" ];
|
||||
path = [
|
||||
# Includes
|
||||
# - The SUID-wrapped `fusermount` binary which enables FUSE
|
||||
# for non-root users
|
||||
# - The SUID-wrapped `mount` binary, used for unmounting
|
||||
"/run/wrappers"
|
||||
] ++ optionals cfg.encrypt [
|
||||
# Includes `logger`, required by gocryptfs
|
||||
pkgs.util-linux
|
||||
];
|
||||
|
||||
script =
|
||||
optionalString useSshfs ''
|
||||
mkdir -p ${sshfsDir}
|
||||
${pkgs.sshfs}/bin/sshfs ${cfg.sshfs.destination} -p ${toString cfg.sshfs.port} ${sshfsDir} \
|
||||
-o ${builtins.concatStringsSep "," ([
|
||||
"IdentityFile='${secretsDir}'/clightning-replication-ssh-key"
|
||||
] ++ cfg.sshfs.sshOptions)}
|
||||
'' +
|
||||
optionalString cfg.encrypt ''
|
||||
cipherDir="${if useSshfs then sshfsDir else localDir}/lightningd-db"
|
||||
mkdir -p "$cipherDir" ${plaintextDir}
|
||||
gocryptfs=(${pkgs.gocryptfs}/bin/gocryptfs -passfile '${secretsDir}/clightning-replication-password')
|
||||
# 1. init
|
||||
if [[ ! -e $cipherDir/gocryptfs.conf ]]; then
|
||||
"''${gocryptfs[@]}" -init "$cipherDir"
|
||||
fi
|
||||
# 2. mount
|
||||
"''${gocryptfs[@]}" "$cipherDir" ${plaintextDir}
|
||||
'';
|
||||
|
||||
postStop =
|
||||
optionalString cfg.encrypt ''
|
||||
umount ${plaintextDir} || true
|
||||
'' +
|
||||
optionalString useSshfs ''
|
||||
umount ${sshfsDir}
|
||||
'';
|
||||
|
||||
serviceConfig = {
|
||||
StopPropagatedFrom = [ "clightning.service" ];
|
||||
CacheDirectory = "clightning-replication";
|
||||
CacheDirectoryMode = "770";
|
||||
User = user;
|
||||
RemainAfterExit = "yes";
|
||||
Type = "oneshot";
|
||||
};
|
||||
};
|
||||
|
||||
nix-bitcoin = mkMerge [
|
||||
(mkIf useSshfs {
|
||||
secrets.clightning-replication-ssh-key = {
|
||||
user = user;
|
||||
permissions = "400";
|
||||
};
|
||||
generateSecretsCmds.clightning-replication-ssh-key = ''
|
||||
if [[ ! -f clightning-replication-ssh-key ]]; then
|
||||
${pkgs.openssh}/bin/ssh-keygen -t ed25519 -q -N "" -C "" -f clightning-replication-ssh-key
|
||||
fi
|
||||
'';
|
||||
})
|
||||
|
||||
(mkIf cfg.encrypt {
|
||||
secrets.clightning-replication-password.user = user;
|
||||
generateSecretsCmds.clightning-replication-password = ''
|
||||
makePasswordSecret clightning-replication-password
|
||||
'';
|
||||
})
|
||||
];
|
||||
};
|
||||
}
|
||||
@@ -1,105 +0,0 @@
|
||||
{ config, lib, pkgs, ... }:
|
||||
|
||||
with lib;
|
||||
let
|
||||
options.services.clightning-rest = {
|
||||
enable = mkEnableOption "lightning-rest";
|
||||
port = mkOption {
|
||||
type = types.port;
|
||||
default = 3001;
|
||||
description = "REST server port.";
|
||||
};
|
||||
docPort = mkOption {
|
||||
type = types.port;
|
||||
default = 4001;
|
||||
description = "Swagger API documentation server port.";
|
||||
};
|
||||
dataDir = mkOption {
|
||||
type = types.path;
|
||||
default = "/var/lib/clightning-rest";
|
||||
description = "The data directory for clightning-rest.";
|
||||
};
|
||||
extraConfig = mkOption {
|
||||
type = types.attrs;
|
||||
default = {};
|
||||
example = {
|
||||
DOMAIN = "mynode.org";
|
||||
};
|
||||
description = ''
|
||||
Extra config options.
|
||||
See: https://github.com/Ride-The-Lightning/c-lightning-REST#option-1-via-config-file-cl-rest-configjson
|
||||
'';
|
||||
};
|
||||
# Used by ./rtl.nix
|
||||
group = mkOption {
|
||||
readOnly = true;
|
||||
default = clightning.group;
|
||||
description = "The group under which clightning-rest is run.";
|
||||
};
|
||||
# Rest server address.
|
||||
# Not configurable. The server always listens on all interfaces:
|
||||
# https://github.com/Ride-The-Lightning/c-lightning-REST/issues/84
|
||||
# Required by netns-isolation.
|
||||
address = mkOption {
|
||||
internal = true;
|
||||
default = "0.0.0.0";
|
||||
};
|
||||
tor.enforce = nbLib.tor.enforce;
|
||||
};
|
||||
|
||||
cfg = config.services.clightning-rest;
|
||||
nbLib = config.nix-bitcoin.lib;
|
||||
nbPkgs = config.nix-bitcoin.pkgs;
|
||||
|
||||
inherit (config.services)
|
||||
bitcoind
|
||||
clightning;
|
||||
|
||||
configFile = builtins.toFile "clightning-rest-config" (builtins.toJSON ({
|
||||
PORT = cfg.port;
|
||||
DOCPORT = cfg.docPort;
|
||||
LNRPCPATH = "${clightning.dataDir}/${bitcoind.makeNetworkName "bitcoin" "regtest"}/lightning-rpc";
|
||||
EXECMODE = "production";
|
||||
PROTOCOL = "https";
|
||||
RPCCOMMANDS = ["*"];
|
||||
} // cfg.extraConfig));
|
||||
in {
|
||||
inherit options;
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
services.clightning.enable = true;
|
||||
|
||||
systemd.tmpfiles.rules = [
|
||||
"d '${cfg.dataDir}' 0770 ${clightning.user} ${cfg.group} - -"
|
||||
];
|
||||
|
||||
systemd.services.clightning-rest = mkIf cfg.enable {
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
wants = [ "clightning.service" ];
|
||||
after = [ "clightning.service" ];
|
||||
path = [ pkgs.openssl ];
|
||||
environment.CL_REST_STATE_DIR = cfg.dataDir;
|
||||
preStart = ''
|
||||
ln -sfn ${configFile} cl-rest-config.json
|
||||
'';
|
||||
postStart = ''
|
||||
while [[ ! -e '${cfg.dataDir}/certs/access.macaroon' ]]; do
|
||||
sleep 0.1
|
||||
done
|
||||
'';
|
||||
serviceConfig = nbLib.defaultHardening // {
|
||||
# clightning-rest reads the config file from the working directory
|
||||
WorkingDirectory = cfg.dataDir;
|
||||
ExecStart = "${nbPkgs.clightning-rest}/bin/cl-rest";
|
||||
# Show "clightning-rest" instead of "node" in the journal
|
||||
SyslogIdentifier = "clightning-rest";
|
||||
User = clightning.user;
|
||||
Restart = "on-failure";
|
||||
RestartSec = "10s";
|
||||
ReadWritePaths = [ cfg.dataDir ];
|
||||
inherit (nbLib.allowNetlink) RestrictAddressFamilies;
|
||||
} // nbLib.allowedIPAddresses cfg.tor.enforce
|
||||
// nbLib.nodejs;
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -1,208 +0,0 @@
|
||||
{ config, lib, pkgs, ... }:
|
||||
|
||||
with lib;
|
||||
let
|
||||
options.services.clightning = {
|
||||
enable = mkEnableOption "clightning, a Lightning Network implementation in C";
|
||||
address = mkOption {
|
||||
type = types.str;
|
||||
default = "127.0.0.1";
|
||||
description = "Address to listen for peer connections.";
|
||||
};
|
||||
port = mkOption {
|
||||
type = types.port;
|
||||
default = 9735;
|
||||
description = "Port to listen for peer connections.";
|
||||
};
|
||||
proxy = mkOption {
|
||||
type = types.nullOr types.str;
|
||||
default = if cfg.tor.proxy then config.nix-bitcoin.torClientAddressWithPort else null;
|
||||
description = ''
|
||||
Socks proxy for connecting to Tor nodes (or for all connections if option always-use-proxy is set).
|
||||
'';
|
||||
};
|
||||
always-use-proxy = mkOption {
|
||||
type = types.bool;
|
||||
default = cfg.tor.proxy;
|
||||
description = ''
|
||||
Always use the proxy, even to connect to normal IP addresses.
|
||||
You can still connect to Unix domain sockets manually.
|
||||
This also disables all DNS lookups, to avoid leaking address information.
|
||||
'';
|
||||
};
|
||||
dataDir = mkOption {
|
||||
type = types.path;
|
||||
default = "/var/lib/clightning";
|
||||
description = "The data directory for clightning.";
|
||||
};
|
||||
networkDir = mkOption {
|
||||
readOnly = true;
|
||||
default = "${cfg.dataDir}/${network}";
|
||||
description = "The network data directory.";
|
||||
};
|
||||
wallet = mkOption {
|
||||
type = types.nullOr types.str;
|
||||
default = null;
|
||||
example = "sqlite3:///var/lib/clightning/bitcoin/lightningd.sqlite3";
|
||||
description = ''
|
||||
Wallet data scheme (sqlite3 or postgres) and location/connection
|
||||
parameters, as fully qualified data source name.
|
||||
'';
|
||||
};
|
||||
useBcliPlugin = mkOption {
|
||||
type = types.bool;
|
||||
default = true;
|
||||
description = ''
|
||||
Use bitcoind (via plugin `bcli`) for getting block data.
|
||||
This option is disabled by plugins that use other sources for
|
||||
fetching block data, like `trustedcoin`.
|
||||
'';
|
||||
};
|
||||
extraConfig = mkOption {
|
||||
type = types.lines;
|
||||
default = "";
|
||||
example = ''
|
||||
alias=mynode
|
||||
'';
|
||||
description = ''
|
||||
Extra lines appended to the configuration file.
|
||||
|
||||
See all available options at
|
||||
https://github.com/ElementsProject/lightning/blob/master/doc/lightningd-config.5.md
|
||||
or by running {command}`lightningd --help`.
|
||||
'';
|
||||
};
|
||||
user = mkOption {
|
||||
type = types.str;
|
||||
default = "clightning";
|
||||
description = "The user as which to run clightning.";
|
||||
};
|
||||
group = mkOption {
|
||||
type = types.str;
|
||||
default = cfg.user;
|
||||
description = "The group as which to run clightning.";
|
||||
};
|
||||
package = mkOption {
|
||||
type = types.package;
|
||||
default = nbPkgs.clightning;
|
||||
defaultText = "config.nix-bitcoin.pkgs.clightning";
|
||||
description = "The package providing clightning binaries.";
|
||||
};
|
||||
cli = mkOption {
|
||||
readOnly = true;
|
||||
default = pkgs.writers.writeBashBin "lightning-cli" ''
|
||||
${cfg.package}/bin/lightning-cli --lightning-dir='${cfg.dataDir}' "$@"
|
||||
'';
|
||||
defaultText = "(See source)";
|
||||
description = "Binary to connect with the clightning instance.";
|
||||
};
|
||||
getPublicAddressCmd = mkOption {
|
||||
type = types.str;
|
||||
default = "";
|
||||
description = ''
|
||||
Bash expression which outputs the public service address to announce to peers.
|
||||
If left empty, no address is announced.
|
||||
'';
|
||||
};
|
||||
tor = nbLib.tor;
|
||||
};
|
||||
|
||||
cfg = config.services.clightning;
|
||||
nbLib = config.nix-bitcoin.lib;
|
||||
nbPkgs = config.nix-bitcoin.pkgs;
|
||||
|
||||
inherit (config.services) bitcoind;
|
||||
|
||||
network = bitcoind.makeNetworkName "bitcoin" "regtest";
|
||||
configFile = pkgs.writeText "config" ''
|
||||
network=${network}
|
||||
${optionalString (!cfg.useBcliPlugin) "disable-plugin=bcli"}
|
||||
${optionalString (cfg.proxy != null) "proxy=${cfg.proxy}"}
|
||||
always-use-proxy=${boolToString cfg.always-use-proxy}
|
||||
bind-addr=${cfg.address}:${toString cfg.port}
|
||||
bitcoin-rpcconnect=${nbLib.address bitcoind.rpc.address}
|
||||
bitcoin-rpcport=${toString bitcoind.rpc.port}
|
||||
bitcoin-rpcuser=${bitcoind.rpc.users.public.name}
|
||||
rpc-file-mode=0660
|
||||
log-timestamps=false
|
||||
${optionalString (cfg.wallet != null) "wallet=${cfg.wallet}"}
|
||||
${ # TODO-EXTERNAL: When updating from a version of clightning before 22.11
|
||||
# to version 22.11.1, then the database upgrade needs to be allowed
|
||||
# explicitly. Remove this when it's unlikely that this module is used
|
||||
# with a clightning version 22.11.1 package.
|
||||
optionalString (cfg.package.version == "22.11.1") "database-upgrade=true"}
|
||||
${cfg.extraConfig}
|
||||
'';
|
||||
|
||||
# If a public clightning onion service is enabled, use the onion port as the public port
|
||||
publicPort = if (config.nix-bitcoin.onionServices.clightning.enable or false)
|
||||
&& config.nix-bitcoin.onionServices.clightning.public
|
||||
then
|
||||
(builtins.elemAt config.services.tor.relay.onionServices.clightning.map 0).port
|
||||
else
|
||||
cfg.port;
|
||||
in {
|
||||
inherit options;
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
services.bitcoind = {
|
||||
enable = true;
|
||||
# Increase rpc thread count due to reports that lightning implementations fail
|
||||
# under high bitcoind rpc load
|
||||
rpc.threads = 16;
|
||||
};
|
||||
|
||||
environment.systemPackages = [ cfg.package (hiPrio cfg.cli) ];
|
||||
|
||||
systemd.tmpfiles.rules = [
|
||||
"d '${cfg.dataDir}' 0770 ${cfg.user} ${cfg.group} - -"
|
||||
];
|
||||
|
||||
systemd.services.clightning = {
|
||||
path = [ bitcoind.package ];
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
requires = [ "bitcoind.service" ];
|
||||
after = [ "bitcoind.service" "nix-bitcoin-secrets.target" ];
|
||||
preStart = ''
|
||||
# Remove an existing socket so that `postStart` can detect when when a new
|
||||
# socket has been created and clightning is ready to accept RPC connections.
|
||||
# This will no longer be needed when clightning supports systemd startup notifications.
|
||||
rm -f ${cfg.networkDir}/lightning-rpc
|
||||
|
||||
umask u=rw,g=r,o=
|
||||
{
|
||||
cat ${configFile}
|
||||
echo "bitcoin-rpcpassword=$(cat ${config.nix-bitcoin.secretsDir}/bitcoin-rpcpassword-public)"
|
||||
${optionalString (cfg.getPublicAddressCmd != "") ''
|
||||
echo "announce-addr=$(${cfg.getPublicAddressCmd}):${toString publicPort}"
|
||||
''}
|
||||
} > '${cfg.dataDir}/config'
|
||||
'';
|
||||
serviceConfig = nbLib.defaultHardening // {
|
||||
ExecStart = "${cfg.package}/bin/lightningd --lightning-dir=${cfg.dataDir}";
|
||||
User = cfg.user;
|
||||
Restart = "on-failure";
|
||||
RestartSec = "10s";
|
||||
ReadWritePaths = [ cfg.dataDir ];
|
||||
# DB upgrades or recovery after a crash can take a while
|
||||
TimeoutStartSec = "10m";
|
||||
} // nbLib.allowedIPAddresses cfg.tor.enforce;
|
||||
# Wait until the rpc socket appears
|
||||
postStart = ''
|
||||
while [[ ! -e ${cfg.networkDir}/lightning-rpc ]]; do
|
||||
sleep 0.1
|
||||
done
|
||||
# Needed to enable lightning-cli for users with group 'clightning'
|
||||
chmod g+x ${cfg.networkDir}
|
||||
'';
|
||||
};
|
||||
|
||||
users.users.${cfg.user} = {
|
||||
isSystemUser = true;
|
||||
group = cfg.group;
|
||||
extraGroups = [ "bitcoinrpc-public" ];
|
||||
};
|
||||
users.groups.${cfg.group} = {};
|
||||
nix-bitcoin.operator.groups = [ cfg.group ];
|
||||
};
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
{ lib, ... }:
|
||||
{
|
||||
nix-bitcoin = {
|
||||
secretsDir = "/var/src/secrets";
|
||||
setupSecrets = true;
|
||||
};
|
||||
environment.variables.NIX_PATH = lib.mkForce "/var/src";
|
||||
|
||||
# The file syncing step in krops resets the secrets file permissions.
|
||||
# So force `setup-secrets.service` to restart on deployment.
|
||||
# Stop it at activation start so that it gets restarted at the end.
|
||||
system.activationScripts.nixBitcoinStopSetupSecrets = ''
|
||||
${/* Skip this step if systemd is not running, i.e. when booting or in nixos-install */ ""}
|
||||
if [[ -e /run/systemd/system ]]; then
|
||||
if ! output=$(/run/current-system/systemd/bin/systemctl stop setup-secrets.service --no-block 2>&1); then
|
||||
# Ignore if the unit is not loaded, which can happen on the first deployment
|
||||
if [[ $output != *setup-secrets.service\ not\ loaded* ]]; then
|
||||
echo "$output"
|
||||
false
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
'';
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
{ config, ... }:
|
||||
{
|
||||
nix-bitcoin.secretsSetupMethod = "nixops";
|
||||
|
||||
deployment.keys = builtins.mapAttrs (n: v: {
|
||||
keyFile = "${config.nix-bitcoin.deployment.secretsDir}/${n}";
|
||||
destDir = config.nix-bitcoin.secretsDir;
|
||||
inherit (v) user group permissions;
|
||||
}) config.nix-bitcoin.secrets;
|
||||
|
||||
# nixops makes the secrets directory accessible only for users with group 'key'.
|
||||
# For compatibility with other deployment methods besides nixops, we forego the
|
||||
# use of the 'key' group and make the secrets dir world-readable instead.
|
||||
# This is safe because all containing files have their specific private
|
||||
# permissions set.
|
||||
systemd.services.allowSecretsDirAccess = {
|
||||
requires = [ "keys.target" ];
|
||||
after = [ "keys.target" ];
|
||||
script = "chmod o+x ${config.nix-bitcoin.secretsDir}";
|
||||
serviceConfig.Type = "oneshot";
|
||||
};
|
||||
|
||||
systemd.targets.nix-bitcoin-secrets = {
|
||||
requires = [ "allowSecretsDirAccess.service" ];
|
||||
after = [ "allowSecretsDirAccess.service" ];
|
||||
};
|
||||
}
|
||||
@@ -1,140 +0,0 @@
|
||||
{ config, lib, pkgs, ... }:
|
||||
|
||||
with lib;
|
||||
let
|
||||
options.services.fulcrum = {
|
||||
enable = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description = ''
|
||||
Enable fulcrum, an Electrum server implemented in C++.
|
||||
|
||||
Compared to electrs, fulcrum has a 3x larger database size but
|
||||
can serve arbitrary address queries instantly.
|
||||
|
||||
fulcrum also enables `txindex` in bitcoind (this is a requirement),
|
||||
which increases the bitcoind datadir size by 8% of the `blocks` size.
|
||||
|
||||
This module disables peering (a distributed list of electrum servers that can
|
||||
be queried by clients), but you can manually enable it via option
|
||||
{option}`extraConfig`.
|
||||
'';
|
||||
};
|
||||
address = mkOption {
|
||||
type = types.str;
|
||||
default = "127.0.0.1";
|
||||
description = "Address to listen for RPC connections.";
|
||||
};
|
||||
port = mkOption {
|
||||
type = types.port;
|
||||
default = 50001;
|
||||
description = "Port to listen for RPC connections.";
|
||||
};
|
||||
dataDir = mkOption {
|
||||
type = types.path;
|
||||
default = "/var/lib/fulcrum";
|
||||
description = "The data directory for fulcrum.";
|
||||
};
|
||||
extraConfig = mkOption {
|
||||
type = types.lines;
|
||||
default = "";
|
||||
example = ''
|
||||
peering = true
|
||||
'';
|
||||
description = ''
|
||||
Extra lines appended to the configuration file.
|
||||
|
||||
See all available options at
|
||||
https://github.com/cculianu/Fulcrum/blob/master/doc/fulcrum-example-config.conf
|
||||
'';
|
||||
};
|
||||
user = mkOption {
|
||||
type = types.str;
|
||||
default = "fulcrum";
|
||||
description = "The user as which to run fulcrum.";
|
||||
};
|
||||
group = mkOption {
|
||||
type = types.str;
|
||||
default = cfg.user;
|
||||
description = "The group as which to run fulcrum.";
|
||||
};
|
||||
tor.enforce = nbLib.tor.enforce;
|
||||
};
|
||||
|
||||
cfg = config.services.fulcrum;
|
||||
nbLib = config.nix-bitcoin.lib;
|
||||
secretsDir = config.nix-bitcoin.secretsDir;
|
||||
bitcoind = config.services.bitcoind;
|
||||
|
||||
configFile = builtins.toFile "fulcrum.conf" ''
|
||||
datadir = ${cfg.dataDir}
|
||||
tcp = ${cfg.address}:${toString cfg.port}
|
||||
|
||||
bitcoind = ${nbLib.addressWithPort bitcoind.rpc.address bitcoind.rpc.port}
|
||||
rpcuser = ${bitcoind.rpc.users.public.name}
|
||||
|
||||
# Disable logging timestamps
|
||||
ts-format = none
|
||||
|
||||
peering = false
|
||||
|
||||
${cfg.extraConfig}
|
||||
'';
|
||||
in {
|
||||
inherit options;
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
assertions = [
|
||||
{ assertion = bitcoind.prune == 0;
|
||||
message = "Fulcrum does not support bitcoind pruning.";
|
||||
}
|
||||
{ assertion =
|
||||
!(config.services ? electrs)
|
||||
|| !config.services.electrs.enable
|
||||
|| config.services.electrs.port != cfg.port;
|
||||
message = ''
|
||||
Fulcrum and Electrs can't both bind to TCP RPC port ${cfg.port}.
|
||||
Change `services.electrs.port` or `services.fulcrum.port`
|
||||
to a port other than ${cfg.port}.
|
||||
'';
|
||||
}
|
||||
];
|
||||
|
||||
services.bitcoind = {
|
||||
enable = true;
|
||||
txindex = true;
|
||||
};
|
||||
|
||||
systemd.tmpfiles.rules = [
|
||||
"d '${cfg.dataDir}' 0770 ${cfg.user} ${cfg.group} - -"
|
||||
];
|
||||
|
||||
systemd.services.fulcrum = {
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
wants = [ "bitcoind.service" ];
|
||||
after = [ "bitcoind.service" "nix-bitcoin-secrets.target" ];
|
||||
preStart = ''
|
||||
{
|
||||
cat ${configFile}
|
||||
echo "rpcpassword = $(cat ${secretsDir}/bitcoin-rpcpassword-public)"
|
||||
} > '${cfg.dataDir}/fulcrum.conf'
|
||||
'';
|
||||
serviceConfig = nbLib.defaultHardening // {
|
||||
ExecStart = "${config.nix-bitcoin.pkgs.fulcrum}/bin/Fulcrum '${cfg.dataDir}/fulcrum.conf'";
|
||||
User = cfg.user;
|
||||
Group = cfg.group;
|
||||
Restart = "on-failure";
|
||||
RestartSec = "10s";
|
||||
ReadWritePaths = cfg.dataDir;
|
||||
ProcSubset = "all"; # Fulcrum requires read access to /proc/meminfo
|
||||
} // nbLib.allowedIPAddresses cfg.tor.enforce;
|
||||
};
|
||||
|
||||
users.users.${cfg.user} = {
|
||||
isSystemUser = true;
|
||||
group = cfg.group;
|
||||
extraGroups = [ "bitcoinrpc-public" ];
|
||||
};
|
||||
users.groups.${cfg.group} = {};
|
||||
};
|
||||
}
|
||||
@@ -1,84 +0,0 @@
|
||||
{ config, lib, pkgs, ... }:
|
||||
|
||||
with lib;
|
||||
let
|
||||
options.services.hardware-wallets = {
|
||||
ledger = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description = ''
|
||||
If enabled, the ledger udev rules will be installed.
|
||||
'';
|
||||
};
|
||||
trezor = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description = ''
|
||||
If enabled, the trezor udev rules will be installed.
|
||||
'';
|
||||
};
|
||||
group = mkOption {
|
||||
type = types.str;
|
||||
default = "hardware-wallets";
|
||||
description = ''
|
||||
Group the hardware wallet udev rules apply to.
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
cfg = config.services.hardware-wallets;
|
||||
in {
|
||||
inherit options;
|
||||
|
||||
config = mkMerge [
|
||||
(mkIf (cfg.ledger || cfg.trezor) {
|
||||
assertions = [
|
||||
{ assertion = (config.services.bitcoind.disablewallet == null || !config.services.bitcoind.disablewallet);
|
||||
message = ''
|
||||
Hardware-Wallets are not compatible with bitcoind.disablewallet.
|
||||
'';
|
||||
}
|
||||
];
|
||||
|
||||
environment.systemPackages = [
|
||||
config.nix-bitcoin.pkgs.hwi
|
||||
# Provides lsusb for debugging
|
||||
pkgs.usbutils
|
||||
];
|
||||
|
||||
users.groups.${cfg.group} = {};
|
||||
nix-bitcoin.operator.groups = [ cfg.group ];
|
||||
})
|
||||
|
||||
(mkIf cfg.ledger {
|
||||
# Ledger Nano S according to https://github.com/LedgerHQ/udev-rules/blob/master/add_udev_rules.sh
|
||||
# Don't use rules from nixpkgs because we want to use our own group.
|
||||
services.udev.packages = lib.singleton (pkgs.writeTextFile {
|
||||
name = "ledger-udev-rules";
|
||||
destination = "/etc/udev/rules.d/20-ledger.rules";
|
||||
text = ''
|
||||
SUBSYSTEMS=="usb", ATTRS{idVendor}=="2c97", ATTRS{idProduct}=="0001", MODE="0660", GROUP="${cfg.group}"
|
||||
'';
|
||||
});
|
||||
})
|
||||
(mkIf cfg.trezor {
|
||||
environment.systemPackages = [ config.nix-bitcoin.pkgs.pyPkgs.nbPython3PackagesWithUnlockedEcdsa.trezor ];
|
||||
# Don't use rules from nixpkgs because we want to use our own group.
|
||||
services.udev.packages = lib.singleton (pkgs.writeTextFile {
|
||||
name = "trezord-udev-rules";
|
||||
destination = "/etc/udev/rules.d/52-trezor.rules";
|
||||
text = ''
|
||||
# TREZOR v1 (One)
|
||||
SUBSYSTEM=="usb", ATTR{idVendor}=="534c", ATTR{idProduct}=="0001", MODE="0660", GROUP="${cfg.group}", TAG+="uaccess", SYMLINK+="trezor%n"
|
||||
KERNEL=="hidraw*", ATTRS{idVendor}=="534c", ATTRS{idProduct}=="0001", MODE="0660", GROUP="${cfg.group}", TAG+="uaccess"
|
||||
|
||||
# TREZOR v2 (T)
|
||||
SUBSYSTEM=="usb", ATTR{idVendor}=="1209", ATTR{idProduct}=="53c0", MODE="0660", GROUP="${cfg.group}", TAG+="uaccess", SYMLINK+="trezor%n"
|
||||
SUBSYSTEM=="usb", ATTR{idVendor}=="1209", ATTR{idProduct}=="53c1", MODE="0660", GROUP="${cfg.group}", TAG+="uaccess", SYMLINK+="trezor%n"
|
||||
KERNEL=="hidraw*", ATTRS{idVendor}=="1209", ATTRS{idProduct}=="53c1", MODE="0660", GROUP="${cfg.group}", TAG+="uaccess"
|
||||
'';
|
||||
});
|
||||
services.trezord.enable = true;
|
||||
})
|
||||
];
|
||||
}
|
||||
@@ -1,133 +0,0 @@
|
||||
{ config, lib, pkgs, ... }:
|
||||
|
||||
with lib;
|
||||
let
|
||||
options.services.joinmarket-ob-watcher = {
|
||||
enable = mkEnableOption "JoinMarket orderbook watcher";
|
||||
address = mkOption {
|
||||
type = types.str;
|
||||
default = "127.0.0.1";
|
||||
description = "HTTP server address.";
|
||||
};
|
||||
port = mkOption {
|
||||
type = types.port;
|
||||
default = 62601;
|
||||
description = "HTTP server port.";
|
||||
};
|
||||
dataDir = mkOption {
|
||||
readOnly = true;
|
||||
default = "/var/lib/joinmarket-ob-watcher";
|
||||
description = "The data directory for JoinMarket orderbook watcher.";
|
||||
};
|
||||
settings = mkOption {
|
||||
type = with types; attrsOf anything;
|
||||
example = {
|
||||
LOGGING = {
|
||||
console_log_level = "DEBUG";
|
||||
};
|
||||
};
|
||||
description = ''
|
||||
Joinmarket settings.
|
||||
See here for possible options:
|
||||
https://github.com/JoinMarket-Org/joinmarket-clientserver/blob/v0.9.11/src/jmclient/configure.py#L98
|
||||
'';
|
||||
};
|
||||
user = mkOption {
|
||||
type = types.str;
|
||||
default = "joinmarket-ob-watcher";
|
||||
description = "The user as which to run JoinMarket.";
|
||||
};
|
||||
group = mkOption {
|
||||
type = types.str;
|
||||
default = cfg.user;
|
||||
description = "The group as which to run JoinMarket.";
|
||||
};
|
||||
# This option is only used by netns-isolation.
|
||||
# Tor is always enabled.
|
||||
tor.enforce = nbLib.tor.enforce;
|
||||
};
|
||||
|
||||
cfg = config.services.joinmarket-ob-watcher;
|
||||
nbLib = config.nix-bitcoin.lib;
|
||||
nbPkgs = config.nix-bitcoin.pkgs;
|
||||
secretsDir = config.nix-bitcoin.secretsDir;
|
||||
|
||||
inherit (config.services) bitcoind joinmarket;
|
||||
in {
|
||||
inherit options;
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
services.bitcoind.rpc.users.joinmarket-ob-watcher = {
|
||||
passwordHMACFromFile = true;
|
||||
rpcwhitelist = bitcoind.rpc.users.public.rpcwhitelist ++ [
|
||||
"listwallets"
|
||||
];
|
||||
};
|
||||
|
||||
# Joinmarket is Tor-only
|
||||
services.tor = {
|
||||
enable = true;
|
||||
client.enable = true;
|
||||
};
|
||||
|
||||
systemd.tmpfiles.rules = [
|
||||
"d '${cfg.dataDir}' 0770 ${cfg.user} ${cfg.group} - -"
|
||||
];
|
||||
|
||||
services.joinmarket-ob-watcher.settings = {
|
||||
BLOCKCHAIN = config.services.joinmarket.settings.BLOCKCHAIN // {
|
||||
rpc_user = bitcoind.rpc.users.joinmarket-ob-watcher.name;
|
||||
rpc_wallet_file = "";
|
||||
};
|
||||
inherit (config.services.joinmarket.settings)
|
||||
"MESSAGING:onion"
|
||||
"MESSAGING:server1"
|
||||
"MESSAGING:server2"
|
||||
"MESSAGING:server3";
|
||||
};
|
||||
|
||||
systemd.services.joinmarket-ob-watcher = rec {
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
requires = [ "tor.service" "bitcoind.service" ];
|
||||
after = requires ++ [ "nix-bitcoin-secrets.target" ];
|
||||
# The service writes to HOME/.config/matplotlib
|
||||
environment.HOME = cfg.dataDir;
|
||||
preStart = ''
|
||||
{
|
||||
cat ${builtins.toFile "joinmarket-ob-watcher.cfg" ((generators.toINI {}) cfg.settings)}
|
||||
echo
|
||||
echo '[BLOCKCHAIN]'
|
||||
echo "rpc_password = $(cat ${secretsDir}/bitcoin-rpcpassword-joinmarket-ob-watcher)"
|
||||
} > '${cfg.dataDir}/joinmarket.cfg'
|
||||
'';
|
||||
serviceConfig = nbLib.defaultHardening // rec {
|
||||
StateDirectory = "joinmarket-ob-watcher";
|
||||
StateDirectoryMode = "770";
|
||||
WorkingDirectory = cfg.dataDir; # The service creates dir 'logs' in the working dir
|
||||
User = cfg.user;
|
||||
ExecStart = ''
|
||||
${nbPkgs.joinmarket}/bin/jm-ob-watcher --datadir=${cfg.dataDir} \
|
||||
--host=${cfg.address} --port=${toString cfg.port}
|
||||
'';
|
||||
SystemCallFilter = nbLib.defaultHardening.SystemCallFilter ++ [ "mbind" ] ;
|
||||
Restart = "on-failure";
|
||||
RestartSec = "10s";
|
||||
} // nbLib.allowedIPAddresses cfg.tor.enforce;
|
||||
};
|
||||
|
||||
users.users.${cfg.user} = {
|
||||
isSystemUser = true;
|
||||
group = cfg.group;
|
||||
home = cfg.dataDir;
|
||||
};
|
||||
users.groups.${cfg.group} = {};
|
||||
|
||||
nix-bitcoin.secrets = {
|
||||
bitcoin-rpcpassword-joinmarket-ob-watcher.user = cfg.user;
|
||||
bitcoin-HMAC-joinmarket-ob-watcher.user = bitcoind.user;
|
||||
};
|
||||
nix-bitcoin.generateSecretsCmds.joinmarket-ob-watcher = ''
|
||||
makeBitcoinRPCPassword joinmarket-ob-watcher
|
||||
'';
|
||||
};
|
||||
}
|
||||
@@ -1,398 +0,0 @@
|
||||
{ config, lib, pkgs, ... }:
|
||||
|
||||
with lib;
|
||||
let
|
||||
options.services.joinmarket = {
|
||||
enable = mkEnableOption "JoinMarket, a Bitcoin CoinJoin implementation";
|
||||
payjoinAddress = mkOption {
|
||||
type = types.str;
|
||||
default = "127.0.0.1";
|
||||
description = ''
|
||||
The address where payjoin onion connections are forwarded to.
|
||||
This address is never used directly, it only serves as the internal endpoint
|
||||
for the payjoin onion service.
|
||||
The onion service is automatically setup by joinmarket and accepts
|
||||
connections at port 80.
|
||||
'';
|
||||
};
|
||||
payjoinPort = mkOption {
|
||||
type = types.port;
|
||||
default = 64180; # A random private port
|
||||
description = "The port corresponding to option {option}`payjoinAddress`.";
|
||||
};
|
||||
messagingAddress = mkOption {
|
||||
type = types.str;
|
||||
default = "127.0.0.1";
|
||||
description = ''
|
||||
The address where messaging onion connections are forwarded to.
|
||||
This address is never used directly, it only serves as the internal endpoint
|
||||
for the messaging onion service.
|
||||
The onion service is automatically setup by joinmarket.
|
||||
'';
|
||||
};
|
||||
messagingPort = mkOption {
|
||||
type = types.port;
|
||||
default = 64181; # payjoinPort + 1
|
||||
description = "The port corresponding to option {option}`messagingAddress`.";
|
||||
};
|
||||
dataDir = mkOption {
|
||||
type = types.path;
|
||||
default = "/var/lib/joinmarket";
|
||||
description = "The data directory for JoinMarket.";
|
||||
};
|
||||
rpcWalletFile = mkOption {
|
||||
type = types.nullOr types.nonEmptyStr;
|
||||
default = "jm_wallet";
|
||||
description = ''
|
||||
Name of the watch-only bitcoind wallet the JoinMarket addresses are imported to.
|
||||
'';
|
||||
};
|
||||
settings = mkOption {
|
||||
type = with types; attrsOf anything;
|
||||
example = {
|
||||
POLICY = {
|
||||
merge_algorithm = "gradual";
|
||||
tx_fees = 5;
|
||||
};
|
||||
LOGGING = {
|
||||
console_log_level = "DEBUG";
|
||||
};
|
||||
};
|
||||
description = ''
|
||||
Joinmarket settings.
|
||||
See here for possible options:
|
||||
https://raw.githubusercontent.com/JoinMarket-Org/joinmarket-clientserver/master/src/jmclient/configure.py#:~:text=defaultconfig%20=
|
||||
If your web browser does not support text fragment URLs, you can can manually
|
||||
search for string `defaultconfig =` to jump to the correct location.
|
||||
'';
|
||||
};
|
||||
user = mkOption {
|
||||
type = types.str;
|
||||
default = "joinmarket";
|
||||
description = "The user as which to run JoinMarket.";
|
||||
};
|
||||
group = mkOption {
|
||||
type = types.str;
|
||||
default = cfg.user;
|
||||
description = "The group as which to run JoinMarket.";
|
||||
};
|
||||
cli = mkOption {
|
||||
default = cli;
|
||||
defaultText = "(See source)";
|
||||
};
|
||||
# This option is only used by netns-isolation.
|
||||
# Tor is always enabled.
|
||||
tor.enforce = nbLib.tor.enforce;
|
||||
inherit (nbLib) cliExec;
|
||||
|
||||
yieldgenerator = {
|
||||
enable = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description = ''
|
||||
Enable the JoinMarket yield generator bot.
|
||||
Documentation: https://github.com/JoinMarket-Org/joinmarket-clientserver/blob/master/docs/YIELDGENERATOR.md
|
||||
'';
|
||||
};
|
||||
ordertype = mkOption {
|
||||
type = types.enum [ "reloffer" "absoffer" ];
|
||||
default = "reloffer";
|
||||
description = ''
|
||||
Which fee type to actually use.
|
||||
'';
|
||||
};
|
||||
cjfee_a = mkOption {
|
||||
type = types.ints.unsigned;
|
||||
default = 500;
|
||||
description = ''
|
||||
Absolute offer fee you wish to receive for coinjoins (cj) in Satoshis.
|
||||
'';
|
||||
};
|
||||
cjfee_r = mkOption {
|
||||
type = types.float;
|
||||
default = 0.00002;
|
||||
description = ''
|
||||
Relative offer fee you wish to receive based on a cj's amount.
|
||||
'';
|
||||
};
|
||||
cjfee_factor = mkOption {
|
||||
type = types.float;
|
||||
default = 0.1;
|
||||
description = ''
|
||||
Variance around the average cj fee.
|
||||
'';
|
||||
};
|
||||
txfee_contribution_factor = mkOption {
|
||||
type = types.float;
|
||||
default = 0.3;
|
||||
description = ''
|
||||
Variance around the average tx fee.
|
||||
'';
|
||||
};
|
||||
minsize = mkOption {
|
||||
type = types.ints.unsigned;
|
||||
default = 100000;
|
||||
description = ''
|
||||
Minimum size of your cj offer in Satoshis. Lower cj amounts will be disregarded.
|
||||
'';
|
||||
};
|
||||
size_factor = mkOption {
|
||||
type = types.float;
|
||||
default = 0.1;
|
||||
description = ''
|
||||
Variance around all offer sizes.
|
||||
'';
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
cfg = config.services.joinmarket;
|
||||
nbLib = config.nix-bitcoin.lib;
|
||||
nbPkgs = config.nix-bitcoin.pkgs;
|
||||
secretsDir = config.nix-bitcoin.secretsDir;
|
||||
runAsUser = config.nix-bitcoin.runAsUserCmd;
|
||||
|
||||
inherit (config.services) bitcoind;
|
||||
|
||||
torAddress = config.services.tor.client.socksListenAddress;
|
||||
|
||||
socks5Settings = {
|
||||
socks5 = true;
|
||||
socks5_host = torAddress.addr;
|
||||
socks5_port = torAddress.port;
|
||||
};
|
||||
|
||||
# The jm scripts create a 'logs' dir in the working dir,
|
||||
# so run them inside dataDir.
|
||||
cli = pkgs.runCommand "joinmarket-cli" {} ''
|
||||
mkdir -p "$out/bin"
|
||||
jm=${nbPkgs.joinmarket}/bin
|
||||
cd "$jm"
|
||||
for bin in jm-*; do
|
||||
{
|
||||
echo "#!${pkgs.bash}/bin/bash";
|
||||
echo "cd '${cfg.dataDir}' && ${cfg.cliExec} ${runAsUser} ${cfg.user} "$jm/$bin" --datadir='${cfg.dataDir}' \"\$@\"";
|
||||
} > "$out/bin/$bin"
|
||||
done
|
||||
chmod -R +x "$out/bin"
|
||||
'';
|
||||
in {
|
||||
inherit options;
|
||||
|
||||
config = mkMerge [
|
||||
{
|
||||
services.joinmarket.settings = {
|
||||
DAEMON = {
|
||||
no_daemon = 0;
|
||||
daemon_port = 27183;
|
||||
daemon_host = "127.0.0.1";
|
||||
};
|
||||
BLOCKCHAIN = {
|
||||
blockchain_source = bitcoind.makeNetworkName "bitcoin-rpc" "regtest";
|
||||
network = bitcoind.makeNetworkName "mainnet" "testnet";
|
||||
rpc_host = nbLib.address bitcoind.rpc.address;
|
||||
rpc_port = bitcoind.rpc.port;
|
||||
rpc_user = bitcoind.rpc.users.privileged.name;
|
||||
rpc_wallet_file = if cfg.rpcWalletFile == null then "" else cfg.rpcWalletFile;
|
||||
};
|
||||
LOGGING = {
|
||||
color = false;
|
||||
};
|
||||
PAYJOIN = {
|
||||
onion_socks5_host = torAddress.addr;
|
||||
onion_socks5_port = torAddress.port;
|
||||
tor_control_host = "unix:/run/tor/control";
|
||||
onion_serving_host = cfg.payjoinAddress;
|
||||
onion_serving_port = cfg.payjoinPort;
|
||||
hidden_service_ssl = false;
|
||||
};
|
||||
YIELDGENERATOR = removeAttrs cfg.yieldgenerator [
|
||||
"enable"
|
||||
# TODO: This is only needed when ./obsolete-options.nix is imported
|
||||
"txfee"
|
||||
];
|
||||
|
||||
# Messaging settings have to be fully specified because joinmarket doesn't
|
||||
# provide default messaging settings.
|
||||
# (`jmclient/configure.py` actually does contain default messaging settings, but
|
||||
# they are removed via fn `_remove_unwanted_default_settings`)
|
||||
"MESSAGING:onion" = socks5Settings // {
|
||||
type = "onion";
|
||||
tor_control_host = "unix:/run/tor/control";
|
||||
# Required option, but ignored because `tor_control_host` is a unix socket
|
||||
tor_control_port = 9051;
|
||||
onion_serving_host = cfg.messagingAddress;
|
||||
onion_serving_port = cfg.messagingPort;
|
||||
hidden_service_dir = "";
|
||||
directory_nodes = "g3hv4uynnmynqqq2mchf3fcm3yd46kfzmcdogejuckgwknwyq5ya6iad.onion:5222,3kxw6lf5vf6y26emzwgibzhrzhmhqiw6ekrek3nqfjjmhwznb2moonad.onion:5222,bqlpq6ak24mwvuixixitift4yu42nxchlilrcqwk2ugn45tdclg42qid.onion:5222";
|
||||
};
|
||||
# irc.darkscience.net
|
||||
"MESSAGING:server1" = socks5Settings // {
|
||||
host = "darkirc6tqgpnwd3blln3yfv5ckl47eg7llfxkmtovrv7c7iwohhb6ad.onion";
|
||||
channel = "joinmarket-pit";
|
||||
port = 6697;
|
||||
usessl = true;
|
||||
};
|
||||
# ilita
|
||||
"MESSAGING:server2" = socks5Settings // {
|
||||
host = "ilitafrzzgxymv6umx2ux7kbz3imyeko6cnqkvy4nisjjj4qpqkrptid.onion";
|
||||
channel = "joinmarket-pit";
|
||||
port = 6667;
|
||||
usessl = false;
|
||||
};
|
||||
# irc.hackint.org
|
||||
"MESSAGING:server3" = socks5Settings // {
|
||||
host = "ncwkrwxpq2ikcngxq3dy2xctuheniggtqeibvgofixpzvrwpa77tozqd.onion";
|
||||
channel = "joinmarket-pit";
|
||||
port = 6667;
|
||||
usessl = false;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
(mkIf cfg.enable {
|
||||
assertions = [
|
||||
{
|
||||
assertion = lib.versionOlder bitcoind.package.version "30";
|
||||
message = ''
|
||||
Joinmarket is not compatible with bitcoind >= 30.
|
||||
(https://github.com/JoinMarket-Org/joinmarket-clientserver/pull/1775)
|
||||
|
||||
To fix this, add the following to your config:
|
||||
services.bitcoind.package = config.nix-bitcoin.pkgs.bitcoind_29;
|
||||
'';
|
||||
}
|
||||
];
|
||||
|
||||
services.bitcoind = {
|
||||
enable = true;
|
||||
disablewallet = false;
|
||||
# TODO-EXTERNAL: remove when joinmarket supports descriptor wallets
|
||||
# (https://github.com/JoinMarket-Org/joinmarket-clientserver/issues/1571).
|
||||
extraConfig = ''
|
||||
deprecatedrpc=create_bdb
|
||||
'';
|
||||
};
|
||||
|
||||
# Joinmarket is Tor-only
|
||||
services.tor = {
|
||||
enable = true;
|
||||
client.enable = true;
|
||||
# Needed for payjoin onion service creation
|
||||
controlSocket.enable = true;
|
||||
};
|
||||
|
||||
environment.systemPackages = [
|
||||
(hiPrio cfg.cli)
|
||||
];
|
||||
|
||||
systemd.tmpfiles.rules = [
|
||||
"d '${cfg.dataDir}' 0770 ${cfg.user} ${cfg.group} - -"
|
||||
];
|
||||
|
||||
systemd.services.joinmarket = {
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
requires = [ "bitcoind.service" ];
|
||||
after = [ "bitcoind.service" "nix-bitcoin-secrets.target" ];
|
||||
preStart = ''
|
||||
{
|
||||
cat ${builtins.toFile "joinmarket.cfg" ((generators.toINI {}) cfg.settings)}
|
||||
echo
|
||||
echo '[BLOCKCHAIN]'
|
||||
echo "rpc_password = $(cat ${secretsDir}/bitcoin-rpcpassword-privileged)"
|
||||
} > '${cfg.dataDir}/joinmarket.cfg'
|
||||
'';
|
||||
postStart = ''
|
||||
walletname=wallet.jmdat
|
||||
wallet="${cfg.dataDir}/wallets/$walletname"
|
||||
if [[ ! -f $wallet ]]; then
|
||||
${optionalString (cfg.rpcWalletFile != null) ''
|
||||
echo "Create watch-only wallet ${cfg.rpcWalletFile}"
|
||||
if ! output=$(${bitcoind.cli}/bin/bitcoin-cli -named createwallet \
|
||||
wallet_name="${cfg.rpcWalletFile}" \
|
||||
descriptors=false \
|
||||
${optionalString (!bitcoind.regtest) "disable_private_keys=true"} 2>&1
|
||||
); then
|
||||
# Ignore error if bitcoind wallet already exists
|
||||
if [[ $output != *"already exists"* ]]; then
|
||||
echo "$output"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
''}
|
||||
|
||||
# Restore wallet from seed if available
|
||||
seed=()
|
||||
if [[ -e jm-wallet-seed ]]; then
|
||||
seed=(--recovery-seed-file jm-wallet-seed)
|
||||
fi
|
||||
cd "${cfg.dataDir}"
|
||||
|
||||
# Strip trailing newline from password file
|
||||
if ! tr -d '\n' < '${secretsDir}/jm-wallet-password' \
|
||||
| ${nbPkgs.joinmarket}/bin/jm-genwallet \
|
||||
--datadir="${cfg.dataDir}" --wallet-password-stdin "''${seed[@]}" "$walletname" \
|
||||
| (if ((! ''${#seed[@]})); then
|
||||
umask u=r,go=
|
||||
grep -ohP '(?<=recovery_seed:).*' > jm-wallet-seed
|
||||
else
|
||||
cat > /dev/null
|
||||
fi); then
|
||||
echo "wallet creation failed"
|
||||
rm -f "$wallet" jm-wallet-seed
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
'';
|
||||
serviceConfig = nbLib.defaultHardening // {
|
||||
ExecStart = "${nbPkgs.joinmarket}/bin/joinmarketd";
|
||||
WorkingDirectory = cfg.dataDir; # The service creates 'commitmentlist' in the working dir
|
||||
User = cfg.user;
|
||||
Restart = "on-failure";
|
||||
RestartSec = "10s";
|
||||
ReadWritePaths = [ cfg.dataDir ];
|
||||
} // nbLib.allowedIPAddresses cfg.tor.enforce;
|
||||
};
|
||||
|
||||
users.users.${cfg.user} = {
|
||||
isSystemUser = true;
|
||||
group = cfg.group;
|
||||
home = cfg.dataDir;
|
||||
# Allow access to the tor control socket, needed for payjoin onion service creation
|
||||
extraGroups = [ "tor" "bitcoin" ];
|
||||
};
|
||||
users.groups.${cfg.group} = {};
|
||||
nix-bitcoin.operator = {
|
||||
groups = [ cfg.group ];
|
||||
allowRunAsUsers = [ cfg.user ];
|
||||
};
|
||||
|
||||
nix-bitcoin.secrets.jm-wallet-password.user = cfg.user;
|
||||
nix-bitcoin.generateSecretsCmds.joinmarket = ''
|
||||
makePasswordSecret jm-wallet-password
|
||||
'';
|
||||
})
|
||||
|
||||
(mkIf (cfg.enable && cfg.yieldgenerator.enable) {
|
||||
systemd.services.joinmarket-yieldgenerator = {
|
||||
wantedBy = [ "joinmarket.service" ];
|
||||
requires = [ "joinmarket.service" ];
|
||||
after = [ "joinmarket.service" "nix-bitcoin-secrets.target" ];
|
||||
script = ''
|
||||
tr -d "\n" <"${secretsDir}/jm-wallet-password" \
|
||||
| ${nbPkgs.joinmarket}/bin/jm-yg-privacyenhanced --datadir='${cfg.dataDir}' \
|
||||
--wallet-password-stdin wallet.jmdat
|
||||
'';
|
||||
serviceConfig = nbLib.defaultHardening // rec {
|
||||
WorkingDirectory = cfg.dataDir; # The service creates dir 'logs' in the working dir
|
||||
# Show "joinmarket-yieldgenerator" instead of "bash" in the journal.
|
||||
# The start script has to run alongside the main process
|
||||
# because it provides the wallet password via stdin to the main process
|
||||
SyslogIdentifier = "joinmarket-yieldgenerator";
|
||||
User = cfg.user;
|
||||
ReadWritePaths = [ cfg.dataDir ];
|
||||
} // nbLib.allowTor;
|
||||
};
|
||||
})
|
||||
];
|
||||
}
|
||||
@@ -1,147 +0,0 @@
|
||||
{ config, lib, pkgs, ... }:
|
||||
|
||||
with lib;
|
||||
let
|
||||
options.services.lightning-loop = {
|
||||
enable = mkEnableOption "Lightning Loop, a non-custodial off/on chain bridge";
|
||||
rpcAddress = mkOption {
|
||||
type = types.str;
|
||||
default = "127.0.0.1";
|
||||
description = "Address to listen for gRPC connections.";
|
||||
};
|
||||
rpcPort = mkOption {
|
||||
type = types.port;
|
||||
default = 11010;
|
||||
description = "Port to listen for gRPC connections.";
|
||||
};
|
||||
restAddress = mkOption {
|
||||
type = types.str;
|
||||
default = cfg.rpcAddress;
|
||||
description = "Address to listen for REST connections.";
|
||||
};
|
||||
restPort = mkOption {
|
||||
type = types.port;
|
||||
default = 8081;
|
||||
description = "Port to listen for REST connections.";
|
||||
};
|
||||
package = mkOption {
|
||||
type = types.package;
|
||||
default = config.nix-bitcoin.pkgs.lightning-loop;
|
||||
defaultText = "config.nix-bitcoin.pkgs.lightning-loop";
|
||||
description = "The package providing lightning-loop binaries.";
|
||||
};
|
||||
dataDir = mkOption {
|
||||
type = types.path;
|
||||
default = "/var/lib/lightning-loop";
|
||||
description = "The data directory for lightning-loop.";
|
||||
};
|
||||
proxy = mkOption {
|
||||
type = types.nullOr types.str;
|
||||
default = if cfg.tor.proxy then config.nix-bitcoin.torClientAddressWithPort else null;
|
||||
description = "`host:port` of SOCKS5 proxy for connnecting to the loop server.";
|
||||
};
|
||||
certificate = {
|
||||
extraIPs = mkOption {
|
||||
type = with types; listOf str;
|
||||
default = [];
|
||||
example = [ "60.100.0.1" ];
|
||||
description = ''
|
||||
Extra `subjectAltName` IPs added to the certificate.
|
||||
This works the same as loop option {option}`tlsextraip`.
|
||||
'';
|
||||
};
|
||||
extraDomains = mkOption {
|
||||
type = with types; listOf str;
|
||||
default = [];
|
||||
example = [ "example.com" ];
|
||||
description = ''
|
||||
Extra `subjectAltName` domain names added to the certificate.
|
||||
This works the same as loop option {option}`tlsextradomain`.
|
||||
'';
|
||||
};
|
||||
};
|
||||
extraConfig = mkOption {
|
||||
type = types.lines;
|
||||
default = "";
|
||||
example = ''
|
||||
debuglevel=trace
|
||||
'';
|
||||
description = ''
|
||||
Extra lines appended to the configuration file.
|
||||
See here for all available options:
|
||||
https://github.com/lightninglabs/loop/blob/11ab596080e9d36f1df43edbeba0702b25aa7457/loopd/config.go#L119
|
||||
'';
|
||||
};
|
||||
cli = mkOption {
|
||||
default = pkgs.writers.writeBashBin "loop" ''
|
||||
${cfg.package}/bin/loop \
|
||||
--rpcserver ${nbLib.addressWithPort cfg.rpcAddress cfg.rpcPort} \
|
||||
--macaroonpath '${cfg.dataDir}/${network}/loop.macaroon' \
|
||||
--tlscertpath '${secretsDir}/loop-cert' "$@"
|
||||
'';
|
||||
defaultText = "(See source)";
|
||||
description = "Binary to connect with the lightning-loop instance.";
|
||||
};
|
||||
tor = nbLib.tor;
|
||||
};
|
||||
|
||||
cfg = config.services.lightning-loop;
|
||||
nbLib = config.nix-bitcoin.lib;
|
||||
secretsDir = config.nix-bitcoin.secretsDir;
|
||||
|
||||
lnd = config.services.lnd;
|
||||
|
||||
network = config.services.bitcoind.network;
|
||||
configFile = builtins.toFile "loop.conf" ''
|
||||
datadir=${cfg.dataDir}
|
||||
network=${network}
|
||||
rpclisten=${cfg.rpcAddress}:${toString cfg.rpcPort}
|
||||
restlisten=${cfg.restAddress}:${toString cfg.restPort}
|
||||
logdir=${cfg.dataDir}/logs
|
||||
tlscertpath=${secretsDir}/loop-cert
|
||||
tlskeypath=${secretsDir}/loop-key
|
||||
|
||||
lnd.host=${nbLib.addressWithPort lnd.rpcAddress lnd.rpcPort}
|
||||
lnd.macaroonpath=${lnd.networkDir}/admin.macaroon
|
||||
lnd.tlspath=${lnd.certPath}
|
||||
|
||||
${optionalString (cfg.proxy != null) "server.proxy=${cfg.proxy}"}
|
||||
|
||||
${cfg.extraConfig}
|
||||
'';
|
||||
in {
|
||||
inherit options;
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
services.lnd.enable = true;
|
||||
|
||||
environment.systemPackages = [ cfg.package (hiPrio cfg.cli) ];
|
||||
|
||||
systemd.tmpfiles.rules = [
|
||||
"d '${cfg.dataDir}' 0770 ${lnd.user} ${lnd.group} - -"
|
||||
];
|
||||
|
||||
services.lightning-loop.certificate.extraIPs = mkIf (cfg.rpcAddress != "127.0.0.1") [ "${cfg.rpcAddress}" ];
|
||||
|
||||
systemd.services.lightning-loop = {
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
requires = [ "lnd.service" ];
|
||||
after = [ "lnd.service" "nix-bitcoin-secrets.target" ];
|
||||
serviceConfig = nbLib.defaultHardening // {
|
||||
ExecStart = "${cfg.package}/bin/loopd --configfile=${configFile}";
|
||||
User = lnd.user;
|
||||
Restart = "on-failure";
|
||||
RestartSec = "10s";
|
||||
ReadWritePaths = [ cfg.dataDir ];
|
||||
} // nbLib.allowedIPAddresses cfg.tor.enforce;
|
||||
};
|
||||
|
||||
nix-bitcoin.secrets = {
|
||||
loop-key.user = lnd.user;
|
||||
loop-cert.user = lnd.user;
|
||||
};
|
||||
nix-bitcoin.generateSecretsCmds.lightning-loop = ''
|
||||
makeCert loop '${nbLib.mkCertExtraAltNames cfg.certificate}'
|
||||
'';
|
||||
};
|
||||
}
|
||||
@@ -1,113 +0,0 @@
|
||||
{ config, lib, pkgs, ... }:
|
||||
|
||||
with lib;
|
||||
let
|
||||
options.services.lightning-pool = {
|
||||
enable = mkEnableOption "Lightning Pool, a marketplace for inbound lightning liquidity ";
|
||||
rpcAddress = mkOption {
|
||||
type = types.str;
|
||||
default = "127.0.0.1";
|
||||
description = "Address to listen for gRPC connections.";
|
||||
};
|
||||
rpcPort = mkOption {
|
||||
type = types.port;
|
||||
default = 12010;
|
||||
description = "Port to listen for gRPC connections.";
|
||||
};
|
||||
restAddress = mkOption {
|
||||
type = types.str;
|
||||
default = cfg.rpcAddress;
|
||||
description = "Address to listen for REST connections.";
|
||||
};
|
||||
restPort = mkOption {
|
||||
type = types.port;
|
||||
default = 8281;
|
||||
description = "Port to listen for REST connections.";
|
||||
};
|
||||
package = mkOption {
|
||||
type = types.package;
|
||||
default = config.nix-bitcoin.pkgs.lightning-pool;
|
||||
defaultText = "config.nix-bitcoin.pkgs.lightning-pool";
|
||||
description = "The package providing lightning-pool binaries.";
|
||||
};
|
||||
dataDir = mkOption {
|
||||
type = types.path;
|
||||
default = "/var/lib/lightning-pool";
|
||||
description = "The data directory for lightning-pool.";
|
||||
};
|
||||
proxy = mkOption {
|
||||
type = types.nullOr types.str;
|
||||
default = if cfg.tor.proxy then config.nix-bitcoin.torClientAddressWithPort else null;
|
||||
description = "host:port of SOCKS5 proxy for connnecting to the pool auction server.";
|
||||
};
|
||||
extraConfig = mkOption {
|
||||
type = types.lines;
|
||||
default = "";
|
||||
example = ''
|
||||
debuglevel=trace
|
||||
'';
|
||||
description = "Extra lines appended to the configuration file.";
|
||||
};
|
||||
cli = mkOption {
|
||||
default = pkgs.writers.writeBashBin "pool" ''
|
||||
exec ${cfg.package}/bin/pool \
|
||||
--rpcserver ${nbLib.addressWithPort cfg.rpcAddress cfg.rpcPort} \
|
||||
--network ${network} \
|
||||
--basedir '${cfg.dataDir}' "$@"
|
||||
'';
|
||||
defaultText = "(See source)";
|
||||
description = "Binary to connect with the lightning-pool instance.";
|
||||
};
|
||||
tor = nbLib.tor;
|
||||
};
|
||||
|
||||
cfg = config.services.lightning-pool;
|
||||
nbLib = config.nix-bitcoin.lib;
|
||||
|
||||
lnd = config.services.lnd;
|
||||
|
||||
network = config.services.bitcoind.network;
|
||||
configFile = builtins.toFile "pool.conf" ''
|
||||
rpclisten=${cfg.rpcAddress}:${toString cfg.rpcPort}
|
||||
restlisten=${cfg.restAddress}:${toString cfg.restPort}
|
||||
${optionalString (cfg.proxy != null) "proxy=${cfg.proxy}"}
|
||||
|
||||
lnd.host=${lnd.rpcAddress}:${toString lnd.rpcPort}
|
||||
lnd.macaroondir=${lnd.networkDir}
|
||||
lnd.tlspath=${lnd.certPath}
|
||||
|
||||
${cfg.extraConfig}
|
||||
'';
|
||||
in {
|
||||
inherit options;
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
services.lnd.enable = true;
|
||||
|
||||
environment.systemPackages = [ cfg.package (hiPrio cfg.cli) ];
|
||||
|
||||
systemd.tmpfiles.rules = [
|
||||
"d '${cfg.dataDir}' 0770 lnd lnd - -"
|
||||
];
|
||||
|
||||
systemd.services.lightning-pool = {
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
requires = [ "lnd.service" ];
|
||||
after = [ "lnd.service" ];
|
||||
preStart = ''
|
||||
mkdir -p '${cfg.dataDir}/${network}'
|
||||
ln -sfn ${configFile} '${cfg.dataDir}/${network}/poold.conf'
|
||||
'';
|
||||
serviceConfig = nbLib.defaultHardening // {
|
||||
# TODO: temporary sleep to prevent race condition
|
||||
ExecStartPre = "${pkgs.coreutils}/bin/sleep 5";
|
||||
ExecStart = "${cfg.package}/bin/poold --basedir='${cfg.dataDir}' --network=${network}";
|
||||
User = "lnd";
|
||||
Restart = "on-failure";
|
||||
RestartSec = "10s";
|
||||
ReadWritePaths = [ cfg.dataDir ];
|
||||
} // (nbLib.allowedIPAddresses cfg.tor.enforce)
|
||||
// nbLib.allowNetlink; # required by gRPC-Go
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -1,294 +0,0 @@
|
||||
{ config, pkgs, lib, ... }:
|
||||
|
||||
with lib;
|
||||
let
|
||||
options = {
|
||||
services.liquidd = {
|
||||
enable = mkEnableOption "Liquid Bitcoin sidechain daemon";
|
||||
address = mkOption {
|
||||
type = types.str;
|
||||
default = "127.0.0.1";
|
||||
description = "Address to listen for peer connections.";
|
||||
};
|
||||
port = mkOption {
|
||||
type = types.port;
|
||||
default = 7042;
|
||||
description = "Override the default port on which to listen for connections.";
|
||||
};
|
||||
onionPort = mkOption {
|
||||
type = types.nullOr types.port;
|
||||
# When the liquidd onion service is enabled, add an onion-tagged socket
|
||||
# to distinguish local connections from Tor connections
|
||||
default = if (config.nix-bitcoin.onionServices.liquidd.enable or false) then 7043 else null;
|
||||
description = ''
|
||||
Port to listen for Tor peer connections.
|
||||
If set, inbound connections to this port are tagged as onion peers.
|
||||
'';
|
||||
};
|
||||
listen = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description = ''
|
||||
Listen for peer connections at `address:port`
|
||||
and `address:onionPort` (if {option}`onionPort` is set).
|
||||
'';
|
||||
};
|
||||
listenWhitelisted = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description = ''
|
||||
Listen for peer connections at `address:whitelistedPort`.
|
||||
Peers connected through this socket are automatically whitelisted.
|
||||
'';
|
||||
};
|
||||
whitelistedPort = mkOption {
|
||||
type = types.port;
|
||||
default = 7044;
|
||||
description = "See {option}`listenWhitelisted`.";
|
||||
};
|
||||
extraConfig = mkOption {
|
||||
type = types.lines;
|
||||
default = "";
|
||||
example = ''
|
||||
par=16
|
||||
rpcthreads=16
|
||||
logips=1
|
||||
'';
|
||||
description = "Extra lines appended to {file}`elements.conf`.";
|
||||
};
|
||||
dataDir = mkOption {
|
||||
type = types.path;
|
||||
default = "/var/lib/liquidd";
|
||||
description = "The data directory for liquidd.";
|
||||
};
|
||||
rpc = {
|
||||
address = mkOption {
|
||||
type = types.str;
|
||||
default = "127.0.0.1";
|
||||
description = "Address to listen for JSON-RPC connections.";
|
||||
};
|
||||
port = mkOption {
|
||||
type = types.port;
|
||||
default = 7041;
|
||||
description = "Port to listen for JSON-RPC connections.";
|
||||
};
|
||||
users = mkOption {
|
||||
default = {};
|
||||
example = {
|
||||
alice.passwordHMAC = "f7efda5c189b999524f151318c0c86$d5b51b3beffbc02b724e5d095828e0bc8b2456e9ac8757ae3211a5d9b16a22ae";
|
||||
bob.passwordHMAC = "b2dd077cb54591a2f3139e69a897ac$4e71f08d48b4347cf8eff3815c0e25ae2e9a4340474079f55705f40574f4ec99";
|
||||
};
|
||||
type = with types; attrsOf (submodule rpcUserOpts);
|
||||
description = ''
|
||||
RPC user information for JSON-RPC connections.
|
||||
'';
|
||||
};
|
||||
};
|
||||
rpcallowip = mkOption {
|
||||
type = types.listOf types.str;
|
||||
default = [ "127.0.0.1" ];
|
||||
description = ''
|
||||
Allow JSON-RPC connections from specified source.
|
||||
'';
|
||||
};
|
||||
rpcuser = mkOption {
|
||||
type = types.str;
|
||||
default = "liquidrpc";
|
||||
description = "Username for JSON-RPC connections";
|
||||
};
|
||||
proxy = mkOption {
|
||||
type = types.nullOr types.str;
|
||||
default = if cfg.tor.proxy then config.nix-bitcoin.torClientAddressWithPort else null;
|
||||
description = "Connect through SOCKS5 proxy";
|
||||
};
|
||||
dbCache = mkOption {
|
||||
type = types.nullOr (types.ints.between 4 16384);
|
||||
default = null;
|
||||
example = 4000;
|
||||
description = "Override the default database cache size in megabytes.";
|
||||
};
|
||||
prune = mkOption {
|
||||
type = types.nullOr (types.coercedTo
|
||||
(types.enum [ "disable" "manual" ])
|
||||
(x: if x == "disable" then 0 else 1)
|
||||
types.ints.unsigned
|
||||
);
|
||||
default = null;
|
||||
example = 10000;
|
||||
description = ''
|
||||
Reduce storage requirements by enabling pruning (deleting) of old
|
||||
blocks. This allows the pruneblockchain RPC to be called to delete
|
||||
specific blocks, and enables automatic pruning of old blocks if a
|
||||
target size in MiB is provided. This mode is incompatible with -txindex
|
||||
and -rescan. Warning: Reverting this setting requires re-downloading
|
||||
the entire blockchain. (`disable` = disable pruning blocks, `manual`
|
||||
= allow manual pruning via RPC, >=550 = automatically prune block files
|
||||
to stay under the specified target size in MiB)
|
||||
'';
|
||||
};
|
||||
validatepegin = mkOption {
|
||||
type = types.nullOr types.bool;
|
||||
default = null;
|
||||
description = ''
|
||||
Validate pegin claims. All functionaries must run this.
|
||||
'';
|
||||
};
|
||||
user = mkOption {
|
||||
type = types.str;
|
||||
default = "liquid";
|
||||
description = "The user as which to run liquidd.";
|
||||
};
|
||||
group = mkOption {
|
||||
type = types.str;
|
||||
default = cfg.user;
|
||||
description = "The group as which to run liquidd.";
|
||||
};
|
||||
cli = mkOption {
|
||||
readOnly = true;
|
||||
default = pkgs.writers.writeBashBin "elements-cli" ''
|
||||
${nbPkgs.elementsd}/bin/elements-cli -datadir='${cfg.dataDir}' "$@"
|
||||
'';
|
||||
defaultText = "(See source)";
|
||||
description = "Binary to connect with the liquidd instance.";
|
||||
};
|
||||
swapCli = mkOption {
|
||||
default = pkgs.writers.writeBashBin "liquidswap-cli" ''
|
||||
${nbPkgs.liquid-swap}/bin/liquidswap-cli -c '${cfg.dataDir}/elements.conf' "$@"
|
||||
'';
|
||||
defaultText = "(See source)";
|
||||
description = "Binary for managing liquid swaps.";
|
||||
};
|
||||
tor = nbLib.tor;
|
||||
};
|
||||
};
|
||||
|
||||
cfg = config.services.liquidd;
|
||||
nbLib = config.nix-bitcoin.lib;
|
||||
nbPkgs = config.nix-bitcoin.pkgs;
|
||||
secretsDir = config.nix-bitcoin.secretsDir;
|
||||
|
||||
bitcoind = config.services.bitcoind;
|
||||
|
||||
configFile = pkgs.writeText "elements.conf" ''
|
||||
# We're already logging via journald
|
||||
nodebuglogfile=1
|
||||
|
||||
startupnotify=/run/current-system/systemd/bin/systemd-notify --ready
|
||||
|
||||
chain=${bitcoind.makeNetworkName "liquidv1" ''
|
||||
regtest
|
||||
[regtest]'' # Add [regtest] config section
|
||||
}
|
||||
${optionalString (cfg.dbCache != null) "dbcache=${toString cfg.dbCache}"}
|
||||
${optionalString (cfg.prune != null) "prune=${toString cfg.prune}"}
|
||||
${optionalString (cfg.validatepegin != null) "validatepegin=${if cfg.validatepegin then "1" else "0"}"}
|
||||
|
||||
# Connection options
|
||||
listen=${if (cfg.listen || cfg.listenWhitelisted) then "1" else "0"}
|
||||
${optionalString cfg.listen
|
||||
"bind=${cfg.address}:${toString cfg.port}"}
|
||||
${optionalString (cfg.listen && cfg.onionPort != null)
|
||||
"bind=${cfg.address}:${toString cfg.onionPort}=onion"}
|
||||
${optionalString cfg.listenWhitelisted
|
||||
"whitebind=${cfg.address}:${toString cfg.whitelistedPort}"}
|
||||
${optionalString (cfg.proxy != null) "proxy=${cfg.proxy}"}
|
||||
|
||||
# RPC server options
|
||||
rpcport=${toString cfg.rpc.port}
|
||||
${concatMapStringsSep "\n"
|
||||
(rpcUser: "rpcauth=${rpcUser.name}:${rpcUser.passwordHMAC}")
|
||||
(attrValues cfg.rpc.users)
|
||||
}
|
||||
rpcbind=${cfg.rpc.address}
|
||||
rpcconnect=${cfg.rpc.address}
|
||||
${lib.concatMapStrings (rpcallowip: "rpcallowip=${rpcallowip}\n") cfg.rpcallowip}
|
||||
rpcuser=${cfg.rpcuser}
|
||||
mainchainrpchost=${nbLib.address bitcoind.rpc.address}
|
||||
mainchainrpcport=${toString bitcoind.rpc.port}
|
||||
mainchainrpcuser=${bitcoind.rpc.users.public.name}
|
||||
|
||||
# Extra config options (from liquidd nixos service)
|
||||
${cfg.extraConfig}
|
||||
'';
|
||||
rpcUserOpts = { name, ... }: {
|
||||
options = {
|
||||
name = mkOption {
|
||||
type = types.str;
|
||||
example = "alice";
|
||||
description = ''
|
||||
Username for JSON-RPC connections.
|
||||
'';
|
||||
};
|
||||
passwordHMAC = mkOption {
|
||||
type = with types; uniq (strMatching "[0-9a-f]+\\$[0-9a-f]{64}");
|
||||
example = "f7efda5c189b999524f151318c0c86$d5b51b3beffbc02b724e5d095828e0bc8b2456e9ac8757ae3211a5d9b16a22ae";
|
||||
description = ''
|
||||
Password HMAC-SHA-256 for JSON-RPC connections. Must be a string of the
|
||||
format `<SALT-HEX>$<HMAC-HEX>`.
|
||||
'';
|
||||
};
|
||||
};
|
||||
config = {
|
||||
name = mkDefault name;
|
||||
};
|
||||
};
|
||||
in {
|
||||
inherit options;
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
assertions = [
|
||||
{ assertion = bitcoind.regtest -> cfg.validatepegin != true;
|
||||
message = "liquidd: `validatepegin` is incompatible with regtest.";
|
||||
}
|
||||
];
|
||||
|
||||
services.bitcoind.enable = true;
|
||||
|
||||
environment.systemPackages = [
|
||||
nbPkgs.elementsd
|
||||
(hiPrio cfg.cli)
|
||||
(hiPrio cfg.swapCli)
|
||||
];
|
||||
|
||||
systemd.tmpfiles.rules = [
|
||||
"d '${cfg.dataDir}' 0770 ${cfg.user} ${cfg.group} - -"
|
||||
];
|
||||
|
||||
systemd.services.liquidd = {
|
||||
wants = [ "bitcoind.service" ];
|
||||
after = [ "bitcoind.service" "nix-bitcoin-secrets.target" ];
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
preStart = ''
|
||||
install -m 640 ${configFile} '${cfg.dataDir}/elements.conf'
|
||||
{
|
||||
echo "rpcpassword=$(cat ${secretsDir}/liquid-rpcpassword)"
|
||||
echo "mainchainrpcpassword=$(cat ${secretsDir}/bitcoin-rpcpassword-public)"
|
||||
} >> '${cfg.dataDir}/elements.conf'
|
||||
'';
|
||||
serviceConfig = nbLib.defaultHardening // {
|
||||
Type = "notify";
|
||||
NotifyAccess = "all";
|
||||
User = cfg.user;
|
||||
Group = cfg.group;
|
||||
TimeoutStartSec = "2h";
|
||||
TimeoutStopSec = "2h";
|
||||
ExecStart = "${nbPkgs.elementsd}/bin/elementsd -datadir='${cfg.dataDir}'";
|
||||
Restart = "on-failure";
|
||||
ReadWritePaths = [ cfg.dataDir ];
|
||||
} // nbLib.allowedIPAddresses cfg.tor.enforce;
|
||||
};
|
||||
|
||||
users.users.${cfg.user} = {
|
||||
isSystemUser = true;
|
||||
group = cfg.group;
|
||||
extraGroups = [ "bitcoinrpc-public" ];
|
||||
};
|
||||
users.groups.${cfg.group} = {};
|
||||
nix-bitcoin.operator.groups = [ cfg.group ];
|
||||
|
||||
nix-bitcoin.secrets.liquid-rpcpassword.user = cfg.user;
|
||||
nix-bitcoin.generateSecretsCmds.liquid = ''
|
||||
makePasswordSecret liquid-rpcpassword
|
||||
'';
|
||||
};
|
||||
}
|
||||
@@ -191,19 +191,6 @@ in {
|
||||
inherit options;
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
assertions = [
|
||||
{ assertion =
|
||||
!(config.services ? clightning)
|
||||
|| !config.services.clightning.enable
|
||||
|| config.services.clightning.port != cfg.port;
|
||||
message = ''
|
||||
LND and clightning can't both bind to lightning port 9735. Either
|
||||
disable LND/clightning or change services.clightning.port or
|
||||
services.lnd.port to a port other than 9735.
|
||||
'';
|
||||
}
|
||||
];
|
||||
|
||||
services.bitcoind = {
|
||||
enable = true;
|
||||
|
||||
|
||||
@@ -1,282 +0,0 @@
|
||||
{ config, lib, pkgs, ... }:
|
||||
|
||||
with lib;
|
||||
let
|
||||
options = {
|
||||
services.lnd.lndconnect = {
|
||||
enable = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description = ''
|
||||
Add a `lndconnect` binary to the system environment which prints
|
||||
connection info for lnd clients.
|
||||
See: https://github.com/LN-Zap/lndconnect
|
||||
|
||||
Usage:
|
||||
```bash
|
||||
# Print QR code
|
||||
lndconnect
|
||||
|
||||
# Print URL
|
||||
lndconnect --url
|
||||
```
|
||||
'';
|
||||
};
|
||||
onion = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description = ''
|
||||
Create an onion service for the lnd REST server,
|
||||
which is used by lndconnect.
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
services.clightning.plugins.clnrest.lnconnect = {
|
||||
enable = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description = ''
|
||||
Add a `lnconnect-clnrest` binary to the system environment which prints
|
||||
connection info for clightning clients.
|
||||
See: https://github.com/LN-Zap/lndconnect
|
||||
|
||||
Usage:
|
||||
```bash
|
||||
# Print QR code
|
||||
lnconnect-clnrest
|
||||
|
||||
# Print URL
|
||||
lnconnect-clnrest --url
|
||||
```
|
||||
'';
|
||||
};
|
||||
onion = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description = ''
|
||||
Create an onion service for the clnrest server,
|
||||
which is used by lnconnect.
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
services.clightning-rest.lndconnect = {
|
||||
enable = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description = ''
|
||||
Add a `lndconnect-clightning` binary to the system environment which prints
|
||||
connection info for clightning clients.
|
||||
See: https://github.com/LN-Zap/lndconnect
|
||||
|
||||
Usage:
|
||||
```bash
|
||||
# Print QR code
|
||||
lndconnect-clightning
|
||||
|
||||
# Print URL
|
||||
lndconnect-clightning --url
|
||||
```
|
||||
'';
|
||||
};
|
||||
onion = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description = ''
|
||||
Create an onion service for the clightning REST server,
|
||||
which is used by lndconnect.
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
nix-bitcoin.mkLndconnect = mkOption {
|
||||
readOnly = true;
|
||||
default = mkLndconnect;
|
||||
description = ''
|
||||
A function to create a lndconnect binary.
|
||||
See the source for further details.
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
nbLib = config.nix-bitcoin.lib;
|
||||
runAsUser = config.nix-bitcoin.runAsUserCmd;
|
||||
|
||||
inherit (config.services)
|
||||
lnd
|
||||
clightning
|
||||
clightning-rest;
|
||||
|
||||
inherit (clightning.plugins) clnrest;
|
||||
|
||||
mkLndconnect = {
|
||||
name,
|
||||
shebang ? "#!${pkgs.stdenv.shell} -e",
|
||||
isClightning ? false,
|
||||
isClnrest ? false,
|
||||
port,
|
||||
authSecretPath,
|
||||
enableOnion,
|
||||
onionService ? null,
|
||||
certPath ? null
|
||||
}:
|
||||
# TODO-EXTERNAL:
|
||||
# lndconnect requires a --configfile argument, although it's unused
|
||||
# https://github.com/LN-Zap/lndconnect/issues/25
|
||||
lib.hiPrio (pkgs.writeScriptBin name ''
|
||||
${shebang}
|
||||
url=$(
|
||||
${getExe config.nix-bitcoin.pkgs.lndconnect} --url \
|
||||
${optionalString enableOnion "--host=$(cat ${config.nix-bitcoin.onionAddresses.dataDir}/${onionService})"} \
|
||||
--port=${toString port} \
|
||||
${if enableOnion || certPath == null then "--nocert" else "--tlscertpath='${certPath}'"} \
|
||||
--adminmacaroonpath='${authSecretPath}' \
|
||||
--configfile=/dev/null "$@"
|
||||
)
|
||||
|
||||
${optionalString isClightning
|
||||
# - Change URL procotcol to c-lightning-rest
|
||||
# - Encode macaroon as hex (in uppercase) instead of base 64.
|
||||
# Because `macaroon` is always the last URL fragment, the
|
||||
# sed replacement below works correctly.
|
||||
''
|
||||
macaroonHex=$(${getExe pkgs.xxd} -p -u -c 99999 '${authSecretPath}')
|
||||
url=$(
|
||||
echo "$url" | ${getExe pkgs.gnused} "
|
||||
s|^lndconnect|c-lightning-rest|
|
||||
s|macaroon=.*|macaroon=$macaroonHex|
|
||||
";
|
||||
)
|
||||
''
|
||||
}
|
||||
|
||||
${optionalString isClnrest
|
||||
# Change URL procotcol to clnrest
|
||||
''
|
||||
url=$(
|
||||
echo "$url" | ${getExe pkgs.gnused} "
|
||||
s|^lndconnect|clnrest|
|
||||
s|macaroon=.*|rune=$(cat '${authSecretPath}')|
|
||||
";
|
||||
)
|
||||
''
|
||||
}
|
||||
|
||||
# If --url is in args
|
||||
if [[ " $* " =~ " --url " ]]; then
|
||||
echo "$url"
|
||||
else
|
||||
# This UTF-8 encoding yields a smaller, more convenient output format
|
||||
# compared to the native lndconnect output
|
||||
echo -n "$url" | ${getExe pkgs.qrencode} -t UTF8 -o -
|
||||
fi
|
||||
'');
|
||||
|
||||
operatorName = config.nix-bitcoin.operator.name;
|
||||
in {
|
||||
inherit options;
|
||||
|
||||
config = mkMerge [
|
||||
(mkIf (lnd.enable && lnd.lndconnect.enable)
|
||||
(mkMerge [
|
||||
{
|
||||
environment.systemPackages = [(
|
||||
mkLndconnect {
|
||||
name = "lndconnect";
|
||||
# Run as lnd user because the macaroon and cert are not group-readable
|
||||
shebang = "#!/usr/bin/env -S ${runAsUser} ${lnd.user} ${pkgs.bash}/bin/bash";
|
||||
enableOnion = lnd.lndconnect.onion;
|
||||
onionService = "${lnd.user}/lnd-rest";
|
||||
port = lnd.restPort;
|
||||
certPath = lnd.certPath;
|
||||
authSecretPath = "${lnd.networkDir}/admin.macaroon";
|
||||
}
|
||||
)];
|
||||
|
||||
services.lnd.restAddress = mkIf (!lnd.lndconnect.onion) "0.0.0.0";
|
||||
}
|
||||
|
||||
(mkIf lnd.lndconnect.onion {
|
||||
services.tor = {
|
||||
enable = true;
|
||||
relay.onionServices.lnd-rest = nbLib.mkOnionService {
|
||||
target.addr = nbLib.address lnd.restAddress;
|
||||
target.port = lnd.restPort;
|
||||
port = lnd.restPort;
|
||||
};
|
||||
};
|
||||
nix-bitcoin.onionAddresses.access = {
|
||||
${lnd.user} = [ "lnd-rest" ];
|
||||
${operatorName} = [ "lnd-rest" ];
|
||||
};
|
||||
})
|
||||
]))
|
||||
|
||||
(mkIf (clnrest.enable && clnrest.lnconnect.enable)
|
||||
(mkMerge [
|
||||
{
|
||||
environment.systemPackages = [(
|
||||
mkLndconnect {
|
||||
name = "lnconnect-clnrest";
|
||||
isClnrest = true;
|
||||
enableOnion = clnrest.lnconnect.onion;
|
||||
onionService = "${operatorName}/clnrest";
|
||||
port = clnrest.port;
|
||||
certPath = "${clightning.networkDir}/client.pem";
|
||||
authSecretPath = "${clightning.networkDir}/admin-rune";
|
||||
}
|
||||
)];
|
||||
|
||||
services.clightning.plugins.clnrest.address = mkIf (!clnrest.lnconnect.onion) "0.0.0.0";
|
||||
}
|
||||
|
||||
(mkIf clnrest.lnconnect.onion {
|
||||
services.tor = {
|
||||
enable = true;
|
||||
relay.onionServices.clnrest = nbLib.mkOnionService {
|
||||
target.addr = nbLib.address clnrest.address;
|
||||
target.port = clnrest.port;
|
||||
port = clnrest.port;
|
||||
};
|
||||
};
|
||||
# This also allows nodeinfo to show the clnrest onion address
|
||||
nix-bitcoin.onionAddresses.access.${operatorName} = [ "clnrest" ];
|
||||
})
|
||||
])
|
||||
)
|
||||
|
||||
(mkIf (clightning-rest.enable && clightning-rest.lndconnect.enable)
|
||||
(mkMerge [
|
||||
{
|
||||
environment.systemPackages = [(
|
||||
mkLndconnect {
|
||||
name = "lndconnect-clightning";
|
||||
isClightning = true;
|
||||
enableOnion = clightning-rest.lndconnect.onion;
|
||||
onionService = "${operatorName}/clightning-rest";
|
||||
port = clightning-rest.port;
|
||||
certPath = "${clightning-rest.dataDir}/certs/certificate.pem";
|
||||
authSecretPath = "${clightning-rest.dataDir}/certs/access.macaroon";
|
||||
}
|
||||
)];
|
||||
|
||||
# clightning-rest always binds to all interfaces
|
||||
}
|
||||
|
||||
(mkIf clightning-rest.lndconnect.onion {
|
||||
services.tor = {
|
||||
enable = true;
|
||||
relay.onionServices.clightning-rest = nbLib.mkOnionService {
|
||||
target.addr = nbLib.address clightning-rest.address;
|
||||
target.port = clightning-rest.port;
|
||||
port = clightning-rest.port;
|
||||
};
|
||||
};
|
||||
# This also allows nodeinfo to show the clightning-rest onion address
|
||||
nix-bitcoin.onionAddresses.access.${operatorName} = [ "clightning-rest" ];
|
||||
})
|
||||
])
|
||||
)
|
||||
];
|
||||
}
|
||||
+6
-23
@@ -94,19 +94,6 @@ let
|
||||
default = 8999;
|
||||
description = "Mempool backend port.";
|
||||
};
|
||||
electrumServer = mkOption {
|
||||
type = types.enum [ "electrs" "fulcrum" ];
|
||||
default = "electrs";
|
||||
description = ''
|
||||
The Electrum server to use for fetching address information.
|
||||
|
||||
Possible options:
|
||||
- electrs:
|
||||
Small database size, slow when querying new addresses.
|
||||
- fulcrum:
|
||||
Large database size, quickly serves arbitrary address queries.
|
||||
'';
|
||||
};
|
||||
settings = mkOption {
|
||||
type = with types; attrsOf (attrsOf anything);
|
||||
example = {
|
||||
@@ -170,8 +157,7 @@ let
|
||||
|
||||
inherit (config.services)
|
||||
bitcoind
|
||||
electrs
|
||||
fulcrum;
|
||||
electrs;
|
||||
|
||||
torSocket = config.services.tor.client.socksListenAddress;
|
||||
|
||||
@@ -240,8 +226,7 @@ in {
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
services.bitcoind.txindex = true;
|
||||
services.electrs.enable = mkIf (cfg.electrumServer == "electrs" ) true;
|
||||
services.fulcrum.enable = mkIf (cfg.electrumServer == "fulcrum" ) true;
|
||||
services.electrs.enable = true;
|
||||
services.mysql = {
|
||||
enable = true;
|
||||
package = pkgs.mariadb;
|
||||
@@ -272,11 +257,9 @@ in {
|
||||
USERNAME = bitcoind.rpc.users.public.name;
|
||||
PASSWORD = "@btcRpcPassword@";
|
||||
};
|
||||
ELECTRUM = let
|
||||
server = config.services.${cfg.electrumServer};
|
||||
in {
|
||||
HOST = server.address;
|
||||
PORT = server.port;
|
||||
ELECTRUM = {
|
||||
HOST = electrs.address;
|
||||
PORT = electrs.port;
|
||||
TLS_ENABLED = false;
|
||||
};
|
||||
DATABASE = {
|
||||
@@ -298,7 +281,7 @@ in {
|
||||
systemd.services.mempool = rec {
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
requires = [ "mysql.service" ];
|
||||
wants = [ "${cfg.electrumServer}.service" ];
|
||||
wants = [ "electrs.service" ];
|
||||
after = requires ++ wants;
|
||||
preStart = ''
|
||||
mkdir -p '${cacheDir}/cache'
|
||||
|
||||
@@ -10,33 +10,15 @@
|
||||
|
||||
# Main features
|
||||
./bitcoind.nix
|
||||
./clightning.nix
|
||||
./clightning-plugins
|
||||
./clightning-rest.nix
|
||||
./clightning-replication.nix
|
||||
./lnd.nix
|
||||
./lightning-loop.nix
|
||||
./lightning-pool.nix
|
||||
./charge-lnd.nix
|
||||
./lndconnect.nix # Requires onion-addresses.nix
|
||||
./rtl.nix
|
||||
./mempool.nix
|
||||
./electrs.nix
|
||||
./fulcrum.nix
|
||||
./liquid.nix
|
||||
./btcpayserver.nix
|
||||
./joinmarket.nix
|
||||
./joinmarket-ob-watcher.nix
|
||||
./hardware-wallets.nix
|
||||
|
||||
# Support features
|
||||
./versioning.nix
|
||||
./security.nix
|
||||
./onion-addresses.nix
|
||||
./onion-services.nix
|
||||
./netns-isolation.nix
|
||||
./nodeinfo.nix
|
||||
./backups.nix
|
||||
];
|
||||
|
||||
disabledModules = [ "services/networking/bitcoind.nix" ];
|
||||
|
||||
@@ -1,366 +0,0 @@
|
||||
{ config, lib, pkgs, ... }:
|
||||
|
||||
with lib;
|
||||
let
|
||||
options.nix-bitcoin.netns-isolation = {
|
||||
enable = mkEnableOption "netns isolation";
|
||||
|
||||
addressblock = mkOption {
|
||||
type = types.ints.u8;
|
||||
default = 1;
|
||||
description = ''
|
||||
The address block N in 169.254.N.0/24, used as the prefix for netns addresses.
|
||||
'';
|
||||
};
|
||||
|
||||
services = mkOption {
|
||||
default = {};
|
||||
type = types.attrsOf (types.submodule {
|
||||
options = {
|
||||
id = mkOption {
|
||||
# TODO: Assert uniqueness
|
||||
type = types.ints.between 11 255;
|
||||
description = ''
|
||||
id for the netns, used for the IP address host part and
|
||||
for naming the interfaces. Must be unique. Must be greater than 10.
|
||||
'';
|
||||
};
|
||||
connections = mkOption {
|
||||
type = with types; listOf str;
|
||||
default = [];
|
||||
};
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
allowedUser = mkOption {
|
||||
type = types.str;
|
||||
description = ''
|
||||
User that is allowed to execute commands in the service network namespaces.
|
||||
'';
|
||||
default = config.nix-bitcoin.operator.name;
|
||||
};
|
||||
|
||||
netns = mkOption {
|
||||
readOnly = true;
|
||||
default = netns;
|
||||
description = "Exposes netns parameters.";
|
||||
};
|
||||
|
||||
bridgeIp = mkOption {
|
||||
readOnly = true;
|
||||
default = bridgeIp;
|
||||
description = "IP of the netns bridge interface.";
|
||||
};
|
||||
};
|
||||
|
||||
cfg = config.nix-bitcoin.netns-isolation;
|
||||
|
||||
netns = builtins.mapAttrs (n: v: {
|
||||
inherit (v) id;
|
||||
address = "169.254.${toString cfg.addressblock}.${toString v.id}";
|
||||
availableNetns = availableNetns.${n};
|
||||
netnsName = "nb-${n}";
|
||||
}) enabledServices;
|
||||
|
||||
# Symmetric netns connection matrix
|
||||
# if clightning.connections = [ "bitcoind" ]; then
|
||||
# availableNetns.bitcoind = [ "clighting" ];
|
||||
# and
|
||||
# availableNetns.clighting = [ "bitcoind" ];
|
||||
#
|
||||
# TODO-EXTERNAL:
|
||||
# Although negligible for our purposes, this calculation's runtime
|
||||
# is in the order of (number of connections * number of services),
|
||||
# because attrsets and lists are fully copied on each update with '//' or '++'.
|
||||
# This can only be improved with an update in the nix language.
|
||||
#
|
||||
availableNetns = let
|
||||
# base = { clightning = [ "bitcoind" ]; ... }
|
||||
base = builtins.mapAttrs (n: v:
|
||||
builtins.filter isEnabled v.connections
|
||||
) enabledServices;
|
||||
in
|
||||
foldl (xs: s1:
|
||||
foldl (xs: s2:
|
||||
xs // { "${s2}" = xs.${s2} ++ [ s1 ]; }
|
||||
) xs cfg.services.${s1}.connections
|
||||
) base (builtins.attrNames base);
|
||||
|
||||
enabledServices = filterAttrs (n: v: isEnabled n) cfg.services;
|
||||
isEnabled = x: config.services.${x}.enable;
|
||||
|
||||
ip = "${pkgs.iproute2}/bin/ip";
|
||||
iptables = "${config.networking.firewall.package}/bin/iptables";
|
||||
|
||||
bridgeIp = "169.254.${toString cfg.addressblock}.10";
|
||||
|
||||
mkCliExec = service: "exec netns-exec ${netns.${service}.netnsName}";
|
||||
in {
|
||||
inherit options;
|
||||
|
||||
config = mkIf cfg.enable (mkMerge [
|
||||
|
||||
# Base infrastructure
|
||||
{
|
||||
networking.dhcpcd.denyInterfaces = [ "nb-br" "nb-veth*" ];
|
||||
services.tor.client.socksListenAddress = {
|
||||
addr = bridgeIp;
|
||||
# Default NixOS values. These must be repeated when redefining this option.
|
||||
port = 9050;
|
||||
IsolateDestAddr = true;
|
||||
};
|
||||
services.i2pd.proto.sam.address = bridgeIp;
|
||||
networking.firewall.interfaces.nb-br.allowedTCPPorts = [
|
||||
config.services.tor.client.socksListenAddress.port
|
||||
config.services.i2pd.proto.sam.port
|
||||
];
|
||||
boot.kernel.sysctl."net.ipv4.ip_forward" = true;
|
||||
|
||||
security.wrappers.netns-exec = {
|
||||
source = config.nix-bitcoin.pkgs.netns-exec;
|
||||
capabilities = "cap_sys_admin=ep";
|
||||
owner = cfg.allowedUser;
|
||||
# Don't authorize the group of `owner`. For normal users, this group is
|
||||
# `users`, which is shared by all normal users.
|
||||
group = "root";
|
||||
permissions = "500";
|
||||
};
|
||||
|
||||
systemd.services = {
|
||||
# Due to a NixOS bug we can't currently use option `networking.bridges` to
|
||||
# setup the bridge while `networking.useDHCP` is enabled.
|
||||
nb-netns-bridge = {
|
||||
description = "nix-bitcoin netns bridge";
|
||||
wantedBy = [ "network-setup.service" ];
|
||||
partOf = [ "network-setup.service" ];
|
||||
before = [ "network-setup.service" ];
|
||||
after = [ "network-pre.target" ];
|
||||
serviceConfig = {
|
||||
Type = "oneshot";
|
||||
RemainAfterExit = true;
|
||||
};
|
||||
script = ''
|
||||
${ip} link add name nb-br type bridge
|
||||
${ip} link set nb-br up
|
||||
${ip} addr add ${bridgeIp}/24 brd + dev nb-br
|
||||
${iptables} -w -t nat -A POSTROUTING -s 169.254.${toString cfg.addressblock}.0/24 -j MASQUERADE
|
||||
'';
|
||||
preStop = ''
|
||||
${iptables} -w -t nat -D POSTROUTING -s 169.254.${toString cfg.addressblock}.0/24 -j MASQUERADE
|
||||
${ip} link del nb-br
|
||||
'';
|
||||
};
|
||||
|
||||
} //
|
||||
(let
|
||||
makeNetnsServices = n: v: let
|
||||
veth = "nb-veth-${toString v.id}";
|
||||
peer = "nb-veth-br-${toString v.id}";
|
||||
inherit (v) netnsName;
|
||||
nsenter = "${pkgs.util-linux}/bin/nsenter";
|
||||
allowedNetnsAddresses = map (available: netns.${available}.address) v.availableNetns;
|
||||
allowedAddresses = concatStringsSep ","
|
||||
([ "127.0.0.1,${bridgeIp},${v.address}" ] ++ allowedNetnsAddresses);
|
||||
|
||||
setup = ''
|
||||
${ip} netns add ${netnsName}
|
||||
${ip} link add ${veth} type veth peer name ${peer}
|
||||
${ip} link set ${veth} netns ${netnsName}
|
||||
# The peer link is never used directly, so don't auto-assign an IPv6 address
|
||||
echo 1 > /proc/sys/net/ipv6/conf/${peer}/disable_ipv6
|
||||
${ip} link set ${peer} up
|
||||
${ip} link set ${peer} master nb-br
|
||||
exec ${nsenter} --net=/run/netns/${netnsName} ${script "in-netns" setupInNetns}
|
||||
'';
|
||||
|
||||
setupInNetns = ''
|
||||
${ip} link set lo up
|
||||
${ip} addr add ${v.address}/24 dev ${veth}
|
||||
${ip} link set ${veth} up
|
||||
${ip} route add default via ${bridgeIp}
|
||||
|
||||
${iptables} -w -P INPUT DROP
|
||||
# allow return traffic to outgoing connections initiated by the service itself
|
||||
${iptables} -w -A INPUT -m conntrack --ctstate ESTABLISHED -j ACCEPT
|
||||
${iptables} -w -A INPUT -s ${allowedAddresses} -j ACCEPT
|
||||
'' + optionalString (config.services.${n}.tor.enforce or false) ''
|
||||
${iptables} -w -P OUTPUT DROP
|
||||
${iptables} -w -A OUTPUT -d ${allowedAddresses} -j ACCEPT
|
||||
'';
|
||||
script = name: src: pkgs.writers.writeDash name ''
|
||||
set -e
|
||||
${src}
|
||||
'';
|
||||
in {
|
||||
"${n}".serviceConfig.NetworkNamespacePath = "/var/run/netns/${netnsName}";
|
||||
|
||||
"netns-${n}" = rec {
|
||||
requires = [ "nb-netns-bridge.service" ];
|
||||
after = [ "nb-netns-bridge.service" ];
|
||||
requiredBy = [ "${n}.service" ];
|
||||
before = requiredBy;
|
||||
serviceConfig = {
|
||||
Type = "oneshot";
|
||||
RemainAfterExit = true;
|
||||
ExecStart = script "setup" setup;
|
||||
};
|
||||
# Link deletion is implicit in netns deletion, but it sometimes only happens
|
||||
# after `netns delete` finishes. Add an extra `link del` to ensure that
|
||||
# the link is deleted before the service stops, which is needed for service
|
||||
# restart to succeed.
|
||||
preStop = ''
|
||||
${ip} netns delete ${netnsName}
|
||||
${ip} link del ${peer} 2> /dev/null || true
|
||||
'';
|
||||
|
||||
};
|
||||
};
|
||||
in
|
||||
foldl (services: n:
|
||||
services // (makeNetnsServices n netns.${n})
|
||||
) {} (builtins.attrNames netns)
|
||||
);
|
||||
}
|
||||
|
||||
# Service-specific config
|
||||
{
|
||||
nix-bitcoin.netns-isolation.services = {
|
||||
bitcoind = {
|
||||
id = 12;
|
||||
};
|
||||
clightning = {
|
||||
id = 13;
|
||||
connections = [ "bitcoind" ];
|
||||
};
|
||||
lnd = {
|
||||
id = 14;
|
||||
connections = [ "bitcoind" ];
|
||||
};
|
||||
liquidd = {
|
||||
id = 15;
|
||||
connections = [ "bitcoind" ];
|
||||
};
|
||||
electrs = {
|
||||
id = 16;
|
||||
connections = [ "bitcoind" ];
|
||||
};
|
||||
nginx = {
|
||||
id = 21;
|
||||
};
|
||||
lightning-loop = {
|
||||
id = 22;
|
||||
connections = [ "lnd" ];
|
||||
};
|
||||
nbxplorer = {
|
||||
id = 23;
|
||||
connections = [ "bitcoind" ]
|
||||
++ optional config.services.btcpayserver.lbtc "liquidd";
|
||||
};
|
||||
btcpayserver = {
|
||||
id = 24;
|
||||
connections = [ "nbxplorer" ]
|
||||
++ optional (config.services.btcpayserver.lightningBackend == "lnd") "lnd"
|
||||
++ optional config.services.btcpayserver.lbtc "liquidd";
|
||||
# communicates with clightning over rpc socket
|
||||
};
|
||||
joinmarket = {
|
||||
id = 25;
|
||||
connections = [ "bitcoind" ];
|
||||
};
|
||||
joinmarket-ob-watcher = {
|
||||
id = 26;
|
||||
connections = [ "bitcoind" ];
|
||||
};
|
||||
lightning-pool = {
|
||||
id = 27;
|
||||
connections = [ "lnd" ];
|
||||
};
|
||||
charge-lnd = {
|
||||
id = 28;
|
||||
connections = [ "lnd" "electrs" ];
|
||||
};
|
||||
rtl = {
|
||||
id = 29;
|
||||
connections = let
|
||||
nodes = config.services.rtl.nodes;
|
||||
in
|
||||
optional nodes.lnd.enable "lnd" ++
|
||||
optional (nodes.lnd.enable && nodes.lnd.loop) "lightning-loop" ++
|
||||
optional nodes.clightning.enable "clightning";
|
||||
};
|
||||
clightning-rest = {
|
||||
id = 30;
|
||||
};
|
||||
fulcrum = {
|
||||
id = 31;
|
||||
connections = [ "bitcoind" ];
|
||||
};
|
||||
mempool = {
|
||||
id = 32;
|
||||
connections = [
|
||||
"bitcoind"
|
||||
"nginx"
|
||||
(if (config.services.mempool.electrumServer == "electrs") then "electrs" else "fulcrum")
|
||||
];
|
||||
};
|
||||
};
|
||||
|
||||
services.bitcoind = {
|
||||
address = netns.bitcoind.address;
|
||||
rpc.address = netns.bitcoind.address;
|
||||
rpc.allowip = [
|
||||
bridgeIp # For operator user
|
||||
netns.bitcoind.address
|
||||
] ++ map (n: netns.${n}.address) netns.bitcoind.availableNetns;
|
||||
};
|
||||
|
||||
services.clightning.address = netns.clightning.address;
|
||||
services.clightning.plugins.clnrest.address = netns.clightning.address;
|
||||
|
||||
services.lnd = {
|
||||
address = netns.lnd.address;
|
||||
rpcAddress = netns.lnd.address;
|
||||
restAddress = netns.lnd.address;
|
||||
};
|
||||
|
||||
services.liquidd = {
|
||||
address = netns.liquidd.address;
|
||||
rpc.address = netns.liquidd.address;
|
||||
rpcallowip = [
|
||||
bridgeIp # For operator user
|
||||
netns.liquidd.address
|
||||
] ++ map (n: netns.${n}.address) netns.liquidd.availableNetns;
|
||||
};
|
||||
|
||||
services.electrs.address = netns.electrs.address;
|
||||
|
||||
services.fulcrum.address = netns.fulcrum.address;
|
||||
|
||||
services.lightning-loop.rpcAddress = netns.lightning-loop.address;
|
||||
|
||||
services.nbxplorer.address = netns.nbxplorer.address;
|
||||
services.btcpayserver.address = netns.btcpayserver.address;
|
||||
|
||||
services.joinmarket = mkIf config.services.joinmarket.enable {
|
||||
payjoinAddress = netns.joinmarket.address;
|
||||
messagingAddress = netns.joinmarket.address;
|
||||
cliExec = mkCliExec "joinmarket";
|
||||
};
|
||||
systemd.services.joinmarket-yieldgenerator = mkIf config.services.joinmarket.yieldgenerator.enable {
|
||||
serviceConfig.NetworkNamespacePath = "/var/run/netns/nb-joinmarket";
|
||||
};
|
||||
|
||||
services.joinmarket-ob-watcher.address = netns.joinmarket-ob-watcher.address;
|
||||
|
||||
services.lightning-pool.rpcAddress = netns.lightning-pool.address;
|
||||
|
||||
services.rtl.address = netns.rtl.address;
|
||||
|
||||
services.clightning-rest.address = netns.clightning-rest.address;
|
||||
|
||||
services.mempool.address = netns.mempool.address;
|
||||
services.mempool.frontend.address = netns.nginx.address;
|
||||
}
|
||||
]);
|
||||
}
|
||||
@@ -130,11 +130,6 @@ in {
|
||||
|
||||
nix-bitcoin.nodeinfo.services = with nodeinfoLib; {
|
||||
bitcoind = mkInfo "";
|
||||
clightning = mkInfo ''
|
||||
info["nodeid"] = shell("lightning-cli getinfo | jq -r '.id'")
|
||||
if 'onion_address' in info:
|
||||
info["id"] = f"{info['nodeid']}@{info['onion_address']}"
|
||||
'';
|
||||
lnd = name: cfg: mkInfo (''
|
||||
info["rest_address"] = "${nbLib.addressWithPort cfg.restAddress cfg.restPort}"
|
||||
'' + mkIfOnionPort "lnd-rest" (onionPort: ''
|
||||
@@ -142,17 +137,7 @@ in {
|
||||
'') + ''
|
||||
info["nodeid"] = shell("lncli getinfo | jq -r '.identity_pubkey'")
|
||||
'') name cfg;
|
||||
clnrest = name: cfg: mkInfoLong {
|
||||
inherit name cfg;
|
||||
systemdServiceName = "clightning";
|
||||
};
|
||||
clightning-rest = mkInfo "";
|
||||
electrs = mkInfo "";
|
||||
fulcrum = mkInfo "";
|
||||
btcpayserver = mkInfo "";
|
||||
liquidd = mkInfo "";
|
||||
joinmarket-ob-watcher = mkInfo "";
|
||||
rtl = mkInfo "";
|
||||
mempool = mkInfo "";
|
||||
mempool-frontend = name: cfg: mkInfoLong {
|
||||
inherit name cfg;
|
||||
|
||||
@@ -1,145 +0,0 @@
|
||||
{ lib, config, ... }:
|
||||
|
||||
with lib;
|
||||
let
|
||||
mkRenamedAnnounceTorOption = service:
|
||||
# use mkRemovedOptionModule because mkRenamedOptionModule fails with an infinite recursion error
|
||||
mkRemovedOptionModule [ "services" service "announce-tor" ] ''
|
||||
Use option `nix-bitcoin.onionServices.${service}.public` instead.
|
||||
'';
|
||||
|
||||
mkSplitEnforceTorOption = service:
|
||||
(mkRemovedOptionModule [ "services" service "enforceTor" ] ''
|
||||
The option has been split into options `tor.proxy` and `tor.enforce`.
|
||||
Set `tor.proxy = true` to proxy outgoing connections with Tor.
|
||||
Set `tor.enforce = true` to only allow connections (incoming and outgoing) through Tor.
|
||||
'');
|
||||
mkRenamedEnforceTorOption = service:
|
||||
(mkRenamedOptionModule [ "services" service "enforceTor" ] [ "services" service "tor" "enforce" ]);
|
||||
|
||||
in {
|
||||
imports = [
|
||||
(mkRenamedOptionModule [ "services" "bitcoind" "bind" ] [ "services" "bitcoind" "address" ])
|
||||
(mkRenamedOptionModule [ "services" "bitcoind" "rpcallowip" ] [ "services" "bitcoind" "rpc" "allowip" ])
|
||||
(mkRenamedOptionModule [ "services" "bitcoind" "rpcthreads" ] [ "services" "bitcoind" "rpc" "threads" ])
|
||||
(mkRenamedOptionModule [ "services" "clightning" "bind-addr" ] [ "services" "clightning" "address" ])
|
||||
(mkRenamedOptionModule [ "services" "clightning" "bindport" ] [ "services" "clightning" "port" ])
|
||||
(mkRenamedOptionModule [ "services" "lnd" "rpclisten" ] [ "services" "lnd" "rpcAddress" ])
|
||||
(mkRenamedOptionModule [ "services" "lnd" "listen" ] [ "services" "lnd" "address" ])
|
||||
(mkRenamedOptionModule [ "services" "lnd" "listenPort" ] [ "services" "lnd" "port" ])
|
||||
(mkRenamedOptionModule [ "services" "btcpayserver" "bind" ] [ "services" "btcpayserver" "address" ])
|
||||
(mkRenamedOptionModule [ "services" "liquidd" "bind" ] [ "services" "liquidd" "address" ])
|
||||
(mkRenamedOptionModule [ "services" "liquidd" "rpcbind" ] [ "services" "liquidd" "rpc" "address" ])
|
||||
# 0.0.70
|
||||
(mkRenamedOptionModule [ "services" "rtl" "cl-rest" ] [ "services" "clightning-rest" ])
|
||||
|
||||
(mkRenamedOptionModule [ "nix-bitcoin" "setup-secrets" ] [ "nix-bitcoin" "setupSecrets" ])
|
||||
|
||||
(mkRenamedAnnounceTorOption "clightning")
|
||||
(mkRenamedAnnounceTorOption "lnd")
|
||||
|
||||
# 0.0.53
|
||||
(mkRemovedOptionModule [ "services" "electrs" "high-memory" ] ''
|
||||
This option is no longer supported by electrs 0.9.0. Electrs now always uses
|
||||
bitcoin peer connections for syncing blocks. This performs well on low and high
|
||||
memory systems.
|
||||
'')
|
||||
# 0.0.86
|
||||
(mkRemovedOptionModule [ "services" "lnd" "restOnionService" "enable" ] ''
|
||||
Set the following options instead:
|
||||
services.lnd.lndconnect = {
|
||||
enable = true;
|
||||
onion = true;
|
||||
}
|
||||
'')
|
||||
(mkRemovedOptionModule [ "services" "lnd" "lndconnectOnion" ] ''
|
||||
Set the following options instead:
|
||||
services.lnd.lndconnect = {
|
||||
enable = true;
|
||||
onion = true;
|
||||
}
|
||||
'')
|
||||
(mkRemovedOptionModule [ "services" "clightning-rest" "lndconnectOnion" ] ''
|
||||
Set the following options instead:
|
||||
services.clightning-rest.lndconnect = {
|
||||
enable = true;
|
||||
onion = true;
|
||||
}
|
||||
'')
|
||||
] ++
|
||||
# 0.0.59
|
||||
(map mkSplitEnforceTorOption [
|
||||
"clightning"
|
||||
"lightning-loop"
|
||||
"lightning-pool"
|
||||
"liquid"
|
||||
"lnd"
|
||||
"bitcoind"
|
||||
]) ++
|
||||
(map mkRenamedEnforceTorOption [
|
||||
"btcpayserver"
|
||||
"rtl"
|
||||
"electrs"
|
||||
]) ++
|
||||
# 0.0.77
|
||||
[
|
||||
(mkRemovedOptionModule [ "services" "clightning" "plugins" "commando" ] ''
|
||||
clightning 0.12.0 ships with a reimplementation of the commando plugin
|
||||
that is incompatible with the commando module that existed in
|
||||
nix-bitcoin. The new built-in commando plugin is always enabled. For
|
||||
information on how to use it, run `lightning-cli help commando` and
|
||||
`lightning-cli help commando-rune`.
|
||||
'')
|
||||
] ++
|
||||
# 0.0.92
|
||||
[
|
||||
(mkRemovedOptionModule [ "services" "spark-wallet" ] ''
|
||||
Spark Lightning Wallet is unmaintained and incompatible with clightning
|
||||
23.05. Therefore, the spark-wallet module has been removed from
|
||||
nix-bitcoin. For a replacement, consider using the rtl (Ride The
|
||||
Lightning) module or the clightning-rest module in combination with the
|
||||
Zeus mobile wallet.
|
||||
'')
|
||||
]
|
||||
++
|
||||
# 0.0.98
|
||||
[
|
||||
(mkRemovedOptionModule [ "services" "clightning" "plugins" "clboss" "acknowledgeDeprecation" ] ''
|
||||
`clboss` is maintained again and has been un-deprecated.
|
||||
'')
|
||||
]
|
||||
++
|
||||
# 0.0.106
|
||||
(map (plugin:
|
||||
mkRemovedOptionModule [ "services" "clightning" "plugins" plugin ] ''
|
||||
This plugin is no longer maintained.
|
||||
'')
|
||||
[ "summary" "helpme" "prometheus" ]
|
||||
)
|
||||
++
|
||||
# 0.0.110
|
||||
[
|
||||
(mkRemovedOptionModule [ "services" "joinmarket" "yieldgenerator" "txfee" ] ''
|
||||
Option `txfee` has been removed in joinmarket 0.9.3:
|
||||
https://github.com/JoinMarket-Org/joinmarket-clientserver/blob/v0.9.3/docs/release-notes/release-notes-0.9.3.md
|
||||
'')
|
||||
];
|
||||
|
||||
config = {
|
||||
# Migrate old clightning-rest datadir from nix-bitcoin versions < 0.0.70
|
||||
systemd.services.clightning-rest-migrate-datadir = let
|
||||
inherit (config.services) clightning-rest clightning;
|
||||
in mkIf config.services.clightning-rest.enable {
|
||||
requiredBy = [ "clightning-rest.service" ];
|
||||
before = [ "clightning-rest.service" ];
|
||||
script = ''
|
||||
if [[ -e /var/lib/cl-rest/certs ]]; then
|
||||
mv /var/lib/cl-rest/* '${clightning-rest.dataDir}'
|
||||
chown -R ${clightning.user}: '${clightning-rest.dataDir}'
|
||||
rm -r /var/lib/cl-rest
|
||||
fi
|
||||
'';
|
||||
serviceConfig.Type = "oneshot";
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -15,10 +15,10 @@ let
|
||||
description = ''
|
||||
This option controls who is allowed to access onion addresses.
|
||||
For example, the following allows user 'myuser' to access bitcoind
|
||||
and clightning onion addresses:
|
||||
and lnd onion addresses:
|
||||
```nix
|
||||
{
|
||||
"myuser" = [ "bitcoind" "clightning" ];
|
||||
"myuser" = [ "bitcoind" "lnd" ];
|
||||
};
|
||||
```
|
||||
The onion hostnames can then be read from
|
||||
|
||||
@@ -104,15 +104,6 @@ in {
|
||||
# Set sensible defaults for some services
|
||||
{
|
||||
nix-bitcoin.onionServices = {
|
||||
btcpayserver = {
|
||||
externalPort = 80;
|
||||
};
|
||||
joinmarket-ob-watcher = {
|
||||
externalPort = 80;
|
||||
};
|
||||
rtl = {
|
||||
externalPort = 80;
|
||||
};
|
||||
mempool-frontend = {
|
||||
externalPort = 80;
|
||||
};
|
||||
|
||||
@@ -19,36 +19,18 @@ in {
|
||||
# and restrict all connections to Tor
|
||||
#
|
||||
bitcoind = defaultEnableTorProxy;
|
||||
clightning = defaultEnableTorProxy;
|
||||
lnd = defaultEnableTorProxy;
|
||||
lightning-loop = defaultEnableTorProxy;
|
||||
liquidd = defaultEnableTorProxy;
|
||||
# TODO-EXTERNAL:
|
||||
# disable Tor enforcement until btcpayserver can fetch rates over Tor
|
||||
# btcpayserver = defaultEnableTorProxy;
|
||||
lightning-pool = defaultEnableTorProxy;
|
||||
mempool = defaultEnableTorProxy;
|
||||
|
||||
# These services don't make outgoing connections
|
||||
# (or use Tor by default in case of joinmarket)
|
||||
# but we restrict them to Tor just to be safe.
|
||||
#
|
||||
electrs = defaultEnforceTor;
|
||||
fulcrum = defaultEnforceTor;
|
||||
nbxplorer = defaultEnforceTor;
|
||||
rtl = defaultEnforceTor;
|
||||
joinmarket = defaultEnforceTor;
|
||||
joinmarket-ob-watcher = defaultEnforceTor;
|
||||
clightning-rest = defaultEnforceTor;
|
||||
};
|
||||
|
||||
# Add onion services for incoming connections
|
||||
nix-bitcoin.onionServices = {
|
||||
bitcoind.enable = defaultTrue;
|
||||
liquidd.enable = defaultTrue;
|
||||
electrs.enable = defaultTrue;
|
||||
fulcrum.enable = defaultTrue;
|
||||
joinmarket-ob-watcher.enable = defaultTrue;
|
||||
rtl.enable = defaultTrue;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -12,11 +12,6 @@ in {
|
||||
./enable-tor.nix
|
||||
];
|
||||
|
||||
options = {
|
||||
# Used by ../versioning.nix
|
||||
nix-bitcoin.secure-node-preset-enabled = {};
|
||||
};
|
||||
|
||||
config = {
|
||||
networking.firewall.enable = true;
|
||||
|
||||
@@ -41,18 +36,8 @@ in {
|
||||
dbCache = 1000;
|
||||
};
|
||||
|
||||
services.liquidd = {
|
||||
# Enable `validatepegin` to verify that a transaction sending BTC into
|
||||
# Liquid exists on Bitcoin. Without it, a malicious liquid federation can
|
||||
# make the node accept a sidechain that is not fully backed.
|
||||
validatepegin = true;
|
||||
listen = true;
|
||||
};
|
||||
|
||||
nix-bitcoin.nodeinfo.enable = true;
|
||||
|
||||
services.backups.frequency = "daily";
|
||||
|
||||
# operator
|
||||
nix-bitcoin.operator.enable = true;
|
||||
users.users.${operatorName} = {
|
||||
|
||||
-239
@@ -1,239 +0,0 @@
|
||||
{ config, lib, pkgs, ... }:
|
||||
|
||||
with lib;
|
||||
let
|
||||
options.services.rtl = {
|
||||
enable = mkEnableOption "Ride The Lightning, a web interface for lnd and clightning";
|
||||
address = mkOption {
|
||||
type = types.str;
|
||||
default = "127.0.0.1";
|
||||
description = "HTTP server address.";
|
||||
};
|
||||
port = mkOption {
|
||||
type = types.port;
|
||||
default = 3000;
|
||||
description = "HTTP server port.";
|
||||
};
|
||||
dataDir = mkOption {
|
||||
type = types.path;
|
||||
default = "/var/lib/rtl";
|
||||
description = "The data directory for RTL.";
|
||||
};
|
||||
nodes = {
|
||||
clightning = {
|
||||
enable = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description = "Enable the clightning node interface.";
|
||||
};
|
||||
extraConfig = mkOption {
|
||||
type = with types; attrsOf anything;
|
||||
default = {};
|
||||
example = {
|
||||
Settings.userPersona = "MERCHANT";
|
||||
Settings.logLevel = "DEBUG";
|
||||
};
|
||||
description = ''
|
||||
Extra clightning node configuration.
|
||||
See here for all available options:
|
||||
https://github.com/Ride-The-Lightning/RTL/blob/master/.github/docs/Application_configurations.md
|
||||
'';
|
||||
};
|
||||
};
|
||||
lnd = {
|
||||
enable = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description = "Enable the lnd node interface.";
|
||||
};
|
||||
loop = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description = "Enable swaps with lightning-loop.";
|
||||
};
|
||||
extraConfig = mkOption {
|
||||
type = with types; attrsOf anything;
|
||||
default = {};
|
||||
example = {
|
||||
Settings.userPersona = "MERCHANT";
|
||||
Settings.logLevel = "DEBUG";
|
||||
};
|
||||
description = ''
|
||||
Extra lnd node configuration.
|
||||
See here for all available options:
|
||||
https://github.com/Ride-The-Lightning/RTL/blob/master/.github/docs/Application_configurations.md
|
||||
'';
|
||||
};
|
||||
};
|
||||
reverseOrder = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description = ''
|
||||
Reverse the order of nodes shown in the UI.
|
||||
By default, clightning is shown before lnd.
|
||||
'';
|
||||
};
|
||||
};
|
||||
nightTheme = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description = "Enable the Night UI Theme.";
|
||||
};
|
||||
extraCurrency = mkOption {
|
||||
type = with types; nullOr str;
|
||||
default = null;
|
||||
example = "USD";
|
||||
description = ''
|
||||
Currency code (ISO 4217) of the extra currency used for displaying balances.
|
||||
When set, this option enables online currency rate fetching.
|
||||
Warning: Rate fetching requires outgoing clearnet connections, so option
|
||||
{option}`tor.enforce` is automatically disabled.
|
||||
'';
|
||||
};
|
||||
user = mkOption {
|
||||
type = types.str;
|
||||
default = "rtl";
|
||||
description = "The user as which to run RTL.";
|
||||
};
|
||||
group = mkOption {
|
||||
type = types.str;
|
||||
default = cfg.user;
|
||||
description = "The group as which to run RTL.";
|
||||
};
|
||||
tor.enforce = nbLib.tor.enforce;
|
||||
};
|
||||
|
||||
cfg = config.services.rtl;
|
||||
nbLib = config.nix-bitcoin.lib;
|
||||
nbPkgs = config.nix-bitcoin.pkgs;
|
||||
secretsDir = config.nix-bitcoin.secretsDir;
|
||||
runePath = "${cfg.dataDir}/clightning-admin-rune";
|
||||
|
||||
inherit (nbLib) optionalAttr;
|
||||
|
||||
node = { isLnd, index }: {
|
||||
inherit index;
|
||||
lnNode = "Node";
|
||||
lnImplementation = if isLnd then "LND" else "CLT";
|
||||
Authentication = {
|
||||
${optionalAttr (isLnd && lndLoopEnabled) "swapMacaroonPath"} = "${lightning-loop.dataDir}/${bitcoind.network}";
|
||||
${optionalAttr (isLnd) "macaroonPath"} = "${cfg.dataDir}/macaroons";
|
||||
${optionalAttr (!isLnd) "runePath"} = runePath;
|
||||
};
|
||||
Settings = {
|
||||
userPersona = "OPERATOR";
|
||||
themeMode = if cfg.nightTheme then "NIGHT" else "DAY";
|
||||
themeColor = "PURPLE";
|
||||
${optionalAttr isLnd "channelBackupPath"} = "${cfg.dataDir}/backup/lnd";
|
||||
logLevel = "INFO";
|
||||
fiatConversion = cfg.extraCurrency != null;
|
||||
${optionalAttr (cfg.extraCurrency != null) "currencyUnit"} = cfg.extraCurrency;
|
||||
${optionalAttr (isLnd && lndLoopEnabled) "swapServerUrl"} =
|
||||
"https://${nbLib.addressWithPort lightning-loop.restAddress lightning-loop.restPort}";
|
||||
lnServerUrl = "https://${
|
||||
if isLnd
|
||||
then nbLib.addressWithPort lnd.restAddress lnd.restPort
|
||||
else nbLib.addressWithPort clightning.plugins.clnrest.address clightning.plugins.clnrest.port
|
||||
}";
|
||||
};
|
||||
};
|
||||
|
||||
nodes' =
|
||||
optional cfg.nodes.clightning.enable
|
||||
(recursiveUpdate (node { isLnd = false; index = 1; }) cfg.nodes.clightning.extraConfig) ++
|
||||
optional cfg.nodes.lnd.enable
|
||||
(recursiveUpdate (node { isLnd = true; index = 2; }) cfg.nodes.lnd.extraConfig);
|
||||
|
||||
nodes = if cfg.nodes.reverseOrder then reverseList nodes' else nodes';
|
||||
|
||||
rtlConfig = {
|
||||
multiPass = "@multiPass@";
|
||||
host = cfg.address;
|
||||
port = cfg.port;
|
||||
SSO.rtlSSO = 0;
|
||||
inherit nodes;
|
||||
};
|
||||
|
||||
configFile = builtins.toFile "config" (builtins.toJSON rtlConfig);
|
||||
|
||||
inherit (config.services)
|
||||
bitcoind
|
||||
lnd
|
||||
clightning
|
||||
lightning-loop;
|
||||
|
||||
lndLoopEnabled = cfg.nodes.lnd.enable && cfg.nodes.lnd.loop;
|
||||
in {
|
||||
inherit options;
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
assertions = [
|
||||
{ assertion = cfg.nodes.clightning.enable || cfg.nodes.lnd.enable;
|
||||
message = ''
|
||||
RTL: At least one of `nodes.lnd.enable` or `nodes.clightning.enable` must be `true`.
|
||||
'';
|
||||
}
|
||||
];
|
||||
|
||||
services.lnd.enable = mkIf cfg.nodes.lnd.enable true;
|
||||
services.lightning-loop.enable = mkIf lndLoopEnabled true;
|
||||
services.clightning = mkIf cfg.nodes.clightning.enable {
|
||||
enable = true;
|
||||
plugins.clnrest.enable = true;
|
||||
};
|
||||
|
||||
systemd.tmpfiles.rules = [
|
||||
"d '${cfg.dataDir}' 0770 ${cfg.user} ${cfg.group} - -"
|
||||
];
|
||||
|
||||
services.rtl.tor.enforce = mkIf (cfg.extraCurrency != null) false;
|
||||
|
||||
systemd.services.rtl = rec {
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
wants = optional cfg.nodes.clightning.enable "clightning.service" ++
|
||||
optional cfg.nodes.lnd.enable "lnd.service";
|
||||
after = wants ++ [ "nix-bitcoin-secrets.target" ];
|
||||
environment.RTL_CONFIG_PATH = cfg.dataDir;
|
||||
environment.DB_DIRECTORY_PATH = cfg.dataDir;
|
||||
serviceConfig = nbLib.defaultHardening // {
|
||||
ExecStartPre = [
|
||||
(nbLib.script "rtl-setup-config" ''
|
||||
<${configFile} sed "s|@multiPass@|$(cat ${secretsDir}/rtl-password)|" \
|
||||
> '${cfg.dataDir}/RTL-Config.json'
|
||||
'')
|
||||
]
|
||||
++ optional cfg.nodes.lnd.enable
|
||||
# The lnd admin macaroon is not readable by group `lnd`, so copy it
|
||||
(nbLib.rootScript "rtl-copy-macaroon" ''
|
||||
install --compare -m 640 -o ${cfg.user} -g ${cfg.group} -D ${lnd.networkDir}/admin.macaroon \
|
||||
'${cfg.dataDir}/macaroons/admin.macaroon'
|
||||
'')
|
||||
++ optional cfg.nodes.clightning.enable
|
||||
(nbLib.rootScript "rtl-create-clnrest-rune-file" ''
|
||||
rune=$(cat '${clightning.networkDir}/admin-rune')
|
||||
install --compare -m 640 -o ${cfg.user} -g ${cfg.group} <(printf 'LIGHTNING_RUNE="%s"\n' "$rune") '${runePath}'
|
||||
'');
|
||||
ExecStart = "${nbPkgs.rtl}/bin/rtl";
|
||||
# Show "rtl" instead of "node" in the journal
|
||||
SyslogIdentifier = "rtl";
|
||||
User = cfg.user;
|
||||
Restart = "on-failure";
|
||||
RestartSec = "10s";
|
||||
ReadWritePaths = [ cfg.dataDir ];
|
||||
} // nbLib.allowedIPAddresses cfg.tor.enforce
|
||||
// nbLib.nodejs;
|
||||
};
|
||||
|
||||
users.users.${cfg.user} = {
|
||||
isSystemUser = true;
|
||||
group = cfg.group;
|
||||
extraGroups = optional lndLoopEnabled lnd.group;
|
||||
};
|
||||
users.groups.${cfg.group} = {};
|
||||
|
||||
nix-bitcoin.secrets.rtl-password.user = cfg.user;
|
||||
nix-bitcoin.generateSecretsCmds.rtl = ''
|
||||
makePasswordSecret rtl-password
|
||||
'';
|
||||
};
|
||||
}
|
||||
@@ -35,14 +35,6 @@ let
|
||||
'';
|
||||
};
|
||||
|
||||
# Currently, this is used only by ../deployment/nixops.nix
|
||||
deployment.secretsDir = mkOption {
|
||||
type = types.path;
|
||||
description = ''
|
||||
Directory of local secrets that are transferred to the nix-bitcoin node on deployment
|
||||
'';
|
||||
};
|
||||
|
||||
secrets = mkOption {
|
||||
default = {};
|
||||
type = with types; attrsOf (submodule (
|
||||
|
||||
@@ -1,292 +0,0 @@
|
||||
{ config, pkgs, lib, ... }:
|
||||
|
||||
# Workflow for releasing a new nix-bitcoin version with incompatible changes:
|
||||
# Let V be the version of the upcoming, incompatible release.
|
||||
# 1. Add change descriptions with `version = V` at the end of the `changes` list below.
|
||||
# 2. Set `nix-bitcoin.configVersion = V` in ../examples/configuration.nix.
|
||||
|
||||
with lib;
|
||||
let
|
||||
options = {
|
||||
nix-bitcoin.configVersion = mkOption {
|
||||
type = with types; nullOr str;
|
||||
default = null;
|
||||
example = "0.0.92";
|
||||
description = ''
|
||||
The nix-bitcoin release version that your config is compatible with.
|
||||
|
||||
When upgrading to a backwards-incompatible release, nix-bitcoin will throw an
|
||||
error during evaluation and provide instructions for migrating your config to
|
||||
the new release.
|
||||
|
||||
Once set, you only need to update this option when explicitly told to in an
|
||||
error message during evaluation.
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
# Sorted by increasing version numbers
|
||||
changes = [
|
||||
{
|
||||
version = "0.0.26";
|
||||
condition = config.services.joinmarket.enable;
|
||||
message = let
|
||||
inherit (config.services.joinmarket) dataDir;
|
||||
in ''
|
||||
JoinMarket 0.8.0 moves from wrapped segwit wallets to native segwit wallets.
|
||||
|
||||
If you have an existing wrapped segwit wallet, you have to manually migrate
|
||||
your funds to a new native segwit wallet.
|
||||
|
||||
To migrate, you first have to deploy the new JoinMarket version:
|
||||
1. Set `nix-bitcoin.configVersion = "0.0.26";` in your configuration.nix
|
||||
2. Deploy the new configuration
|
||||
|
||||
Then run the following on your nix-bitcoin node:
|
||||
1. Move your wallet:
|
||||
mv ${dataDir}/wallets/wallet.jmdat ${dataDir}/wallets/old.jmdat
|
||||
2. Autogenerate a new p2wpkh wallet:
|
||||
systemctl restart joinmarket
|
||||
3. Transfer your funds manually by doing sweeps for each mixdepth:
|
||||
jm-sendpayment -m <mixdepth> -N 0 old.jmdat 0 <destaddr>
|
||||
|
||||
Run this command for every available mixdepth (`-m 0`, `-m 1`, ...).
|
||||
IMPORTANT: Use a different <destaddr> for every run.
|
||||
|
||||
Explanation of the options:
|
||||
-m <mixdepth>: spend from given mixdepth.
|
||||
-N 0: don't coinjoin on this spend
|
||||
old.jmdat: spend from old wallet
|
||||
0: set amount to zero to do a sweep, i.e. transfer all funds at given mixdepth
|
||||
<destaddr>: destination p2wpkh address from wallet.jmdat with mixdepth 0
|
||||
|
||||
Privacy Notes:
|
||||
- This method transfers all funds to the same mixdepth 0.
|
||||
Because wallet inputs at the same mixdepth can be considered to be linked, this undoes
|
||||
the unlinking effects of previous coinjoins and resets all funds to mixdepth 0.
|
||||
This only applies in case that the inputs to the new wallet are used for further coinjoins.
|
||||
When inputs are instead kept separate in future transactions, the unlinking effects of
|
||||
different mixdepths are preserved.
|
||||
- A different <destaddr> should be used for every transaction.
|
||||
- You might want to time stagger the transactions.
|
||||
- Additionally, you can use coin-freezing to exclude specific inputs from the sweep.
|
||||
|
||||
More information at
|
||||
https://github.com/JoinMarket-Org/joinmarket-clientserver/blob/v0.8.0/docs/NATIVE-SEGWIT-UPGRADE.md
|
||||
'';
|
||||
}
|
||||
(mkOnionServiceChange "clightning")
|
||||
(mkOnionServiceChange "lnd")
|
||||
(mkOnionServiceChange "btcpayserver")
|
||||
{
|
||||
version = "0.0.41";
|
||||
condition = config.services.lnd.enable || config.services.joinmarket.enable;
|
||||
message = let
|
||||
secretsDir = config.nix-bitcoin.secretsDir;
|
||||
lnd = config.services.lnd;
|
||||
jm = config.services.joinmarket;
|
||||
in ''
|
||||
Secret files generated by services at runtime are now stored in the service
|
||||
data dirs instead of the global secrets dir.
|
||||
|
||||
To migrate, run the following Bash script as root on your nix-bitcoin node:
|
||||
|
||||
if [[ -e ${secretsDir}/lnd-seed-mnemonic ]]; then
|
||||
install -o ${lnd.user} -g ${lnd.group} -m400 "${secretsDir}/lnd-seed-mnemonic" "${lnd.dataDir}"
|
||||
fi
|
||||
if [[ -e ${secretsDir}/jm-wallet-seed ]]; then
|
||||
install -o ${jm.user} -g ${jm.group} -m400 "${secretsDir}/jm-wallet-seed" "${jm.dataDir}"
|
||||
fi
|
||||
rm -f "${secretsDir}"/{lnd-seed-mnemonic,jm-wallet-seed}
|
||||
'';
|
||||
}
|
||||
{
|
||||
version = "0.0.49";
|
||||
condition = config.services.joinmarket.enable;
|
||||
message = ''
|
||||
Starting with 0.21.0, bitcoind no longer automatically creates and loads a
|
||||
default wallet named `wallet.dat` [1].
|
||||
The joinmarket service now automatically creates a watch-only bitcoind wallet
|
||||
(named by option `services.joinmarket.rpcWalletFile`) when creating a joinmarket wallet.
|
||||
|
||||
If you've used JoinMarket before, add the following to your configuration to
|
||||
continue using the default `wallet.dat` wallet:
|
||||
services.joinmarket.rpcWalletFile = null;
|
||||
|
||||
[1] https://github.com/bitcoin/bitcoin/pull/15454
|
||||
'';
|
||||
}
|
||||
{
|
||||
version = "0.0.51";
|
||||
condition = config.services.joinmarket.enable;
|
||||
message = let
|
||||
jmDataDir = config.services.joinmarket.dataDir;
|
||||
in ''
|
||||
Joinmarket 0.9.1 has added support for Fidelity Bonds [1].
|
||||
|
||||
If you've used joinmarket before, do the following to enable Fidelity Bonds in your existing wallet.
|
||||
Enabling Fidelity Bonds has no effect if you don't use them.
|
||||
|
||||
1. Deploy the new system config to your node
|
||||
2. Run the following on your node:
|
||||
# Ensure that the wallet seed exists and rename the wallet
|
||||
ls ${jmDataDir}/jm-wallet-seed && mv ${jmDataDir}/wallets/wallet.jmdat{,.bak}
|
||||
# This automatically recreates the wallet with Fidelity Bonds support
|
||||
systemctl restart joinmarket
|
||||
# Remove wallet backup if update was successful
|
||||
rm ${jmDataDir}/wallets/wallet.jmdat.bak
|
||||
|
||||
[1] https://github.com/JoinMarket-Org/joinmarket-clientserver/blob/master/docs/fidelity-bonds.md
|
||||
'';
|
||||
}
|
||||
{
|
||||
version = "0.0.53";
|
||||
condition = config.services.electrs.enable;
|
||||
message = let
|
||||
dbPath = "${config.services.electrs.dataDir}/mainnet";
|
||||
in ''
|
||||
Electrs 0.9.0 has switched to a new, more space efficient database format,
|
||||
reducing storage demands by ~60% [1].
|
||||
When started, electrs will automatically reindex the bitcoin blockchain.
|
||||
This can take a few hours, depending on your hardware. The electrs server is
|
||||
inactive during reindexing.
|
||||
|
||||
To upgrade, do the following:
|
||||
|
||||
- If you have less than 40 GB of free space [2] on the electrs data dir volume:
|
||||
1. Delete the database:
|
||||
systemctl stop electrs
|
||||
rm -r '${dbPath}'
|
||||
2. Deploy the new system config to your node
|
||||
|
||||
- Otherwise:
|
||||
1. Deploy the new system config to your node
|
||||
2. Check that electrs works as expected and delete the old database:
|
||||
rm -r '${dbPath}'
|
||||
|
||||
[1] https://github.com/romanz/electrs/blob/557911e3baf9a000f883a6f619f0518945a7678d/doc/usage.md#upgrading
|
||||
[2] This is based on the bitcoin blockchain size as of 2021-09.
|
||||
The general formula is, approximately, size_of(${dbPath}) * 0.6
|
||||
This includes the final database size (0.4) plus some extra storage (0.2).
|
||||
'';
|
||||
}
|
||||
{
|
||||
version = "0.0.57";
|
||||
condition = config.nix-bitcoin ? secure-node-preset-enabled && config.services.liquidd.enable;
|
||||
message = ''
|
||||
The `secure-node.nix` preset does _not_ set `liquidd.prune = 1000` anymore.
|
||||
|
||||
- If you want to keep the same behavior as before, manually set
|
||||
`services.liquidd.prune = 1000;` in your configuration.nix.
|
||||
- Otherwise, if you want to turn off pruning, you must instruct liquidd
|
||||
to reindex by setting `services.liquidd.extraConfig = "reindex=1";`.
|
||||
This can be removed after having started liquidd with that option
|
||||
once.
|
||||
'';
|
||||
}
|
||||
{
|
||||
version = "0.0.65";
|
||||
condition = config.nix-bitcoin ? secure-node-preset-enabled &&
|
||||
config.nix-bitcoin.secretsDir == "/etc/nix-bitcoin-secrets";
|
||||
message = ''
|
||||
The `secure-node.nix` preset does not set the secrets directory
|
||||
to "/secrets" anymore.
|
||||
Instead, the default location "/etc/nix-bitcoin-secrets" is used.
|
||||
|
||||
To upgrade, choose one of the following:
|
||||
|
||||
- Continue using "/secrets":
|
||||
Add `nix-bitcoin.secretsDir = "/secrets";` to your configuration.nix.
|
||||
|
||||
- Move your secrets to the default location:
|
||||
Run the following command as root on your node:
|
||||
`rsync -a /secrets/ /etc/nix-bitcoin-secrets`.
|
||||
You can delete the old "/secrets" directory after deploying the new system
|
||||
config to your node.
|
||||
'';
|
||||
}
|
||||
{
|
||||
version = "0.0.70";
|
||||
condition = config.services.nbxplorer.enable;
|
||||
message = ''
|
||||
The nbxplorer database backend has changed from DBTrie to Postgresql.
|
||||
The new `services.postgresql` database name is `nbxplorer`.
|
||||
The migration happens automatically after deploying.
|
||||
Migration time for a large server with a 5GB DBTrie database takes about 40 minutes.
|
||||
See also: https://github.com/dgarage/NBXplorer/blob/master/docs/Postgres-Migration.md
|
||||
'';
|
||||
}
|
||||
{
|
||||
version = "0.0.70";
|
||||
condition = config.services.clightning-rest.enable;
|
||||
message = ''
|
||||
The `cl-rest` service has been renamed to `clightning-rest`.
|
||||
and is now available as a standalone service (`services.clightning-rest`).
|
||||
Its data dir has moved to `${config.services.clightning-rest.dataDir}`,
|
||||
and the service now runs under the clightning user and group.
|
||||
The data dir migration happens automatically after deploying.
|
||||
'';
|
||||
}
|
||||
{
|
||||
version = "0.0.70";
|
||||
condition = config.services.lnd.lndconnectOnion.enable;
|
||||
message = ''
|
||||
The `lndconnect-rest-onion` binary has been renamed to `lndconnect`.
|
||||
'';
|
||||
}
|
||||
{
|
||||
version = "0.0.85";
|
||||
condition = config.services.fulcrum.enable;
|
||||
message = ''
|
||||
Fulcrum 1.9.0 has changed its database format.
|
||||
The database update happens automatically and instantly on deployment,
|
||||
but you can't switch back to an older Fulcrum version afterwards.
|
||||
'';
|
||||
}
|
||||
];
|
||||
|
||||
mkOnionServiceChange = service: {
|
||||
version = "0.0.30";
|
||||
condition = config.services.${service}.enable;
|
||||
message = ''
|
||||
The onion service for ${service} has been disabled in the default
|
||||
configuration (`secure-node.nix`).
|
||||
|
||||
To enable the onion service, add the following to your configuration:
|
||||
nix-bitcon.onionServices.${service}.enable = true;
|
||||
'';
|
||||
};
|
||||
|
||||
version = config.nix-bitcoin.configVersion;
|
||||
|
||||
incompatibleChanges = optionals
|
||||
(version != null && versionOlder lastChange)
|
||||
(builtins.filter (change: versionOlder change && (change.condition or true)) changes);
|
||||
|
||||
errorMsg = ''
|
||||
|
||||
This version of nix-bitcoin contains the following changes
|
||||
that are incompatible with your config (version ${version}):
|
||||
|
||||
${concatMapStringsSep "\n" (change: ''
|
||||
- ${change.message}(This change was introduced in version ${change.version})
|
||||
'') incompatibleChanges}
|
||||
After addressing the above changes, set nix-bitcoin.configVersion = "${lastChange.version}";
|
||||
in your nix-bitcoin configuration.
|
||||
'';
|
||||
|
||||
versionOlder = change: (builtins.compareVersions change.version version) > 0;
|
||||
lastChange = builtins.elemAt changes (builtins.length changes - 1);
|
||||
in
|
||||
{
|
||||
imports = [
|
||||
./obsolete-options.nix
|
||||
];
|
||||
|
||||
inherit options;
|
||||
|
||||
config = {
|
||||
# Force evaluation. An actual option value is never assigned
|
||||
system = optionalAttrs (builtins.length incompatibleChanges > 0) (builtins.throw errorMsg);
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user