1{
2 config,
3 lib,
4 pkgs,
5 ...
6}:
7
8let
9 cfg = config.services.whoogle-search;
10in
11{
12 options = {
13 services.whoogle-search = {
14 enable = lib.mkEnableOption "Whoogle, a metasearch engine";
15
16 port = lib.mkOption {
17 type = lib.types.port;
18 default = 5000;
19 description = "Port to listen on.";
20 };
21
22 listenAddress = lib.mkOption {
23 type = lib.types.str;
24 default = "127.0.0.1";
25 description = "Address to listen on for the web interface.";
26 };
27
28 extraEnv = lib.mkOption {
29 type = with lib.types; attrsOf str;
30 default = { };
31 description = ''
32 Extra environment variables to pass to Whoogle, see
33 https://github.com/benbusby/whoogle-search?tab=readme-ov-file#environment-variables
34 '';
35 };
36 };
37 };
38
39 config = lib.mkIf cfg.enable {
40
41 systemd.services.whoogle-search = {
42 description = "Whoogle Search";
43 wantedBy = [ "multi-user.target" ];
44 path = [ pkgs.whoogle-search ];
45
46 environment = {
47 CONFIG_VOLUME = "/var/lib/whoogle-search";
48 } // cfg.extraEnv;
49
50 serviceConfig = {
51 Type = "simple";
52 ExecStart =
53 "${lib.getExe pkgs.whoogle-search}"
54 + " --host '${cfg.listenAddress}'"
55 + " --port '${builtins.toString cfg.port}'";
56 ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
57 StateDirectory = "whoogle-search";
58 StateDirectoryMode = "0750";
59 DynamicUser = true;
60 PrivateTmp = true;
61 ProtectSystem = true;
62 ProtectHome = true;
63 Restart = "on-failure";
64 RestartSec = "5s";
65 };
66 };
67 };
68
69 meta.maintainers = with lib.maintainers; [ malte-v ];
70}