juspay / services-flake

NixOS-like services for Nix flakes
https://community.flake.parts/services-flake
MIT License
299 stars 28 forks source link

searxng: init #241

Closed drupol closed 3 weeks ago

drupol commented 4 weeks ago

This PR:

Test with:

{
  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
    flake-parts.url = "github:hercules-ci/flake-parts";
    systems.url = "github:nix-systems/default";
    process-compose-flake.url = "github:Platonic-Systems/process-compose-flake";
    services-flake.url = "github:juspay/services-flake";
  };
  outputs =
    inputs:
    inputs.flake-parts.lib.mkFlake { inherit inputs; } {
      systems = import inputs.systems;
      imports = [ inputs.process-compose-flake.flakeModule ];
      perSystem =
        { pkgs, lib, ... }:
        {
          # `process-compose.foo` will add a flake package output called "foo".
          # Therefore, this will add a default package that you can build using
          # `nix build` and run using `nix run`.
          process-compose."default" =
            pc:
            let
              inherit (pc.config.services.searxng.searxng) host port;
            in
            {
              imports = [ inputs.services-flake.processComposeModules.default ];

              services.searxng."searxng" = {
                enable = true;
                settings = {
                  use_default_settings = true;
                  server.secret_key = "secret";
                  server.limiter = false;
                };
              };

              # Open the browser after the Open WebUI service has started
              settings.processes.open-browser = {
                command =
                  let
                    opener = if pkgs.stdenv.isDarwin then "open" else lib.getExe' pkgs.xdg-utils "xdg-open";
                    url = "http://${host}:${toString port}";
                  in
                  "${opener} ${url}";
                depends_on.searxng.condition = "process_healthy";
              };
            };
        };
    };
}
shivaraj-bh commented 4 weeks ago

I just tried it out with the following settings:

{
  services.searxng."searxng1" = {
    enable = true;
    settings = {
      use_default_settings = true;
      server.secret_key = "secret";
      search.formats = [ "html" "json" ];
    };
  };
}

And tried out the json format output with curl:

❯ curl -G 'http://localhost:1234/search' \
  --data-urlencode 'q=OpenAI' \
  --data-urlencode 'format=json' | jq '.results | .[:1]'
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 34975  100 34975    0     0  11099      0  0:00:03  0:00:03 --:--:-- 11099
[
  {
    "url": "https://openai.com/",
    "title": "OpenAI",
    "content": "OpenAI announces GPT-4o, a new version of its powerful language model, and ChatGPT, a free service that lets you chat with it. Learn more about their research, products, and mission to create safe and beneficial artificial general intelligence.",
    "thumbnail": "",
    "engine": "google",
    "parsed_url": [
      "https",
      "openai.com",
      "/",
      "",
      "",
      ""
    ],
    "template": "default.html",
    "engines": [
      "duckduckgo",
      "google",
      "brave"
    ],
    "positions": [
      1,
      1,
      1,
      2
    ],
    "publishedDate": "2024-05-13T00:00:00",
    "score": 14.0,
    "category": "general"
  }
]

pretty cool! will be really helpful to provide search engine access to agents.

drupol commented 4 weeks ago

pretty cool! will be really helpful to provide search engine access to agents.

Already using it in conjunction with open-webui on my server, that's the reason why I did this PR.

shivaraj-bh commented 3 weeks ago

Can merge after @shivaraj-bh review (and addressing of comments) with CI fully passing (currently fails on mac).

For the time-being, we can disable tests for this package on Darwin (like we do for grafana), with a comment linking to upstream issue: https://github.com/NixOS/nixpkgs/issues/321329.

drupol commented 3 weeks ago

I think i'm done.

drupol commented 3 weeks ago

Top! thanks.