2024-10-19 04:54:55 +00:00
|
|
|
{
|
|
|
|
lib,
|
|
|
|
pkgs,
|
|
|
|
inputs,
|
|
|
|
...
|
|
|
|
}:
|
|
|
|
let
|
2024-10-26 07:42:14 +00:00
|
|
|
pkgs' = inputs.ip-checker.packages.${pkgs.stdenv.hostPlatform.system};
|
2024-10-19 04:54:55 +00:00
|
|
|
in
|
|
|
|
{
|
|
|
|
systemd.services."ip-checker" = {
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
2024-10-19 09:30:29 +00:00
|
|
|
environment = {
|
2024-10-25 13:50:23 +00:00
|
|
|
IP_CHECKER_ASN_DB = pkgs.dbip-asn-lite.mmdb;
|
|
|
|
IP_CHECKER_CITY_DB = pkgs.dbip-city-lite.mmdb;
|
2024-11-07 03:31:03 +00:00
|
|
|
IP_CHECKER_LISTEN = "unix//run/ip-checker/ip-checker.sock";
|
|
|
|
IP_CHECKER_MODE = "prod";
|
|
|
|
IP_CHECKER_SOCKET_PERMISSION = "0770";
|
2024-10-19 09:30:29 +00:00
|
|
|
};
|
2024-10-19 04:54:55 +00:00
|
|
|
serviceConfig = {
|
2024-10-26 07:42:14 +00:00
|
|
|
ExecStart = lib.getExe pkgs'.api;
|
2024-11-07 03:31:03 +00:00
|
|
|
RuntimeDirectory = "ip-checker";
|
|
|
|
Group = "ip-checker";
|
2024-10-19 04:54:55 +00:00
|
|
|
|
|
|
|
CapabilityBoundingSet = "";
|
|
|
|
DynamicUser = true;
|
|
|
|
LockPersonality = true;
|
|
|
|
MemoryDenyWriteExecute = true;
|
|
|
|
NoNewPrivileges = true;
|
|
|
|
PrivateDevices = true;
|
|
|
|
PrivateUsers = true;
|
|
|
|
ProcSubset = "pid";
|
|
|
|
ProtectClock = true;
|
|
|
|
ProtectControlGroups = true;
|
|
|
|
ProtectHome = true;
|
|
|
|
ProtectHostname = true;
|
|
|
|
ProtectKernelLogs = true;
|
|
|
|
ProtectKernelModules = true;
|
|
|
|
ProtectKernelTunables = true;
|
|
|
|
ProtectProc = "invisible";
|
|
|
|
ProtectSystem = "strict";
|
|
|
|
RestrictNamespaces = true;
|
|
|
|
RestrictRealtime = true;
|
|
|
|
RestrictSUIDSGID = true;
|
|
|
|
SystemCallArchitectures = "native";
|
|
|
|
SystemCallErrorNumber = "EPERM";
|
|
|
|
SystemCallFilter = "@system-service";
|
|
|
|
UMask = "0077";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-11-07 03:31:03 +00:00
|
|
|
systemd.services."caddy".serviceConfig.SupplementaryGroups = [ "ip-checker" ];
|
|
|
|
|
2024-10-19 04:54:55 +00:00
|
|
|
services.caddy.settings.apps.http.servers.srv0.routes = lib.singleton {
|
|
|
|
match = lib.singleton { host = [ "ip.ny4.dev" ]; };
|
|
|
|
handle = lib.singleton {
|
2024-10-25 13:50:23 +00:00
|
|
|
handler = "subroute";
|
|
|
|
routes = [
|
|
|
|
# TODO: make `curl ip.ny4.dev` work
|
|
|
|
{
|
|
|
|
match = [ { path = [ "/api/v1/*" ]; } ];
|
|
|
|
handle = lib.singleton {
|
|
|
|
handler = "reverse_proxy";
|
2024-11-07 03:31:03 +00:00
|
|
|
upstreams = lib.singleton { dial = "unix//run/ip-checker/ip-checker.sock"; };
|
2024-10-25 13:50:23 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
{
|
|
|
|
handle = lib.singleton {
|
|
|
|
handler = "file_server";
|
2024-10-26 07:42:14 +00:00
|
|
|
root = pkgs'.ui;
|
2024-10-25 13:50:23 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
];
|
2024-10-19 04:54:55 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|