/
rimgo.nix
107 lines (105 loc) · 2.65 KB
/
rimgo.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
{
config,
lib,
pkgs,
...
}:
let
cfg = config.services.rimgo;
inherit (lib)
mkOption
mkEnableOption
mkPackageOption
mkDefault
mkIf
types
literalExpression
optionalString
getExe
mapAttrs
;
in
{
options.services.rimgo = {
enable = mkEnableOption "rimgo";
package = mkPackageOption pkgs "rimgo" { };
settings = mkOption {
type = types.submodule {
freeformType = with types; attrsOf str;
options = {
PORT = mkOption {
type = types.port;
default = 3000;
example = 69420;
description = "The port to use.";
};
ADDRESS = mkOption {
type = types.str;
default = "127.0.0.1";
example = "1.1.1.1";
description = "The address to listen on.";
};
};
};
example = literalExpression ''
{
PORT = 69420;
FORCE_WEBP = "1";
}
'';
description = ''
Settings for rimgo, see [the official documentation](https://rimgo.codeberg.page/docs/usage/configuration/) for supported options.
'';
};
};
config = mkIf cfg.enable {
systemd.services.rimgo = {
description = "Rimgo";
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];
environment = mapAttrs (_: toString) cfg.settings;
serviceConfig = {
ExecStart = getExe cfg.package;
AmbientCapabilities = mkIf (cfg.settings.PORT < 1024) [
"CAP_NET_BIND_SERVICE"
];
DynamicUser = true;
Restart = "on-failure";
RestartSec = "5s";
CapabilityBoundingSet = [
(optionalString (cfg.settings.PORT < 1024) "CAP_NET_BIND_SERVICE")
];
DeviceAllow = [ "" ];
LockPersonality = true;
MemoryDenyWriteExecute = true;
PrivateDevices = true;
PrivateUsers = cfg.settings.PORT >= 1024;
ProcSubset = "pid";
ProtectClock = true;
ProtectControlGroups = true;
ProtectHome = true;
ProtectHostname = true;
ProtectKernelLogs = true;
ProtectKernelModules = true;
ProtectKernelTunables = true;
ProtectProc = "invisible";
RestrictAddressFamilies = [
"AF_INET"
"AF_INET6"
];
RestrictNamespaces = true;
RestrictRealtime = true;
RestrictSUIDSGID = true;
SystemCallArchitectures = "native";
SystemCallFilter = [
"@system-service"
"~@privileged"
];
UMask = "0077";
};
};
};
meta = {
maintainers = with lib.maintainers; [ quantenzitrone ];
};
}