2018-06-28 13:16:37 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
# search also generates ddclient entries for all other logs
|
|
|
|
|
|
|
|
with import <stockholm/lib>;
|
|
|
|
let
|
|
|
|
ddclientUser = "ddclient";
|
|
|
|
sec = toString <secrets>;
|
|
|
|
nsupdate = import "${sec}/nsupdate-hub.nix";
|
|
|
|
stateDir = "/var/spool/ddclient";
|
|
|
|
cfg = "${stateDir}/cfg";
|
|
|
|
ext-if = config.makefu.server.primary-itf;
|
|
|
|
ddclientPIDFile = "${stateDir}/ddclient.pid";
|
|
|
|
|
|
|
|
# TODO: correct cert generation requires a `real` internet ip address
|
|
|
|
|
|
|
|
gen-cfg = dict: ''
|
|
|
|
ssl=yes
|
|
|
|
cache=${stateDir}/ddclient.cache
|
|
|
|
pid=${ddclientPIDFile}
|
|
|
|
${concatStringsSep "\n" (mapAttrsToList (user: pass: ''
|
|
|
|
|
|
|
|
protocol=dyndns2
|
|
|
|
use=web, web=http://ipv4.nsupdate.info/myip
|
|
|
|
ssl=yes
|
|
|
|
server=ipv4.nsupdate.info
|
|
|
|
login=${user}
|
|
|
|
password='${pass}'
|
|
|
|
${user}
|
|
|
|
|
|
|
|
'') dict)}
|
|
|
|
'';
|
2018-09-13 20:54:55 +00:00
|
|
|
uhubDir = "/var/lib/uhub";
|
2018-06-28 13:16:37 +00:00
|
|
|
|
|
|
|
in {
|
2021-06-05 13:08:59 +00:00
|
|
|
users.users."${ddclientUser}" = {
|
2018-06-28 13:16:37 +00:00
|
|
|
uid = genid "ddclient";
|
|
|
|
description = "ddclient daemon user";
|
|
|
|
home = stateDir;
|
2021-06-05 13:08:59 +00:00
|
|
|
isSystemUser = true;
|
2018-06-28 13:16:37 +00:00
|
|
|
createHome = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd.services = {
|
|
|
|
ddclient-nsupdate-uhub = {
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
after = [ "ip-up.target" ];
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "forking";
|
|
|
|
User = ddclientUser;
|
|
|
|
PIDFile = ddclientPIDFile;
|
|
|
|
ExecStartPre = pkgs.writeDash "init-nsupdate" ''
|
|
|
|
cp -vf ${pkgs.writeText "ddclient-config" (gen-cfg nsupdate)} ${cfg}
|
|
|
|
chmod 700 ${cfg}
|
|
|
|
'';
|
|
|
|
ExecStart = "${pkgs.ddclient}/bin/ddclient -verbose -daemon 1 -noquiet -file ${cfg}";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
networking.firewall.extraCommands = ''
|
|
|
|
iptables -A PREROUTING -t nat -i ${ext-if} -p tcp --dport 411 -j REDIRECT --to-port 1511
|
|
|
|
'';
|
|
|
|
systemd.services.uhub.serviceConfig = {
|
|
|
|
PrivateTmp = true;
|
|
|
|
PermissionsStartOnly = true;
|
|
|
|
ExecStartPre = pkgs.writeDash "uhub-pre" ''
|
2018-09-13 20:54:55 +00:00
|
|
|
cp -f ${toString <secrets/wildcard.krebsco.de.crt>} ${uhubDir}/uhub.crt
|
|
|
|
cp -f ${toString <secrets/wildcard.krebsco.de.key>} ${uhubDir}/uhub.key
|
|
|
|
if test -d ${uhubDir};then
|
|
|
|
echo "Directory ${uhubDir} already exists, skipping db init"
|
|
|
|
else
|
|
|
|
echo "Copying sql user db"
|
|
|
|
cp ${toString <secrets/uhub.sql>} ${uhubDir}/uhub.sql
|
|
|
|
fi
|
|
|
|
chown -R uhub ${uhubDir}
|
2018-06-28 13:16:37 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
};
|
2018-09-13 20:54:55 +00:00
|
|
|
users.users.uhub = {
|
|
|
|
home = uhubDir;
|
|
|
|
createHome = true;
|
2021-12-04 19:12:59 +00:00
|
|
|
isSystemUser = true;
|
|
|
|
group = "uhub";
|
2018-09-13 20:54:55 +00:00
|
|
|
};
|
2021-12-04 19:12:59 +00:00
|
|
|
users.group.uhub = {};
|
|
|
|
services.uhub.home = {
|
2018-06-28 13:16:37 +00:00
|
|
|
enable = true;
|
|
|
|
port = 1511;
|
|
|
|
enableTLS = true;
|
|
|
|
hubConfig = ''
|
|
|
|
hub_name = "krebshub"
|
2018-09-13 20:54:55 +00:00
|
|
|
tls_certificate = ${uhubDir}/uhub.crt
|
|
|
|
tls_private_key = ${uhubDir}/uhub.key
|
|
|
|
registered_users_only = true
|
2018-06-28 13:16:37 +00:00
|
|
|
'';
|
|
|
|
plugins = {
|
|
|
|
welcome = {
|
|
|
|
enable = true;
|
|
|
|
motd = "shareit";
|
|
|
|
rules = "1. Don't be an asshole";
|
|
|
|
};
|
|
|
|
history = {
|
|
|
|
enable = true;
|
|
|
|
};
|
|
|
|
authSqlite = {
|
|
|
|
enable = true;
|
2018-09-13 20:54:55 +00:00
|
|
|
file = "${uhubDir}/uhub.sql";
|
2018-06-28 13:16:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
networking.firewall.allowedTCPPorts = [ 411 1511 ];
|
|
|
|
}
|