-
Notifications
You must be signed in to change notification settings - Fork 107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add liana
support
#708
base: master
Are you sure you want to change the base?
add liana
support
#708
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
{ config, lib, pkgs, ... }: | ||
|
||
with lib; | ||
let | ||
options.services.lianad = { | ||
enable = mkEnableOption "lianad bitcoin wallet"; | ||
daemon = mkOption { | ||
type = types.bool; | ||
default = false; | ||
description = mdDoc "Whether to run the process as a UNIX daemon (double fork magic)."; | ||
}; | ||
data_dir = mkOption { | ||
type = types.path; | ||
default = "/var/lib/lianad"; | ||
description = mdDoc "Path to the folder where we should store the application data."; | ||
}; | ||
main_descriptor = mkOption { | ||
type = types.str; | ||
default = "wsh(or_d(pk([0dd8c6f0/48'/1'/0'/2']tpubDFMbZ7U5k5hEfsttnZTKMmwrGMHnqUGxhShsvBjHimXBpmAp5KmxpyGsLx2toCaQgYq5TipBLhTUtA2pRSB9b14m5KwSohTDoCHkk1EnqtZ/<0;1>/*),and_v(v:pkh([d4ab66f1/48'/1'/0'/2']tpubDEXYN145WM4rVKtcWpySBYiVQ229pmrnyAGJT14BBh2QJr7ABJswchDicZfFaauLyXhDad1nCoCZQEwAW87JPotP93ykC9WJvoASnBjYBxW/<0;1>/*),older(65535))))#7nvn6ssc"; | ||
description = mdDoc "The wallet descriptor."; | ||
}; | ||
network = mkOption { | ||
type = types.str; | ||
default = "bitcoin"; | ||
description = mdDoc "bitcoin, testnet, signet, or regtest"; | ||
}; | ||
bitcoind_addr = mkOption { | ||
type = types.str; | ||
default = "127.0.0.1"; | ||
description = mdDoc "bitcoind address."; | ||
}; | ||
bitcoind_port = mkOption { | ||
type = types.port; | ||
default = 8332; | ||
description = mdDoc "bitcoind port."; | ||
}; | ||
}; | ||
|
||
cfg = config.services.lianad; | ||
nbLib = config.nix-bitcoin.lib; | ||
secretsDir = config.nix-bitcoin.secretsDir; | ||
bitcoind = config.services.bitcoind; | ||
in { | ||
inherit options; | ||
|
||
config = mkIf cfg.enable { | ||
services.bitcoind = { | ||
enable = true; | ||
listenWhitelisted = true; | ||
}; | ||
|
||
systemd.tmpfiles.rules = [ | ||
"d '${cfg.dataDir}' 0770 ${cfg.user} ${cfg.group} - -" | ||
]; | ||
|
||
systemd.services.lianad = { | ||
wantedBy = [ "multi-user.target" ]; | ||
requires = [ "bitcoind.service" ]; | ||
after = [ "bitcoind.service" "nix-bitcoin-secrets.target" ]; | ||
preStart = '' | ||
cat << EOF > lianad_config.toml | ||
# these should come from options.services.lianad | ||
daemon = false | ||
data_dir = "/var/lib/lianad" | ||
log_level = "debug" | ||
main_descriptor = "wsh(or_d(pk([0dd8c6f0/48'/1'/0'/2']tpubDFMbZ7U5k5hEfsttnZTKMmwrGMHnqUGxhShsvBjHimXBpmAp5KmxpyGsLx2toCaQgYq5TipBLhTUtA2pRSB9b14m5KwSohTDoCHkk1EnqtZ/<0;1>/*),and_v(v:pkh([d4ab66f1/48'/1'/0'/2']tpubDEXYN145WM4rVKtcWpySBYiVQ229pmrnyAGJT14BBh2QJr7ABJswchDicZfFaauLyXhDad1nCoCZQEwAW87JPotP93ykC9WJvoASnBjYBxW/<0;1>/*),older(65535))))#7nvn6ssc" | ||
|
||
# these should come from options.services.lianad | ||
[bitcoin_config] | ||
network = "signet" | ||
poll_interval_secs = 30 | ||
|
||
# these should come from options.services.bitcoind | ||
[bitcoind_config] | ||
addr = "127.0.0.1:38332" | ||
auth = "username:password" | ||
|
||
EOF | ||
''; | ||
Comment on lines
+60
to
+79
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could be a let
tomlFile =./example.toml;
tomlData = builtins.readFile tomlFile;
tomlObj = builtins.fromTOML tomlData;
tomlString = toString tomlObj;
in
tomlString Then you can interpolate the hardcoded nastiness with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. will this allow me to dynamically generate the TOML file and write it into the output's datadir? it seems like a convenient tool for reading configs that already exist on disk, but our use case is the opposite direction: we need to generate a TOML file with values coming from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can generate a static toml file from a set using mySet = { foo = "bar""; };
myTomlFile = (pkgs.formats.toml {}).generate mySet; But this of course cannot contain secrets such as bitcoind credentials that are not going into the nix store. So then the The lnd module actually already does this: preStart = ''
install -m600 ${configFile} '${cfg.dataDir}/lnd.conf'
{
echo "bitcoind.rpcpass=$(cat ${secretsDir}/bitcoin-rpcpassword-${rpcUser})"
${optionalString (cfg.getPublicAddressCmd != "") ''
echo "externalip=$(${cfg.getPublicAddressCmd})"
''}
} >> '${cfg.dataDir}/lnd.conf' |
||
serviceConfig = nbLib.defaultHardening // { | ||
# lianad only uses the working directory for reading lianad_config.toml | ||
WorkingDirectory = cfg.dataDir; | ||
ExecStart = '' | ||
${config.nix-bitcoin.pkgs.lianad}/bin/lianad \ | ||
--conf lianad_config.toml | ||
''; | ||
User = cfg.user; | ||
Group = cfg.group; | ||
Restart = "on-failure"; | ||
RestartSec = "10s"; | ||
ReadWritePaths = [ cfg.dataDir ]; | ||
} // nbLib.allowedIPAddresses cfg.tor.enforce; | ||
}; | ||
|
||
users.users.${cfg.user} = { | ||
isSystemUser = true; | ||
group = cfg.group; | ||
extraGroups = [ "bitcoinrpc-public" ]; | ||
}; | ||
users.groups.${cfg.group} = {}; | ||
}; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ stdenv, lib, fetchFromGitHub, rustPlatform }: | ||
|
||
rustPlatform.buildRustPackage rec { | ||
pname = "liana"; | ||
version = "5.0"; | ||
|
||
src = fetchFromGitHub { | ||
owner = "wizardsardine"; | ||
repo = pname; | ||
rev = version; | ||
hash = "sha256-RkZ2HSN7IjwN3tD0UhpMeQeqkb+Y79kSWnjJZ5KPbQk="; | ||
}; | ||
|
||
cargoHash = "sha256-v3tMz93mNsTy0k27IzgYk9bL2VfqtXImMlnvwgswp6U="; | ||
|
||
meta = { | ||
description = "The missing safety net for your coins"; | ||
homepage = "https://wizardsardine.com/liana/"; | ||
license = lib.licenses.bsd3; | ||
}; | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't it better to move these hardcoded defaults to
example
instead ofdefault
.I can see easily an user shooting himself in the foot.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ideally this should come from
options.services.lianad.*
, and it definitely makes sense to remove this default value, but with the tradeoff thatoptions.services.lianad.main_descriptor
must become a mandatory option.unfortunately
lianad
's CLI is still very limited, so everything needs to be written indo aconfig.toml
, andlianad
will not start unless there is a valid descriptor insideconfig.toml
so the challenge here is:
lianad_config_example.toml
asoptions.services.lianad.*
insidemodules/liana.nix
so they're available assystemd
configurations (which seems to be the most common pattern acrossnix-bitcoin
modules)options.services.lianad.*
and used to generate aconfig.toml
on the module's output (ideally placed somewhere like/var/lib/lianad
)I started doing a heredoc inside the
preStart
but still unsure whether that is the best approach. It feels a bit dirty tbh.Also, while the variables are still hardcoded on the heredoc, the idea is to take their actual values from
options.services.lianad.*
. There heredoc includes some comments. But again: heredoc might not be the best approach.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes but still in a footgun for the user.
Check my comment below on how to interpolate TOML file contents into a string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not really, this is a proposal to mitigate the footgun
options.services.lianad.main_descriptor
on theirconfiguration.nix
, which in turn is used to dynamically generate aconfig.toml
file on disk of the output's datadirsystemd
service, because there's no validconfig.toml
in diskthe heredoc is still hardcoding things, but hopefully something along these lines will be a viable approach:
I'll give it a try at some time later.