at master 2.7 kB view raw
1{ lib, pkgs, ... }: 2 3{ 4 name = "searx"; 5 meta = with lib.maintainers; { 6 maintainers = [ 7 SuperSandro2000 8 _999eagle 9 ]; 10 }; 11 12 # basic setup: searx running the built-in webserver 13 nodes.base = { 14 services.searx = { 15 enable = true; 16 environmentFile = pkgs.writeText "secrets" '' 17 SEARX_SECRET_KEY = somesecret 18 ''; 19 20 settings = { 21 engines = [ 22 { 23 name = "startpage"; 24 shortcut = "start"; 25 } 26 ]; 27 plugins = { }; 28 server = { 29 port = "8080"; 30 bind_address = "0.0.0.0"; 31 secret_key = "$SEARX_SECRET_KEY"; 32 }; 33 }; 34 }; 35 36 }; 37 38 # fancy setup: run in uWSGI and use nginx as proxy 39 nodes.fancy = 40 { config, lib, ... }: 41 { 42 services.searx = { 43 enable = true; 44 settings = { 45 plugins = { }; 46 server.secret_key = "somesecret"; 47 }; 48 49 configureNginx = true; 50 domain = "localhost"; 51 uwsgiConfig = { 52 # use /searx as url "mountpoint" 53 mount = "/searx=searx.webapp:application"; 54 module = ""; 55 manage-script-name = true; 56 }; 57 }; 58 59 services.nginx.virtualHosts.${config.services.searx.domain} = { 60 locations = { 61 "/static/" = lib.mkForce { }; 62 "/searx/static/".alias = "${config.services.searx.package}/share/static/"; 63 }; 64 }; 65 }; 66 67 testScript = '' 68 base.start() 69 70 with subtest("Settings have been merged"): 71 base.wait_for_unit("searx-init") 72 base.wait_for_file("/run/searx/settings.yml") 73 output = base.succeed( 74 "${pkgs.yq-go}/bin/yq eval" 75 " '.engines[] | select(.name==\"startpage\") | .shortcut'" 76 " /run/searx/settings.yml" 77 ).strip() 78 assert output == "start", "Settings not merged" 79 80 with subtest("Environment variables have been substituted"): 81 base.succeed("grep -q somesecret /run/searx/settings.yml") 82 base.copy_from_vm("/run/searx/settings.yml") 83 84 with subtest("Basic setup is working"): 85 base.wait_for_open_port(8080) 86 base.wait_for_unit("searx") 87 base.succeed( 88 "${pkgs.curl}/bin/curl --fail http://localhost:8080" 89 ) 90 base.shutdown() 91 92 with subtest("Nginx+uWSGI setup is working"): 93 fancy.start() 94 fancy.wait_for_open_port(80) 95 fancy.wait_for_unit("uwsgi") 96 fancy.succeed( 97 "${pkgs.curl}/bin/curl --fail http://localhost/searx >&2" 98 ) 99 fancy.succeed( 100 "${pkgs.curl}/bin/curl --fail http://localhost/searx/static/themes/simple/js/leaflet.js >&2" 101 ) 102 ''; 103}