10 cfg = config.services.wasabibackend;
11 opt = options.services.wasabibackend;
25 BitcoinRpcConnectionString = "${cfg.rpc.user}:${cfg.rpc.password}";
27 // optionalAttrs (cfg.network == "mainnet") {
29 MainNetBitcoinP2pEndPoint = "${cfg.endpoint.ip}:${toString cfg.endpoint.port}";
30 MainNetBitcoinCoreRpcEndPoint = "${cfg.rpc.ip}:${toString cfg.rpc.port}";
32 // optionalAttrs (cfg.network == "testnet") {
34 TestNetBitcoinP2pEndPoint = "${cfg.endpoint.ip}:${toString cfg.endpoint.port}";
35 TestNetBitcoinCoreRpcEndPoint = "${cfg.rpc.ip}:${toString cfg.rpc.port}";
37 // optionalAttrs (cfg.network == "regtest") {
39 RegTestBitcoinP2pEndPoint = "${cfg.endpoint.ip}:${toString cfg.endpoint.port}";
40 RegTestBitcoinCoreRpcEndPoint = "${cfg.rpc.ip}:${toString cfg.rpc.port}";
43 configFile = pkgs.writeText "wasabibackend.conf" (builtins.toJSON confOptions);
50 services.wasabibackend = {
51 enable = mkEnableOption "Wasabi backend service";
55 default = "/var/lib/wasabibackend";
56 description = "The data directory for the Wasabi backend node.";
59 customConfigFile = mkOption {
60 type = types.nullOr types.path;
62 description = "Defines the path to a custom configuration file that is copied to the user's directory. Overrides any config options.";
72 description = "The network to use for the Wasabi backend service.";
78 default = "127.0.0.1";
79 description = "IP address for P2P connection to bitcoind.";
85 description = "Port for P2P connection to bitcoind.";
92 default = "127.0.0.1";
93 description = "IP address for RPC connection to bitcoind.";
99 description = "Port for RPC connection to bitcoind.";
105 description = "RPC user for the bitcoin endpoint.";
108 password = mkOption {
110 default = "password";
111 description = "RPC password for the bitcoin endpoint. Warning: this is stored in cleartext in the Nix store! Use `configFile` or `passwordFile` if needed.";
114 passwordFile = mkOption {
115 type = types.nullOr types.path;
117 description = "File that contains the password of the RPC user.";
123 default = "wasabibackend";
124 description = "The user as which to run the wasabibackend node.";
130 defaultText = literalExpression "config.${opt.user}";
131 description = "The group as which to run the wasabibackend node.";
136 config = mkIf cfg.enable {
138 systemd.tmpfiles.rules = [
139 "d '${cfg.dataDir}' 0770 '${cfg.user}' '${cfg.group}' - -"
142 systemd.services.wasabibackend = {
143 description = "wasabibackend server";
144 wantedBy = [ "multi-user.target" ];
145 wants = [ "network-online.target" ];
146 after = [ "network-online.target" ];
148 DOTNET_PRINT_TELEMETRY_MESSAGE = "false";
149 DOTNET_CLI_TELEMETRY_OPTOUT = "true";
152 mkdir -p ${cfg.dataDir}/.walletwasabi/backend
154 if cfg.customConfigFile != null then
156 cp -v ${cfg.customConfigFile} ${cfg.dataDir}/.walletwasabi/backend/Config.json
160 cp -v ${configFile} ${cfg.dataDir}/.walletwasabi/backend/Config.json
161 ${optionalString (cfg.rpc.passwordFile != null) ''
163 cat ${cfg.dataDir}/.walletwasabi/backend/Config.json | ${pkgs.jq}/bin/jq --arg rpconnection "${cfg.rpc.user}:$(cat "${cfg.rpc.passwordFile}")" '. + { BitcoinRpcConnectionString: $rpconnection }' > $CONFIGTMP
164 mv $CONFIGTMP ${cfg.dataDir}/.walletwasabi/backend/Config.json
168 chmod ug+w ${cfg.dataDir}/.walletwasabi/backend/Config.json
173 ExecStart = "${pkgs.wasabibackend}/bin/WasabiBackend";
174 ProtectSystem = "full";
178 users.users.${cfg.user} = {
181 description = "wasabibackend daemon user";
186 users.groups.${cfg.group} = { };