1 { options, config, lib, pkgs, ... }:
8 cfg = config.services.searx;
10 settingsFile = pkgs.writeText "settings.yml"
11 (builtins.toJSON cfg.settings);
16 # write NixOS settings as JSON
19 cp --no-preserve=mode ${settingsFile} settings.yml
22 # substitute environment variables
23 env -0 | while IFS='=' read -r -d ''' n v; do
24 sed "s#@$n@#$v#g" -i settings.yml
28 settingType = with types; (oneOf
32 ]) // { description = "JSON value"; };
39 (mkRenamedOptionModule
40 [ "services" "searx" "configFile" ]
41 [ "services" "searx" "settingsFile" ])
53 relatedPackages = [ "searx" ];
54 description = lib.mdDoc "Whether to enable Searx, the meta search engine.";
57 environmentFile = mkOption {
58 type = types.nullOr types.path;
60 description = lib.mdDoc ''
61 Environment file (see `systemd.exec(5)`
62 "EnvironmentFile=" section for the syntax) to define variables for
63 Searx. This option can be used to safely include secret keys into the
69 type = types.attrsOf settingType;
71 example = literalExpression ''
73 server.bind_address = "0.0.0.0";
74 server.secret_key = "@SEARX_SECRET_KEY@";
76 engines = lib.singleton
77 { name = "wolframalpha";
79 api_key = "@WOLFRAM_API_KEY@";
80 engine = "wolframalpha_api";
84 description = lib.mdDoc ''
85 Searx settings. These will be merged with (taking precedence over)
86 the default configuration. It's also possible to refer to
88 (defined in [](#opt-services.searx.environmentFile))
89 using the syntax `@VARIABLE_NAME@`.
92 For available settings, see the Searx
93 [docs](https://searx.github.io/searx/admin/settings.html).
98 settingsFile = mkOption {
100 default = "${runDir}/settings.yml";
101 description = lib.mdDoc ''
102 The path of the Searx server settings.yml file. If no file is
103 specified, a default file is used (default config file has debug mode
104 enabled). Note: setting this options overrides
105 [](#opt-services.searx.settings).
108 This file, along with any secret key it contains, will be copied
109 into the world-readable Nix store.
115 type = types.package;
116 default = pkgs.searx;
117 defaultText = literalExpression "pkgs.searx";
118 description = lib.mdDoc "searx package to use.";
121 runInUwsgi = mkOption {
124 description = lib.mdDoc ''
125 Whether to run searx in uWSGI as a "vassal", instead of using its
126 built-in HTTP server. This is the recommended mode for public or
127 large instances, but is unecessary for LAN or local-only use.
130 The built-in HTTP server logs all queries by default.
135 uwsgiConfig = mkOption {
136 type = options.services.uwsgi.instance.type;
137 default = { http = ":8080"; };
138 example = literalExpression ''
140 disable-logging = true;
141 http = ":8080"; # serve via HTTP...
142 socket = "/run/searx/searx.sock"; # ...or UNIX socket
143 chmod-socket = "660"; # allow the searx group to read/write to the socket
146 description = lib.mdDoc ''
147 Additional configuration of the uWSGI vassal running searx. It
148 should notably specify on which interfaces and ports the vassal
158 ###### implementation
160 config = mkIf cfg.enable {
161 environment.systemPackages = [ cfg.package ];
164 { description = "Searx daemon user";
169 users.groups.searx = { };
171 systemd.services.searx-init = {
172 description = "Initialise Searx settings";
175 RemainAfterExit = true;
177 RuntimeDirectory = "searx";
178 RuntimeDirectoryMode = "750";
179 } // optionalAttrs (cfg.environmentFile != null)
180 { EnvironmentFile = builtins.toPath cfg.environmentFile; };
181 script = generateConfig;
184 systemd.services.searx = mkIf (!cfg.runInUwsgi) {
185 description = "Searx server, the meta search engine.";
186 wantedBy = [ "network.target" "multi-user.target" ];
187 requires = [ "searx-init.service" ];
188 after = [ "searx-init.service" ];
192 ExecStart = "${cfg.package}/bin/searx-run";
193 } // optionalAttrs (cfg.environmentFile != null)
194 { EnvironmentFile = builtins.toPath cfg.environmentFile; };
196 SEARX_SETTINGS_PATH = cfg.settingsFile;
197 SEARXNG_SETTINGS_PATH = cfg.settingsFile;
201 systemd.services.uwsgi = mkIf (cfg.runInUwsgi)
202 { requires = [ "searx-init.service" ];
203 after = [ "searx-init.service" ];
206 services.searx.settings = {
207 # merge NixOS settings with defaults settings.yml
208 use_default_settings = mkDefault true;
211 services.uwsgi = mkIf (cfg.runInUwsgi) {
213 plugins = [ "python3" ];
215 instance.type = "emperor";
216 instance.vassals.searx = {
219 immediate-uid = "searx";
220 immediate-gid = "searx";
222 enable-threads = true;
223 module = "searx.webapp";
225 "SEARX_SETTINGS_PATH=${cfg.settingsFile}"
226 # searxng compatiblity https://github.com/searxng/searxng/issues/1519
227 "SEARXNG_SETTINGS_PATH=${cfg.settingsFile}"
230 pythonPackages = self: [ cfg.package ];
231 } // cfg.uwsgiConfig;
236 meta.maintainers = with maintainers; [ rnhmjoj ];