2022-09-29 03:24:56 +01:00
|
|
|
{
|
|
|
|
self,
|
|
|
|
system,
|
|
|
|
}: {
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
...
|
|
|
|
}: let
|
|
|
|
inherit (lib) mkEnableOption mkIf mkOption;
|
2024-01-02 14:06:58 +00:00
|
|
|
inherit (lib.types) str int;
|
2022-09-29 03:24:56 +01:00
|
|
|
inherit (lib.strings) escapeShellArgs;
|
|
|
|
inherit (self.packages.${system}) server templates;
|
|
|
|
|
|
|
|
cfg = config.services.tlaternet-webserver;
|
|
|
|
in {
|
|
|
|
options = {
|
|
|
|
services.tlaternet-webserver = {
|
|
|
|
enable = mkEnableOption "tlaternet web server";
|
2022-10-14 12:16:51 +01:00
|
|
|
listen = {
|
|
|
|
addr = mkOption {
|
|
|
|
type = str;
|
|
|
|
description = "IP address.";
|
|
|
|
default = "127.0.0.1";
|
|
|
|
};
|
2022-09-29 03:24:56 +01:00
|
|
|
|
2022-10-14 12:16:51 +01:00
|
|
|
port = mkOption {
|
|
|
|
type = int;
|
|
|
|
description = "Port number.";
|
|
|
|
default = 8000;
|
2022-09-29 03:24:56 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
systemd.services.tlaternet-webserver = {
|
|
|
|
description = "tlaternet webserver";
|
|
|
|
wantedBy = ["multi-user.target"];
|
|
|
|
after = ["network.target"];
|
|
|
|
|
|
|
|
script = escapeShellArgs [
|
|
|
|
"${server}/bin/tlaternet-webserver"
|
|
|
|
"--template-directory"
|
|
|
|
templates
|
|
|
|
"--address"
|
|
|
|
"${cfg.listen.addr}:${toString cfg.listen.port}"
|
|
|
|
];
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
Restart = "always";
|
|
|
|
|
|
|
|
DynamicUser = true;
|
|
|
|
ProtectHome = true; # Override the default (read-only)
|
|
|
|
PrivateDevices = true;
|
|
|
|
PrivateIPC = true;
|
|
|
|
PrivateUsers = true;
|
|
|
|
ProtectHostname = true;
|
|
|
|
ProtectClock = true;
|
|
|
|
ProtectKernelTunables = true;
|
|
|
|
ProtectKernelModules = true;
|
|
|
|
ProtectKernelLogs = true;
|
|
|
|
ProtectControlGroups = true;
|
|
|
|
RestrictAddressFamilies = ["AF_UNIX" "AF_INET" "AF_INET6"];
|
|
|
|
RestrictNamespaces = true;
|
|
|
|
LockPersonality = true;
|
|
|
|
MemoryDenyWriteExecute = true;
|
|
|
|
RestrictRealtime = true;
|
|
|
|
RestrictSUIDSGID = true;
|
|
|
|
SystemCallArchitectures = "native";
|
|
|
|
SystemCallFilter = ["@system-service" "~@privileged @resources @setuid @keyring"];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|