git.iko.soy/typeable/nixpkgs
on master help sign in
namecoind nixos module: init
commitb6fb7604846dfc5af2d5b999388e65c5bf43b3a0 authorThomas Strobel <ts468@cam.ac.uk> dateTue 8 Sep 2015, 19:24 (11 years ago) parent5e21271
3 files changed+131
nixos/modules/misc/ids.nix+2 nixos/modules/module-list.nix+1 nixos/modules/services/networking/namecoind.nix+128
nixos/modules/misc/ids.nix+2
@@ -229,6 +229,7 @@
229229 riak = 205;
230230 shout = 206;
231231 gateone = 207;
232+ namecoin = 208;
232233
233234 # When adding a uid, make sure it doesn't match an existing gid. And don't use uids above 399!
234235
@@ -436,6 +437,7 @@
436437 riak = 205;
437438 #shout = 206; #unused
438439 gateone = 207;
440+ #namecoin = 208; #unused
439441
440442 # When adding a gid, make sure it doesn't match an existing
441443 # uid. Users and groups with the same name should have equal
nixos/modules/module-list.nix+1
@@ -303,6 +303,7 @@
303303 ./services/networking/minidlna.nix
304304 ./services/networking/mstpd.nix
305305 ./services/networking/murmur.nix
306+ ./services/networking/namecoind.nix
306307 ./services/networking/nat.nix
307308 ./services/networking/networkmanager.nix
308309 ./services/networking/ngircd.nix
nixos/modules/services/networking/namecoind.nixnew file+128
@@ -0,0 +1,128 @@
1+{ config, lib, pkgs, ... }:
2+
3+with lib;
4+
5+let
6+ cfg = config.services.namecoind;
7+
8+ namecoinConf =
9+ let
10+ useSSL = (cfg.rpcCertificate != null) && (cfg.rpcKey != null);
11+ in
12+ pkgs.writeText "namecoin.conf" ''
13+ server=1
14+ daemon=0
15+ rpcallowip=127.0.0.1
16+ walletpath=${cfg.wallet}
17+ gen=${if cfg.generate then "1" else "0"}
18+ rpcssl=${if useSSL then "1" else "0"}
19+ ${optionalString useSSL "rpcsslcertificatechainfile=${cfg.rpcCertificate}"}
20+ ${optionalString useSSL "rpcsslprivatekeyfile=${cfg.rpcKey}"}
21+ ${optionalString useSSL "rpcsslciphers=TLSv1.2+HIGH:TLSv1+HIGH:!SSLv2:!aNULL:!eNULL:!3DES:@STRENGTH"}
22+ txindex=1
23+ txprevcache=1
24+ '';
25+
26+in
27+
28+{
29+
30+ ###### interface
31+
32+ options = {
33+
34+ services.namecoind = {
35+
36+ enable = mkOption {
37+ type = types.bool;
38+ default = false;
39+ description = ''
40+ Whether to run namecoind.
41+ '';
42+ };
43+
44+ wallet = mkOption {
45+ type = types.path;
46+ example = "/etc/namecoin/wallet.dat";
47+ description = ''
48+ Wallet file.
49+ '';
50+ };
51+
52+ userFile = mkOption {
53+ type = types.nullOr types.path;
54+ default = null;
55+ example = "/etc/namecoin/user";
56+ description = ''
57+ File containing the user name and user password to
58+ authenticate RPC connections to namecoind.
59+ The content of the file is of the form:
60+ <literal>
61+ USER=namecoin
62+ PASSWORD=secret
63+ </literal>
64+ '';
65+ };
66+
67+ generate = mkOption {
68+ type = types.bool;
69+ default = false;
70+ description = ''
71+ Whether to generate (mine) Namecoins.
72+ '';
73+ };
74+
75+ rpcCertificate = mkOption {
76+ type = types.nullOr types.path;
77+ default = null;
78+ example = "/etc/namecoin/server.cert";
79+ description = ''
80+ Certificate file for securing RPC connections.
81+ '';
82+ };
83+
84+ rpcKey = mkOption {
85+ type = types.nullOr types.path;
86+ default = null;
87+ example = "/etc/namecoin/server.pem";
88+ description = ''
89+ Key file for securing RPC connections.
90+ '';
91+ };
92+
93+ };
94+
95+ };
96+
97+
98+ ###### implementation
99+
100+ config = mkIf cfg.enable {
101+
102+ users.extraUsers = singleton
103+ { name = "namecoin";
104+ uid = config.ids.uids.namecoin;
105+ description = "Namecoin daemon user";
106+ home = "/var/lib/namecoin";
107+ createHome = true;
108+ };
109+
110+ systemd.services.namecoind = {
111+ description = "Namecoind Daemon";
112+ after = [ "network.target" ];
113+ wantedBy = [ "multi-user.target" ];
114+ serviceConfig = {
115+ Type = "simple";
116+ User = "namecoin";
117+ EnvironmentFile = cfg.userFile;
118+ ExecStart = "${pkgs.altcoins.namecoind}/bin/namecoind -conf=${namecoinConf} -rpcuser=$USER -rpcpassword=$PASSWORD -printtoconsole";
119+ ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
120+ ExecStop = "${pkgs.coreutils}/bin/kill -KILL $MAINPID";
121+ StandardOutput = "null";
122+ Nice = "10";
123+ };
124+ };
125+
126+ };
127+
128+}