nix-config/config/services/pr-tracker.nix

145 lines
4 KiB
Nix
Raw Normal View History

2024-07-19 07:01:37 +02:00
{
config,
nodes,
lib,
pkgs,
...
2024-07-26 22:12:48 +02:00
}:
let
2024-07-19 07:01:37 +02:00
prestart = pkgs.writeShellScript "pr-tracker-pre" ''
2024-07-19 22:53:10 +02:00
if [ ! -d ./nixpkgs ]; then
2024-07-19 07:01:37 +02:00
${lib.getExe pkgs.git} clone https://github.com/NixOS/nixpkgs.git
fi
'';
2024-07-26 22:12:48 +02:00
in
{
2024-07-19 22:53:10 +02:00
wireguard.elisabeth = {
client.via = "elisabeth";
2024-07-26 22:12:48 +02:00
firewallRuleForNode.elisabeth.allowedTCPPorts = [ 3000 ];
2024-07-19 22:53:10 +02:00
};
2024-07-26 22:12:48 +02:00
networking.firewall.allowedTCPPorts = [ 3000 ];
2024-07-19 07:01:37 +02:00
environment.persistence."/persist".directories = [
{
directory = "/var/lib/pr-tracker";
user = "pr-tracker";
group = "pr-tracker";
mode = "0700";
}
];
age.secrets.maddyPasswd = {
generator.script = "alnum";
owner = "pr-tracker";
};
age.secrets.prTrackerEnv = {
2024-07-19 22:53:10 +02:00
rekeyFile = config.node.secretsDir + "/env.age";
2024-07-19 07:01:37 +02:00
owner = "pr-tracker";
};
age.secrets.prTrackerWhiteList = {
2024-07-19 22:53:10 +02:00
rekeyFile = config.node.secretsDir + "/white-list.age";
2024-07-19 07:01:37 +02:00
owner = "pr-tracker";
};
nodes.maddy = {
age.secrets.pr-trackerPasswd = {
inherit (config.age.secrets.maddyPasswd) rekeyFile;
inherit (nodes.maddy.config.services.maddy) group;
mode = "640";
};
services.maddy.ensureCredentials = {
2024-07-26 22:12:48 +02:00
"pr-tracker@${config.secrets.secrets.global.domains.mail_public}".passwordFile =
nodes.maddy.config.age.secrets.pr-trackerPasswd.path;
2024-07-19 07:01:37 +02:00
};
};
systemd.sockets.pr-tracker = {
2024-07-26 22:12:48 +02:00
listenStreams = [ "0.0.0.0:3000" ];
wantedBy = [ "sockets.target" ];
2024-07-19 07:01:37 +02:00
};
systemd.services.pr-tracker = {
2024-07-26 22:12:48 +02:00
path = [ pkgs.git ];
2024-07-19 07:01:37 +02:00
serviceConfig = {
User = "pr-tracker";
Group = "pr-tracker";
StateDirectory = "pr-tracker";
WorkingDirectory = "/var/lib/pr-tracker";
LimitNOFILE = "1048576";
PrivateTmp = true;
PrivateDevices = true;
StateDirectoryMode = "0700";
Restart = "always";
ExecStartPre = prestart;
2024-07-19 22:53:10 +02:00
ExecStart = ''
2024-07-20 18:50:49 +02:00
${lib.getExe pkgs.pr-tracker} --url "https://pr-tracker.${config.secrets.secrets.global.domains.web}"\
2024-07-26 22:12:21 +02:00
--user-agent "Patricks pr-tracker" \
--path nixpkgs --remote origin \
--email-white-list ${config.age.secrets.prTrackerWhiteList.path} \
--email-address pr-tracker@${config.secrets.secrets.global.domains.mail_public} \
--email-server smtp.${config.secrets.secrets.global.domains.mail_public} \
2024-07-19 22:53:10 +02:00
'';
2024-07-19 07:01:37 +02:00
EnvironmentFile = config.age.secrets.prTrackerEnv.path;
# Hardening
CapabilityBoundingSet = "";
LockPersonality = true;
MemoryDenyWriteExecute = true;
PrivateUsers = true;
ProtectClock = true;
ProtectControlGroups = true;
ProtectHome = true;
ProtectHostname = true;
ProtectKernelLogs = true;
ProtectKernelModules = true;
ProtectKernelTunables = true;
ProtectProc = "invisible";
ProcSubset = "pid";
ProtectSystem = "strict";
RestrictAddressFamilies = [
"AF_INET"
"AF_INET6"
"AF_NETLINK"
];
RestrictNamespaces = true;
RestrictRealtime = true;
SystemCallArchitectures = "native";
SystemCallFilter = [
"@system-service"
"@pkey"
];
UMask = "0077";
};
};
systemd.timers.pr-tracker-update = {
2024-07-26 22:12:48 +02:00
wantedBy = [ "timers.target" ];
2024-07-19 07:01:37 +02:00
timerConfig = {
OnBootSec = "30m";
OnUnitActiveSec = "30m";
};
};
2024-07-26 22:12:48 +02:00
users.groups.pr-tracker = { };
2024-07-19 22:53:10 +02:00
users.users.pr-tracker = {
isSystemUser = true;
group = "pr-tracker";
home = "/var/lib/pr-tracker";
};
2024-07-19 07:01:37 +02:00
systemd.services.pr-tracker-update = {
script = ''
set -eu
${lib.getExe pkgs.git} -C nixpkgs fetch
${lib.getExe pkgs.curl} http://localhost:3000/update
'';
serviceConfig = {
Requires = "pr-tracker";
Type = "oneshot";
User = "pr-tracker";
Group = "pr-tracker";
StateDirectory = "pr-tracker";
WorkingDirectory = "/var/lib/pr-tracker";
LimitNOFILE = "1048576";
PrivateTmp = true;
PrivateDevices = true;
StateDirectoryMode = "0700";
ExecStartPre = prestart;
EnvironmentFile = config.age.secrets.prTrackerEnv.path;
};
};
}