1import ./make-test-python.nix ({ pkgs, ...} :
2
3{
4 name = "searx";
5 meta = with pkgs.lib.maintainers; {
6 maintainers = [ rnhmjoj ];
7 };
8
9 # basic setup: searx running the built-in webserver
10 nodes.base = { ... }: {
11 imports = [ ../modules/profiles/minimal.nix ];
12
13 services.searx = {
14 enable = true;
15 environmentFile = pkgs.writeText "secrets" ''
16 WOLFRAM_API_KEY = sometoken
17 SEARX_SECRET_KEY = somesecret
18 '';
19
20 settings.server =
21 { port = "8080";
22 bind_address = "0.0.0.0";
23 secret_key = "@SEARX_SECRET_KEY@";
24 };
25 settings.engines = [
26 { name = "wolframalpha";
27 api_key = "@WOLFRAM_API_KEY@";
28 engine = "wolframalpha_api";
29 }
30 { name = "startpage";
31 shortcut = "start";
32 }
33 ];
34 };
35
36 };
37
38 # fancy setup: run in uWSGI and use nginx as proxy
39 nodes.fancy = { ... }: {
40 imports = [ ../modules/profiles/minimal.nix ];
41
42 services.searx = {
43 enable = true;
44 # searx refuses to run if unchanged
45 settings.server.secret_key = "somesecret";
46
47 runInUwsgi = true;
48 uwsgiConfig = {
49 # serve using the uwsgi protocol
50 socket = "/run/searx/uwsgi.sock";
51 chmod-socket = "660";
52
53 # use /searx as url "mountpoint"
54 mount = "/searx=searx.webapp:application";
55 module = "";
56 manage-script-name = true;
57 };
58 };
59
60 # use nginx as reverse proxy
61 services.nginx.enable = true;
62 services.nginx.virtualHosts.localhost = {
63 locations."/searx".extraConfig =
64 ''
65 include ${pkgs.nginx}/conf/uwsgi_params;
66 uwsgi_pass unix:/run/searx/uwsgi.sock;
67 '';
68 locations."/searx/static/".alias = "${pkgs.searx}/share/static/";
69 };
70
71 # allow nginx access to the searx socket
72 users.users.nginx.extraGroups = [ "searx" ];
73
74 };
75
76 testScript =
77 ''
78 base.start()
79
80 with subtest("Settings have been merged"):
81 base.wait_for_unit("searx-init")
82 base.wait_for_file("/run/searx/settings.yml")
83 output = base.succeed(
84 "${pkgs.yq-go}/bin/yq eval"
85 " '.engines[] | select(.name==\"startpage\") | .shortcut'"
86 " /run/searx/settings.yml"
87 ).strip()
88 assert output == "start", "Settings not merged"
89
90 with subtest("Environment variables have been substituted"):
91 base.succeed("grep -q somesecret /run/searx/settings.yml")
92 base.succeed("grep -q sometoken /run/searx/settings.yml")
93 base.copy_from_vm("/run/searx/settings.yml")
94
95 with subtest("Basic setup is working"):
96 base.wait_for_open_port(8080)
97 base.wait_for_unit("searx")
98 base.succeed(
99 "${pkgs.curl}/bin/curl --fail http://localhost:8080"
100 )
101 base.shutdown()
102
103 with subtest("Nginx+uWSGI setup is working"):
104 fancy.start()
105 fancy.wait_for_open_port(80)
106 fancy.wait_for_unit("uwsgi")
107 fancy.succeed(
108 "${pkgs.curl}/bin/curl --fail http://localhost/searx >&2"
109 )
110 fancy.succeed(
111 "${pkgs.curl}/bin/curl --fail http://localhost/searx/static/themes/oscar/js/bootstrap.min.js >&2"
112 )
113 '';
114})