12 inherit (pkgs) nntp-proxy;
14 cfg = config.services.nntp-proxy;
16 configBool = b: if b then "TRUE" else "FALSE";
18 confFile = pkgs.writeText "nntp-proxy.conf" ''
21 # NNTP Server host and port address
22 server = "${cfg.upstreamServer}";
23 port = ${toString cfg.upstreamPort};
25 username = "${cfg.upstreamUser}";
26 # NNTP password in clear text
27 password = "${cfg.upstreamPassword}";
28 # Maximum number of connections allowed by the NNTP
29 max_connections = ${toString cfg.upstreamMaxConnections};
34 # Local address and port to bind to
35 bind_ip = "${cfg.listenAddress}";
36 bind_port = ${toString cfg.port};
38 # SSL key and cert file
39 ssl_key = "${cfg.sslKey}";
40 ssl_cert = "${cfg.sslCert}";
42 # prohibit users from posting
43 prohibit_posting = ${configBool cfg.prohibitPosting};
44 # Verbose levels: ERROR, WARNING, NOTICE, INFO, DEBUG
45 verbose = "${toUpper cfg.verbosity}";
46 # Password is made with: 'mkpasswd -m sha-512 <password>'
48 concatStringsSep ",\n" (
49 mapAttrsToList (username: userConfig: ''
51 username = "${username}";
52 password = "${userConfig.passwordHash}";
53 max_connections = ${toString userConfig.maxConnections};
69 services.nntp-proxy = {
70 enable = mkEnableOption "NNTP-Proxy";
72 upstreamServer = mkOption {
75 example = "ssl-eu.astraweb.com";
77 Upstream server address
81 upstreamPort = mkOption {
89 upstreamMaxConnections = mkOption {
93 Upstream server maximum allowed concurrent connections
97 upstreamUser = mkOption {
101 Upstream server username
105 upstreamPassword = mkOption {
109 Upstream server password
113 listenAddress = mkOption {
115 default = "127.0.0.1";
118 Proxy listen address (IPv6 literal addresses need to be enclosed in "[" and "]" characters)
133 example = "/path/to/your/key.file";
141 default = "cert.pem";
142 example = "/path/to/your/cert.file";
144 Proxy ssl certificate path
148 prohibitPosting = mkOption {
152 Whether to prohibit posting to the upstream server
156 verbosity = mkOption {
172 type = types.attrsOf (
175 username = mkOption {
182 passwordHash = mkOption {
184 example = "$6$GtzE7FrpE$wwuVgFYU.TZH4Rz.Snjxk9XGua89IeVwPQ/fEUD8eujr40q5Y021yhn0aNcsQ2Ifw.BLclyzvzgegopgKcneL0";
186 SHA-512 password hash (can be generated by
187 `mkpasswd -m sha-512 <password>`)
191 maxConnections = mkOption {
195 Maximum number of concurrent connections to the proxy for this user
202 NNTP-Proxy user configuration
206 example = literalExpression ''
209 passwordHash = "$6$1l0t5Kn2Dk$appzivc./9l/kjq57eg5UCsBKlcfyCr0zNWYNerKoPsI1d7eAwiT0SVsOVx/CTgaBNT/u4fi2vN.iGlPfv1ek0";
213 passwordHash = "$6$6lwEsWB.TmsS$W7m1riUx4QrA8pKJz8hvff0dnF1NwtZXgdjmGqA1Dx2MDPj07tI9GNcb0SWlMglE.2/hBgynDdAd/XqqtRqVQ0";
223 ###### implementation
225 config = mkIf cfg.enable {
227 users.users.nntp-proxy = {
229 group = "nntp-proxy";
230 description = "NNTP-Proxy daemon user";
232 users.groups.nntp-proxy = { };
234 systemd.services.nntp-proxy = {
235 description = "NNTP proxy";
240 wantedBy = [ "multi-user.target" ];
244 serviceConfig.ExecStart = "${nntp-proxy}/bin/nntp-proxy ${confFile}";
246 if [ ! \( -f ${cfg.sslCert} -a -f ${cfg.sslKey} \) ]; then
247 ${pkgs.openssl.bin}/bin/openssl req -subj '/CN=AutoGeneratedCert/O=NixOS Service/C=US' \
248 -new -newkey rsa:2048 -days 365 -nodes -x509 -keyout ${cfg.sslKey} -out ${cfg.sslCert};