diff options
author | Michele Guerini Rocco <rnhmjoj@users.noreply.github.com> | 2021-01-14 10:15:37 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-14 10:15:37 +0100 |
commit | 721a4ecfa690e29af2b8b6bc3b244488d6b3dac5 (patch) | |
tree | 3a43e0ea46911c81539fd4725daa45e26ed8a20a /nixos/modules | |
parent | 3022d757812276206ecc143cf7c76c35719a3b3a (diff) | |
parent | f741cccd456be47c0b56f5468df851f1182f4a1b (diff) |
Merge pull request #109114 from illustris/searx
searx: 0.17.0 -> 0.18.0
Diffstat (limited to 'nixos/modules')
-rw-r--r-- | nixos/modules/services/networking/searx.nix | 60 |
1 files changed, 22 insertions, 38 deletions
diff --git a/nixos/modules/services/networking/searx.nix b/nixos/modules/services/networking/searx.nix index 85696beeba4a..a515e4a3dc3b 100644 --- a/nixos/modules/services/networking/searx.nix +++ b/nixos/modules/services/networking/searx.nix @@ -1,4 +1,4 @@ -{ config, lib, pkgs, ... }: +{ options, config, lib, pkgs, ... }: with lib; @@ -6,42 +6,14 @@ let runDir = "/run/searx"; cfg = config.services.searx; - hasEngines = - builtins.hasAttr "engines" cfg.settings && - cfg.settings.engines != { }; - - # Script to merge NixOS settings with - # the default settings.yml bundled in searx. - mergeConfig = '' + generateConfig = '' cd ${runDir} - # find the default settings.yml - default=$(find '${cfg.package}/' -name settings.yml) # write NixOS settings as JSON - cat <<'EOF' > settings.json + cat <<'EOF' > settings.yml ${builtins.toJSON cfg.settings} EOF - ${optionalString hasEngines '' - # extract and convert the default engines array to an object - ${pkgs.yq-go}/bin/yq r "$default" engines -j | \ - ${pkgs.jq}/bin/jq 'reduce .[] as $e ({}; .[$e.name] = $e)' \ - > engines.json - - # merge and update the NixOS engines with the newly created object - cp settings.json temp.json - ${pkgs.jq}/bin/jq -s '. as [$s, $e] | $s | .engines |= - ($e * . | to_entries | map (.value))' \ - temp.json engines.json > settings.json - - # clean up temporary files - rm {engines,temp}.json - ''} - - # merge the default and NixOS settings - ${pkgs.yq-go}/bin/yq m -P settings.json "$default" > settings.yml - rm settings.json - # substitute environment variables env -0 | while IFS='=' read -r -d ''' n v; do sed "s#@$n@#$v#g" -i settings.yml @@ -51,6 +23,12 @@ let chmod 400 settings.yml ''; + settingType = with types; (oneOf + [ bool int float str + (listOf settingType) + (attrsOf settingType) + ]) // { description = "JSON value"; }; + in { @@ -86,15 +64,16 @@ in }; settings = mkOption { - type = types.attrs; + type = types.attrsOf settingType; default = { }; example = literalExample '' { server.port = 8080; server.bind_address = "0.0.0.0"; server.secret_key = "@SEARX_SECRET_KEY@"; - engines.wolframalpha = - { shortcut = "wa"; + engines = lib.singleton + { name = "wolframalpha"; + shortcut = "wa"; api_key = "@WOLFRAM_API_KEY@"; engine = "wolframalpha_api"; }; @@ -155,9 +134,9 @@ in }; uwsgiConfig = mkOption { - type = types.attrs; + type = options.services.uwsgi.instance.type; default = { http = ":8080"; }; - example = lib.literalExample '' + example = literalExample '' { disable-logging = true; http = ":8080"; # serve via HTTP... @@ -199,7 +178,7 @@ in RuntimeDirectoryMode = "750"; } // optionalAttrs (cfg.environmentFile != null) { EnvironmentFile = builtins.toPath cfg.environmentFile; }; - script = mergeConfig; + script = generateConfig; }; systemd.services.searx = mkIf (!cfg.runInUwsgi) { @@ -221,6 +200,11 @@ in after = [ "searx-init.service" ]; }; + services.searx.settings = { + # merge NixOS settings with defaults settings.yml + use_default_settings = mkDefault true; + }; + services.uwsgi = mkIf (cfg.runInUwsgi) { enable = true; plugins = [ "python3" ]; @@ -241,6 +225,6 @@ in }; - meta.maintainers = with lib.maintainers; [ rnhmjoj ]; + meta.maintainers = with maintainers; [ rnhmjoj ]; } |