nixos/searx: remove settings.yml merging script
Starting with 0.18.0, searx can merge the settings.yml automatically with the default values, so the script is obsolete.
This commit is contained in:
parent
1013de19f1
commit
f741cccd45
@ -1,4 +1,4 @@
|
|||||||
{ config, lib, pkgs, ... }:
|
{ options, config, lib, pkgs, ... }:
|
||||||
|
|
||||||
with lib;
|
with lib;
|
||||||
|
|
||||||
@ -6,42 +6,14 @@ let
|
|||||||
runDir = "/run/searx";
|
runDir = "/run/searx";
|
||||||
cfg = config.services.searx;
|
cfg = config.services.searx;
|
||||||
|
|
||||||
hasEngines =
|
generateConfig = ''
|
||||||
builtins.hasAttr "engines" cfg.settings &&
|
|
||||||
cfg.settings.engines != { };
|
|
||||||
|
|
||||||
# Script to merge NixOS settings with
|
|
||||||
# the default settings.yml bundled in searx.
|
|
||||||
mergeConfig = ''
|
|
||||||
cd ${runDir}
|
cd ${runDir}
|
||||||
# find the default settings.yml
|
|
||||||
default=$(find '${cfg.package}/' -name settings.yml)
|
|
||||||
|
|
||||||
# write NixOS settings as JSON
|
# write NixOS settings as JSON
|
||||||
cat <<'EOF' > settings.json
|
cat <<'EOF' > settings.yml
|
||||||
${builtins.toJSON cfg.settings}
|
${builtins.toJSON cfg.settings}
|
||||||
EOF
|
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
|
# substitute environment variables
|
||||||
env -0 | while IFS='=' read -r -d ''' n v; do
|
env -0 | while IFS='=' read -r -d ''' n v; do
|
||||||
sed "s#@$n@#$v#g" -i settings.yml
|
sed "s#@$n@#$v#g" -i settings.yml
|
||||||
@ -51,6 +23,12 @@ let
|
|||||||
chmod 400 settings.yml
|
chmod 400 settings.yml
|
||||||
'';
|
'';
|
||||||
|
|
||||||
|
settingType = with types; (oneOf
|
||||||
|
[ bool int float str
|
||||||
|
(listOf settingType)
|
||||||
|
(attrsOf settingType)
|
||||||
|
]) // { description = "JSON value"; };
|
||||||
|
|
||||||
in
|
in
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -86,15 +64,16 @@ in
|
|||||||
};
|
};
|
||||||
|
|
||||||
settings = mkOption {
|
settings = mkOption {
|
||||||
type = types.attrs;
|
type = types.attrsOf settingType;
|
||||||
default = { };
|
default = { };
|
||||||
example = literalExample ''
|
example = literalExample ''
|
||||||
{ server.port = 8080;
|
{ server.port = 8080;
|
||||||
server.bind_address = "0.0.0.0";
|
server.bind_address = "0.0.0.0";
|
||||||
server.secret_key = "@SEARX_SECRET_KEY@";
|
server.secret_key = "@SEARX_SECRET_KEY@";
|
||||||
|
|
||||||
engines.wolframalpha =
|
engines = lib.singleton
|
||||||
{ shortcut = "wa";
|
{ name = "wolframalpha";
|
||||||
|
shortcut = "wa";
|
||||||
api_key = "@WOLFRAM_API_KEY@";
|
api_key = "@WOLFRAM_API_KEY@";
|
||||||
engine = "wolframalpha_api";
|
engine = "wolframalpha_api";
|
||||||
};
|
};
|
||||||
@ -155,9 +134,9 @@ in
|
|||||||
};
|
};
|
||||||
|
|
||||||
uwsgiConfig = mkOption {
|
uwsgiConfig = mkOption {
|
||||||
type = types.attrs;
|
type = options.services.uwsgi.instance.type;
|
||||||
default = { http = ":8080"; };
|
default = { http = ":8080"; };
|
||||||
example = lib.literalExample ''
|
example = literalExample ''
|
||||||
{
|
{
|
||||||
disable-logging = true;
|
disable-logging = true;
|
||||||
http = ":8080"; # serve via HTTP...
|
http = ":8080"; # serve via HTTP...
|
||||||
@ -199,7 +178,7 @@ in
|
|||||||
RuntimeDirectoryMode = "750";
|
RuntimeDirectoryMode = "750";
|
||||||
} // optionalAttrs (cfg.environmentFile != null)
|
} // optionalAttrs (cfg.environmentFile != null)
|
||||||
{ EnvironmentFile = builtins.toPath cfg.environmentFile; };
|
{ EnvironmentFile = builtins.toPath cfg.environmentFile; };
|
||||||
script = mergeConfig;
|
script = generateConfig;
|
||||||
};
|
};
|
||||||
|
|
||||||
systemd.services.searx = mkIf (!cfg.runInUwsgi) {
|
systemd.services.searx = mkIf (!cfg.runInUwsgi) {
|
||||||
@ -221,6 +200,11 @@ in
|
|||||||
after = [ "searx-init.service" ];
|
after = [ "searx-init.service" ];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
services.searx.settings = {
|
||||||
|
# merge NixOS settings with defaults settings.yml
|
||||||
|
use_default_settings = mkDefault true;
|
||||||
|
};
|
||||||
|
|
||||||
services.uwsgi = mkIf (cfg.runInUwsgi) {
|
services.uwsgi = mkIf (cfg.runInUwsgi) {
|
||||||
enable = true;
|
enable = true;
|
||||||
plugins = [ "python3" ];
|
plugins = [ "python3" ];
|
||||||
@ -241,6 +225,6 @@ in
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
meta.maintainers = with lib.maintainers; [ rnhmjoj ];
|
meta.maintainers = with maintainers; [ rnhmjoj ];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -22,13 +22,15 @@ import ./make-test-python.nix ({ pkgs, ...} :
|
|||||||
bind_address = "0.0.0.0";
|
bind_address = "0.0.0.0";
|
||||||
secret_key = "@SEARX_SECRET_KEY@";
|
secret_key = "@SEARX_SECRET_KEY@";
|
||||||
};
|
};
|
||||||
settings.engines = {
|
settings.engines = [
|
||||||
wolframalpha =
|
{ name = "wolframalpha";
|
||||||
{ api_key = "@WOLFRAM_API_KEY@";
|
api_key = "@WOLFRAM_API_KEY@";
|
||||||
engine = "wolframalpha_api";
|
engine = "wolframalpha_api";
|
||||||
};
|
}
|
||||||
startpage.shortcut = "start";
|
{ name = "startpage";
|
||||||
};
|
shortcut = "start";
|
||||||
|
}
|
||||||
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
@ -109,4 +111,3 @@ import ./make-test-python.nix ({ pkgs, ...} :
|
|||||||
)
|
)
|
||||||
'';
|
'';
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user