From f3098faecd73edec233861bc4bc73caabbc7b5ff Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Thu, 20 Jun 2024 22:08:45 +0200 Subject: [PATCH] feat(searxng): init (#241) --- doc/searxng.md | 21 +++++++++++ example/llm/flake.nix | 2 +- nix/default.nix | 1 + nix/searxng.nix | 83 +++++++++++++++++++++++++++++++++++++++++++ nix/searxng_test.nix | 22 ++++++++++++ test/flake.nix | 2 ++ 6 files changed, 130 insertions(+), 1 deletion(-) create mode 100644 doc/searxng.md create mode 100644 nix/searxng.nix create mode 100644 nix/searxng_test.nix diff --git a/doc/searxng.md b/doc/searxng.md new file mode 100644 index 0000000..53f7c46 --- /dev/null +++ b/doc/searxng.md @@ -0,0 +1,21 @@ +# Searxng + +[Searxng](https://github.com/searxng/searxng) is a free internet metasearch engine which aggregates results from various search services and databases. Users are neither tracked nor profiled. + +## Getting Started + +```nix +# In `perSystem.process-compose.` +{ + services.searxng."instance-name" = { + enable = true; + port = 1234; + host = "127.0.0.1"; + secret_key = "my-secret-key"; + settings = { + doi_resolvers."dummy" = "http://example.org"; + default_doi_resolver = "dummy"; + }; + }; +} +``` diff --git a/example/llm/flake.nix b/example/llm/flake.nix index 0f3ab8b..4d7d204 100644 --- a/example/llm/flake.nix +++ b/example/llm/flake.nix @@ -31,7 +31,7 @@ dataDir = "${dataDirBase}/ollama1"; # Define the models to download when our app starts - # + # # You can also initialize this to empty list, and download the # models manually in the UI. # diff --git a/nix/default.nix b/nix/default.nix index a853a9a..1adbd7c 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -21,5 +21,6 @@ in ./cassandra.nix ./tempo.nix ./weaviate.nix + ./searxng.nix ]; } diff --git a/nix/searxng.nix b/nix/searxng.nix new file mode 100644 index 0000000..fb52006 --- /dev/null +++ b/nix/searxng.nix @@ -0,0 +1,83 @@ +{ pkgs, lib, name, config, ... }: +let + inherit (lib) types; + yamlFormat = pkgs.formats.yaml { }; +in +{ + options = { + enable = lib.mkEnableOption name; + package = lib.mkPackageOption pkgs "searxng" { }; + + host = lib.mkOption { + description = "Searxng bind address"; + default = "127.0.0.1"; + type = types.str; + }; + + port = lib.mkOption { + description = "Searxng port to listen on"; + default = 8080; + type = types.port; + }; + + use_default_settings = lib.mkOption { + description = "Use default Searxng settings"; + default = true; + type = types.bool; + }; + + secret_key = lib.mkOption { + description = "Searxng secret key"; + default = "secret"; + example = "secret-key"; + type = types.str; + }; + + settings = lib.mkOption { + type = yamlFormat.type; + default = { }; + example = lib.literalExpression '' + { + doi_resolvers."dummy" = "http://example.org"; + default_doi_resolver = "dummy"; + } + ''; + description = '' + Searxng settings + ''; + }; + + outputs.settings = lib.mkOption { + type = types.deferredModule; + internal = true; + readOnly = true; + default = { + processes = { + "${name}" = { + environment = { + SEARXNG_SETTINGS_PATH = "${yamlFormat.generate "settings.yaml" ( + lib.recursiveUpdate config.settings { + server.bind_address = config.host; + server.port = config.port; + server.secret_key = config.secret_key; + use_default_settings = config.use_default_settings; + } + )}"; + }; + command = lib.getExe config.package; + namespace = name; + availability.restart = "on_failure"; + readiness_probe = { + exec.command = "${lib.getExe pkgs.curl} -f -k http://${config.host}:${toString config.port}"; + initial_delay_seconds = 5; + period_seconds = 10; + timeout_seconds = 2; + success_threshold = 1; + failure_threshold = 5; + }; + }; + }; + }; + }; + }; +} diff --git a/nix/searxng_test.nix b/nix/searxng_test.nix new file mode 100644 index 0000000..36f2a82 --- /dev/null +++ b/nix/searxng_test.nix @@ -0,0 +1,22 @@ +{ pkgs, ... }: +{ + services.searxng."searxng1" = { + enable = true; + use_default_settings = false; + settings = { + doi_resolvers."dummy" = "http://example.org"; + default_doi_resolver = "dummy"; + }; + }; + + settings.processes.test = { + command = pkgs.writeShellApplication { + runtimeInputs = [ pkgs.curl ]; + text = '' + curl http://127.0.0.1:8080 + ''; + name = "searxng-test"; + }; + depends_on."searxng1".condition = "process_healthy"; + }; +} diff --git a/test/flake.nix b/test/flake.nix index 4995218..1b8386f 100644 --- a/test/flake.nix +++ b/test/flake.nix @@ -52,6 +52,8 @@ ] ++ lib.optionals pkgs.stdenv.isLinux [ # Broken on Darwin: https://github.com/NixOS/nixpkgs/issues/316954 "${inputs.services-flake}/nix/grafana_test.nix" + # Broken on Darwin: https://github.com/NixOS/nixpkgs/issues/321329 + "${inputs.services-flake}/nix/searxng_test.nix" ])); }; };