blob: 318623638bdc6ce9625f157a12986f5a269d09be (
plain)
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
|
self:
{ config
, lib
, pkgs
, ...
}:
let
inherit (builtins) fromTOML readFile;
cfg = config.services.searchix;
package = self.packages.default;
defaults = fromTOML (readFile ../../defaults.toml);
settingsFormat = pkgs.formats.toml { };
defaultServiceConfig = {
User = cfg.user;
Group = cfg.group;
ReadWritePaths = [ cfg.homeDir ];
StateDirectory = mkIf (cfg.homeDir == "/var/lib/searchix") [ "searchix" ];
Restart = "on-failure";
CacheDirectory = "searchix";
CapabilityBoundingSet = "";
DeviceAllow = "";
LockPersonality = true;
MemoryDenyWriteExecute = true;
NoNewPrivileges = true;
PrivateDevices = true;
PrivateMounts = true;
PrivateTmp = true;
PrivateUsers = true;
ProtectClock = true;
ProtectHome = true;
ProtectHostname = true;
ProtectSystem = "strict";
ProtectControlGroups = true;
ProtectKernelLogs = true;
ProtectKernelModules = true;
ProtectKernelTunables = true;
RestrictAddressFamilies = [ "AF_UNIX" "AF_INET" "AF_INET6" ];
RestrictNamespaces = true;
RestrictRealtime = true;
RestrictSUIDSGID = true;
SystemCallArchitectures = "native";
SystemCallFilter = [ "@system-service" "~@privileged @setuid @keyring" ];
UMask = "0066";
};
inherit (lib) mkEnableOption mkOption mkIf optionalAttrs types;
in
{
options.services.searchix = {
enable = mkEnableOption "Searchix options search";
user = mkOption {
type = types.str;
default = "searchix";
description = "User account under which searchix runs.";
};
group = mkOption {
type = types.str;
default = "searchix";
description = "Group under which searchix runs.";
};
homeDir = mkOption {
type = types.path;
default = "/var/lib/searchix";
description = "Home directory for searchix user";
};
settings = mkOption {
default = { };
type = types.submodule {
freeformType = settingsFormat.type;
options = {
dataPath = mkOption {
type = types.str;
description = "Where to store search index and other data.";
default = "${cfg.homeDir}/data";
};
logLevel = mkOption {
type = with types; enum [ "error" "warn" "info" "debug" ];
description = "Only log messages with the given severity or above.";
default = "info";
};
web = mkOption {
default = { };
type = types.submodule {
freeformType = settingsFormat.type;
options = {
port = mkOption {
type = types.port;
description = "Port for searchix to listen on";
default = 51313;
};
listenAddress = mkOption {
type = types.str;
description = "Listen on a specific IP address.";
default = "localhost";
};
baseURL =
let
inherit (config.services.searchix.settings) web;
in
mkOption {
type = types.str;
description = "The base URL that searchix will be served on.";
default = "http://${web.listenAddress}:${toString web.port}";
};
environment = mkOption {
type = types.str;
description = "Environment name for logging";
default = "production";
};
sentryDSN = mkOption {
type = types.str;
description = "Optionally enable sentry to track errors.";
default = "";
};
contentSecurityPolicy = mkOption {
type = types.submodule {
freeformType = settingsFormat.type;
};
description = "Control resources a browser should be allowed to load.";
default = defaults.Web.ContentSecurityPolicy;
};
headers = mkOption {
type = with types; attrsOf str;
description = "HTTP Headers to send with every request. Case-insensitive.";
default = defaults.Web.Headers;
};
};
};
};
importer = mkOption {
default = { };
type = types.submodule {
freeformType = settingsFormat.type;
options = {
timeout = mkOption {
type = types.str;
default = "30m";
description = ''
Maximum time to wait for all import jobs.
May need to be increased based on the number of sources.
'';
};
updateAt = mkOption {
type = types.strMatching "[[:digit:]]{2}:[[:digit:]]{2}:[[:digit:]]{2}";
default = defaults.Importer.UpdateAt;
example = "02:00:00";
description = "Time of day to fetch and import new options.";
};
sources = mkOption {
type = with types;
attrsOf (submodule (import ./source-options.nix {
inherit cfg settingsFormat;
}));
default = defaults.Importer.Sources;
description = "Declarative specification of options sources for searchix.";
};
};
};
};
};
};
description = ''
Configuration for searchix.
See https://git.alanpearce.eu/searchix/tree/defaults.toml
'';
};
};
config = mkIf cfg.enable {
systemd.services.searchix = {
description = "Searchix Nix option search";
wantedBy = [ "multi-user.target" ];
path = with pkgs; [ nix ];
serviceConfig = defaultServiceConfig // {
ExecStart = "${package}/bin/searchix-web --config ${(settingsFormat.generate "searchix-config.toml" cfg.settings)}";
} // lib.optionalAttrs (cfg.settings.web.port < 1024) {
AmbientCapabilities = [ "CAP_NET_BIND_SERVICE" ];
CapabilityBoundingSet = [ "CAP_NET_BIND_SERVICE" ];
};
};
users.users = optionalAttrs (cfg.user == "searchix") {
searchix = {
inherit (cfg) group;
home = cfg.homeDir;
isSystemUser = true;
};
};
users.groups = optionalAttrs (cfg.group == "searchix") {
searchix = { };
};
};
}
|