2021-01-12 21:53:25 +00:00
|
|
|
{ options, config, lib, pkgs, ... }:
|
2014-03-07 19:09:59 +00:00
|
|
|
|
2014-04-14 15:26:48 +01:00
|
|
|
with lib;
|
2014-03-07 19:09:59 +00:00
|
|
|
|
|
|
|
let
|
2020-11-06 09:12:20 +00:00
|
|
|
runDir = "/run/searx";
|
2014-03-07 19:09:59 +00:00
|
|
|
cfg = config.services.searx;
|
|
|
|
|
2021-01-12 21:53:25 +00:00
|
|
|
generateConfig = ''
|
2020-11-06 09:12:20 +00:00
|
|
|
cd ${runDir}
|
2020-10-27 12:55:12 +00:00
|
|
|
|
|
|
|
# write NixOS settings as JSON
|
2021-01-12 21:53:25 +00:00
|
|
|
cat <<'EOF' > settings.yml
|
2020-10-27 12:55:12 +00:00
|
|
|
${builtins.toJSON cfg.settings}
|
|
|
|
EOF
|
|
|
|
|
|
|
|
# substitute environment variables
|
|
|
|
env -0 | while IFS='=' read -r -d ''' n v; do
|
|
|
|
sed "s#@$n@#$v#g" -i settings.yml
|
|
|
|
done
|
2020-11-06 09:12:20 +00:00
|
|
|
|
|
|
|
# set strict permissions
|
|
|
|
chmod 400 settings.yml
|
2020-10-27 12:55:12 +00:00
|
|
|
'';
|
2014-03-07 19:09:59 +00:00
|
|
|
|
2021-01-12 21:53:25 +00:00
|
|
|
settingType = with types; (oneOf
|
|
|
|
[ bool int float str
|
|
|
|
(listOf settingType)
|
|
|
|
(attrsOf settingType)
|
|
|
|
]) // { description = "JSON value"; };
|
|
|
|
|
2014-03-07 19:09:59 +00:00
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
2020-10-27 12:55:12 +00:00
|
|
|
imports = [
|
|
|
|
(mkRenamedOptionModule
|
|
|
|
[ "services" "searx" "configFile" ]
|
|
|
|
[ "services" "searx" "settingsFile" ])
|
|
|
|
];
|
|
|
|
|
2014-03-07 19:09:59 +00:00
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
services.searx = {
|
|
|
|
|
2020-10-27 12:55:12 +00:00
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
relatedPackages = [ "searx" ];
|
|
|
|
description = "Whether to enable Searx, the meta search engine.";
|
|
|
|
};
|
2014-03-07 19:09:59 +00:00
|
|
|
|
2020-10-27 12:55:12 +00:00
|
|
|
environmentFile = mkOption {
|
2017-04-04 16:14:32 +01:00
|
|
|
type = types.nullOr types.path;
|
|
|
|
default = null;
|
2020-10-27 12:55:12 +00:00
|
|
|
description = ''
|
|
|
|
Environment file (see <literal>systemd.exec(5)</literal>
|
|
|
|
"EnvironmentFile=" section for the syntax) to define variables for
|
|
|
|
Searx. This option can be used to safely include secret keys into the
|
|
|
|
Searx configuration.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
settings = mkOption {
|
2021-01-12 21:53:25 +00:00
|
|
|
type = types.attrsOf settingType;
|
2020-10-27 12:55:12 +00:00
|
|
|
default = { };
|
|
|
|
example = literalExample ''
|
|
|
|
{ server.port = 8080;
|
|
|
|
server.bind_address = "0.0.0.0";
|
|
|
|
server.secret_key = "@SEARX_SECRET_KEY@";
|
|
|
|
|
2021-01-12 21:53:25 +00:00
|
|
|
engines = lib.singleton
|
|
|
|
{ name = "wolframalpha";
|
|
|
|
shortcut = "wa";
|
2020-10-27 12:55:12 +00:00
|
|
|
api_key = "@WOLFRAM_API_KEY@";
|
|
|
|
engine = "wolframalpha_api";
|
|
|
|
};
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
description = ''
|
|
|
|
Searx settings. These will be merged with (taking precedence over)
|
|
|
|
the default configuration. It's also possible to refer to
|
|
|
|
environment variables
|
|
|
|
(defined in <xref linkend="opt-services.searx.environmentFile"/>)
|
|
|
|
using the syntax <literal>@VARIABLE_NAME@</literal>.
|
|
|
|
<note>
|
|
|
|
<para>
|
|
|
|
For available settings, see the Searx
|
|
|
|
<link xlink:href="https://searx.github.io/searx/admin/settings.html">docs</link>.
|
|
|
|
</para>
|
|
|
|
</note>
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
settingsFile = mkOption {
|
|
|
|
type = types.path;
|
2020-11-06 09:12:20 +00:00
|
|
|
default = "${runDir}/settings.yml";
|
2020-10-27 12:55:12 +00:00
|
|
|
description = ''
|
|
|
|
The path of the Searx server settings.yml file. If no file is
|
|
|
|
specified, a default file is used (default config file has debug mode
|
|
|
|
enabled). Note: setting this options overrides
|
|
|
|
<xref linkend="opt-services.searx.settings"/>.
|
|
|
|
<warning>
|
|
|
|
<para>
|
|
|
|
This file, along with any secret key it contains, will be copied
|
|
|
|
into the world-readable Nix store.
|
|
|
|
</para>
|
|
|
|
</warning>
|
|
|
|
'';
|
2014-03-07 19:09:59 +00:00
|
|
|
};
|
|
|
|
|
2017-02-10 21:44:10 +00:00
|
|
|
package = mkOption {
|
2017-03-07 13:01:30 +00:00
|
|
|
type = types.package;
|
2017-08-01 00:11:36 +01:00
|
|
|
default = pkgs.searx;
|
|
|
|
defaultText = "pkgs.searx";
|
2017-02-10 21:44:10 +00:00
|
|
|
description = "searx package to use.";
|
|
|
|
};
|
|
|
|
|
2020-11-06 09:12:20 +00:00
|
|
|
runInUwsgi = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Whether to run searx in uWSGI as a "vassal", instead of using its
|
|
|
|
built-in HTTP server. This is the recommended mode for public or
|
|
|
|
large instances, but is unecessary for LAN or local-only use.
|
|
|
|
<warning>
|
|
|
|
<para>
|
|
|
|
The built-in HTTP server logs all queries by default.
|
|
|
|
</para>
|
|
|
|
</warning>
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
uwsgiConfig = mkOption {
|
2021-01-12 21:53:25 +00:00
|
|
|
type = options.services.uwsgi.instance.type;
|
2020-11-06 09:12:20 +00:00
|
|
|
default = { http = ":8080"; };
|
2021-01-12 21:53:25 +00:00
|
|
|
example = literalExample ''
|
2020-11-06 09:12:20 +00:00
|
|
|
{
|
|
|
|
disable-logging = true;
|
|
|
|
http = ":8080"; # serve via HTTP...
|
|
|
|
socket = "/run/searx/searx.sock"; # ...or UNIX socket
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
description = ''
|
|
|
|
Additional configuration of the uWSGI vassal running searx. It
|
|
|
|
should notably specify on which interfaces and ports the vassal
|
|
|
|
should listen.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2014-03-07 19:09:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
2020-11-06 09:12:20 +00:00
|
|
|
config = mkIf cfg.enable {
|
|
|
|
environment.systemPackages = [ cfg.package ];
|
|
|
|
|
|
|
|
users.users.searx =
|
|
|
|
{ description = "Searx daemon user";
|
|
|
|
group = "searx";
|
|
|
|
isSystemUser = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
users.groups.searx = { };
|
|
|
|
|
|
|
|
systemd.services.searx-init = {
|
|
|
|
description = "Initialise Searx settings";
|
2020-10-27 12:55:12 +00:00
|
|
|
serviceConfig = {
|
2020-11-06 09:12:20 +00:00
|
|
|
Type = "oneshot";
|
|
|
|
RemainAfterExit = true;
|
2020-10-27 12:55:12 +00:00
|
|
|
User = "searx";
|
2020-11-06 09:12:20 +00:00
|
|
|
RuntimeDirectory = "searx";
|
|
|
|
RuntimeDirectoryMode = "750";
|
|
|
|
} // optionalAttrs (cfg.environmentFile != null)
|
|
|
|
{ EnvironmentFile = builtins.toPath cfg.environmentFile; };
|
2021-01-12 21:53:25 +00:00
|
|
|
script = generateConfig;
|
2020-11-06 09:12:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
systemd.services.searx = mkIf (!cfg.runInUwsgi) {
|
|
|
|
description = "Searx server, the meta search engine.";
|
|
|
|
wantedBy = [ "network.target" "multi-user.target" ];
|
|
|
|
requires = [ "searx-init.service" ];
|
|
|
|
after = [ "searx-init.service" ];
|
|
|
|
serviceConfig = {
|
|
|
|
User = "searx";
|
|
|
|
Group = "searx";
|
2020-10-27 12:55:12 +00:00
|
|
|
ExecStart = "${cfg.package}/bin/searx-run";
|
|
|
|
} // optionalAttrs (cfg.environmentFile != null)
|
|
|
|
{ EnvironmentFile = builtins.toPath cfg.environmentFile; };
|
|
|
|
environment.SEARX_SETTINGS_PATH = cfg.settingsFile;
|
|
|
|
};
|
2014-03-07 19:09:59 +00:00
|
|
|
|
2020-11-06 09:12:20 +00:00
|
|
|
systemd.services.uwsgi = mkIf (cfg.runInUwsgi)
|
|
|
|
{ requires = [ "searx-init.service" ];
|
|
|
|
after = [ "searx-init.service" ];
|
|
|
|
};
|
|
|
|
|
2021-01-12 21:53:25 +00:00
|
|
|
services.searx.settings = {
|
|
|
|
# merge NixOS settings with defaults settings.yml
|
|
|
|
use_default_settings = mkDefault true;
|
|
|
|
};
|
|
|
|
|
2020-11-06 09:12:20 +00:00
|
|
|
services.uwsgi = mkIf (cfg.runInUwsgi) {
|
|
|
|
enable = true;
|
|
|
|
plugins = [ "python3" ];
|
|
|
|
|
|
|
|
instance.type = "emperor";
|
|
|
|
instance.vassals.searx = {
|
|
|
|
type = "normal";
|
|
|
|
strict = true;
|
|
|
|
immediate-uid = "searx";
|
|
|
|
immediate-gid = "searx";
|
|
|
|
lazy-apps = true;
|
|
|
|
enable-threads = true;
|
|
|
|
module = "searx.webapp";
|
|
|
|
env = [ "SEARX_SETTINGS_PATH=${cfg.settingsFile}" ];
|
|
|
|
pythonPackages = self: [ cfg.package ];
|
|
|
|
} // cfg.uwsgiConfig;
|
|
|
|
};
|
2014-03-07 19:09:59 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2021-01-12 21:53:25 +00:00
|
|
|
meta.maintainers = with maintainers; [ rnhmjoj ];
|
2019-12-04 16:07:45 +00:00
|
|
|
|
2014-03-07 19:09:59 +00:00
|
|
|
}
|