11 cfg = config.services.namecoind;
12 dataDir = "/var/lib/namecoind";
13 useSSL = (cfg.rpc.certificate != null) && (cfg.rpc.key != null);
14 useRPC = (cfg.rpc.user != null) && (cfg.rpc.password != null);
16 listToConf = option: list: concatMapStrings (value: "${option}=${value}\n") list;
18 configFile = pkgs.writeText "namecoin.conf" (
24 walletpath=${cfg.wallet}
25 gen=${if cfg.generate then "1" else "0"}
26 ${listToConf "addnode" cfg.extraNodes}
27 ${listToConf "connect" cfg.trustedNodes}
29 + optionalString useRPC ''
30 rpcbind=${cfg.rpc.address}
31 rpcport=${toString cfg.rpc.port}
32 rpcuser=${cfg.rpc.user}
33 rpcpassword=${cfg.rpc.password}
34 ${listToConf "rpcallowip" cfg.rpc.allowFrom}
36 + optionalString useSSL ''
38 rpcsslcertificatechainfile=${cfg.rpc.certificate}
39 rpcsslprivatekeyfile=${cfg.rpc.key}
40 rpcsslciphers=TLSv1.2+HIGH:TLSv1+HIGH:!SSLv2:!aNULL:!eNULL:!3DES:@STRENGTH
52 services.namecoind = {
54 enable = mkEnableOption "namecoind, Namecoin client";
58 default = "${dataDir}/wallet.dat";
60 Wallet file. The ownership of the file has to be
61 namecoin:namecoin, and the permissions must be 0640.
69 Whether to generate (mine) Namecoins.
73 extraNodes = mkOption {
74 type = types.listOf types.str;
77 List of additional peer IP addresses to connect to.
81 trustedNodes = mkOption {
82 type = types.listOf types.str;
85 List of the only peer IP addresses to connect to. If specified
86 no other connection will be made.
91 type = types.nullOr types.str;
94 User name for RPC connections.
98 rpc.password = mkOption {
99 type = types.nullOr types.str;
102 Password for RPC connections.
106 rpc.address = mkOption {
110 IP address the RPC server will bind to.
114 rpc.port = mkOption {
118 Port the RPC server will bind to.
122 rpc.certificate = mkOption {
123 type = types.nullOr types.path;
125 example = "/var/lib/namecoind/server.cert";
127 Certificate file for securing RPC connections.
132 type = types.nullOr types.path;
134 example = "/var/lib/namecoind/server.pem";
136 Key file for securing RPC connections.
140 rpc.allowFrom = mkOption {
141 type = types.listOf types.str;
142 default = [ "127.0.0.1" ];
144 List of IP address ranges allowed to use the RPC API.
145 Wiledcards (*) can be user to specify a range.
153 ###### implementation
155 config = mkIf cfg.enable {
157 users.users.namecoin = {
158 uid = config.ids.uids.namecoin;
159 description = "Namecoin daemon user";
164 users.groups.namecoin = {
165 gid = config.ids.gids.namecoin;
168 systemd.services.namecoind = {
169 description = "Namecoind daemon";
170 after = [ "network.target" ];
171 wantedBy = [ "multi-user.target" ];
173 startLimitIntervalSec = 120;
178 ExecStart = "${pkgs.namecoind}/bin/namecoind -conf=${configFile} -datadir=${dataDir} -printtoconsole";
179 ExecStop = "${pkgs.coreutils}/bin/kill -KILL $MAINPID";
180 ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
183 TimeoutStopSec = "60s";
184 TimeoutStartSec = "2s";
188 preStart = optionalString (cfg.wallet != "${dataDir}/wallet.dat") ''
189 # check wallet file permissions
190 if [ "$(stat --printf '%u' ${cfg.wallet})" != "${toString config.ids.uids.namecoin}" \
191 -o "$(stat --printf '%g' ${cfg.wallet})" != "${toString config.ids.gids.namecoin}" \
192 -o "$(stat --printf '%a' ${cfg.wallet})" != "640" ]; then
193 echo "ERROR: bad ownership or rights on ${cfg.wallet}" >&2
202 meta.maintainers = with lib.maintainers; [ rnhmjoj ];