2 { config, lib, pkgs, ... }:
7 cfg = config.services.namecoind;
8 dataDir = "/var/lib/namecoind";
9 useSSL = (cfg.rpc.certificate != null) && (cfg.rpc.key != null);
10 useRPC = (cfg.rpc.user != null) && (cfg.rpc.password != null);
12 listToConf = option: list:
13 concatMapStrings (value :"${option}=${value}\n") list;
15 configFile = pkgs.writeText "namecoin.conf" (''
20 walletpath=${cfg.wallet}
21 gen=${if cfg.generate then "1" else "0"}
22 ${listToConf "addnode" cfg.extraNodes}
23 ${listToConf "connect" cfg.trustedNodes}
24 '' + optionalString useRPC ''
25 rpcbind=${cfg.rpc.address}
26 rpcport=${toString cfg.rpc.port}
27 rpcuser=${cfg.rpc.user}
28 rpcpassword=${cfg.rpc.password}
29 ${listToConf "rpcallowip" cfg.rpc.allowFrom}
30 '' + optionalString useSSL ''
32 rpcsslcertificatechainfile=${cfg.rpc.certificate}
33 rpcsslprivatekeyfile=${cfg.rpc.key}
34 rpcsslciphers=TLSv1.2+HIGH:TLSv1+HIGH:!SSLv2:!aNULL:!eNULL:!3DES:@STRENGTH
45 services.namecoind = {
47 enable = mkEnableOption "namecoind, Namecoin client";
51 default = "${dataDir}/wallet.dat";
53 Wallet file. The ownership of the file has to be
54 namecoin:namecoin, and the permissions must be 0640.
62 Whether to generate (mine) Namecoins.
66 extraNodes = mkOption {
67 type = types.listOf types.str;
70 List of additional peer IP addresses to connect to.
74 trustedNodes = mkOption {
75 type = types.listOf types.str;
78 List of the only peer IP addresses to connect to. If specified
79 no other connection will be made.
84 type = types.nullOr types.str;
87 User name for RPC connections.
91 rpc.password = mkOption {
92 type = types.nullOr types.str;
95 Password for RPC connections.
99 rpc.address = mkOption {
103 IP address the RPC server will bind to.
107 rpc.port = mkOption {
111 Port the RPC server will bind to.
115 rpc.certificate = mkOption {
116 type = types.nullOr types.path;
118 example = "/var/lib/namecoind/server.cert";
120 Certificate file for securing RPC connections.
125 type = types.nullOr types.path;
127 example = "/var/lib/namecoind/server.pem";
129 Key file for securing RPC connections.
134 rpc.allowFrom = mkOption {
135 type = types.listOf types.str;
136 default = [ "127.0.0.1" ];
138 List of IP address ranges allowed to use the RPC API.
139 Wiledcards (*) can be user to specify a range.
148 ###### implementation
150 config = mkIf cfg.enable {
152 users.users.namecoin = {
153 uid = config.ids.uids.namecoin;
154 description = "Namecoin daemon user";
159 users.groups.namecoin = {
160 gid = config.ids.gids.namecoin;
163 systemd.services.namecoind = {
164 description = "Namecoind daemon";
165 after = [ "network.target" ];
166 wantedBy = [ "multi-user.target" ];
168 startLimitIntervalSec = 120;
173 ExecStart = "${pkgs.namecoind}/bin/namecoind -conf=${configFile} -datadir=${dataDir} -printtoconsole";
174 ExecStop = "${pkgs.coreutils}/bin/kill -KILL $MAINPID";
175 ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
178 TimeoutStopSec = "60s";
179 TimeoutStartSec = "2s";
183 preStart = optionalString (cfg.wallet != "${dataDir}/wallet.dat") ''
184 # check wallet file permissions
185 if [ "$(stat --printf '%u' ${cfg.wallet})" != "${toString config.ids.uids.namecoin}" \
186 -o "$(stat --printf '%g' ${cfg.wallet})" != "${toString config.ids.gids.namecoin}" \
187 -o "$(stat --printf '%a' ${cfg.wallet})" != "640" ]; then
188 echo "ERROR: bad ownership or rights on ${cfg.wallet}" >&2
197 meta.maintainers = with lib.maintainers; [ rnhmjoj ];