| 
									
										
										
										
											2020-11-02 01:34:53 +01:00
										 |  |  | import ./make-test-python.nix ({ pkgs, ...} : | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   name = "searx"; | 
					
						
							| 
									
										
										
										
											2021-01-17 21:14:59 +01:00
										 |  |  |   meta = with pkgs.lib.maintainers; { | 
					
						
							| 
									
										
										
										
											2020-11-02 01:34:53 +01:00
										 |  |  |     maintainers = [ rnhmjoj ]; | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-06 10:12:20 +01:00
										 |  |  |   # basic setup: searx running the built-in webserver | 
					
						
							|  |  |  |   nodes.base = { ... }: { | 
					
						
							| 
									
										
										
										
											2020-11-02 01:34:53 +01:00
										 |  |  |     imports = [ ../modules/profiles/minimal.nix ]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     services.searx = { | 
					
						
							|  |  |  |       enable = true; | 
					
						
							|  |  |  |       environmentFile = pkgs.writeText "secrets" ''
 | 
					
						
							|  |  |  |         WOLFRAM_API_KEY  = sometoken | 
					
						
							|  |  |  |         SEARX_SECRET_KEY = somesecret | 
					
						
							|  |  |  |       '';
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       settings.server = | 
					
						
							| 
									
										
										
										
											2020-11-06 10:12:20 +01:00
										 |  |  |         { port = "8080"; | 
					
						
							| 
									
										
										
										
											2020-11-02 01:34:53 +01:00
										 |  |  |           bind_address = "0.0.0.0"; | 
					
						
							|  |  |  |           secret_key = "@SEARX_SECRET_KEY@"; | 
					
						
							|  |  |  |         }; | 
					
						
							| 
									
										
										
										
											2021-01-12 22:53:25 +01:00
										 |  |  |       settings.engines = [ | 
					
						
							|  |  |  |         { name = "wolframalpha"; | 
					
						
							|  |  |  |           api_key = "@WOLFRAM_API_KEY@"; | 
					
						
							|  |  |  |           engine = "wolframalpha_api"; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         { name = "startpage"; | 
					
						
							|  |  |  |           shortcut = "start"; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       ]; | 
					
						
							| 
									
										
										
										
											2020-11-06 10:12:20 +01:00
										 |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   # fancy setup: run in uWSGI and use nginx as proxy | 
					
						
							|  |  |  |   nodes.fancy = { ... }: { | 
					
						
							|  |  |  |     imports = [ ../modules/profiles/minimal.nix ]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     services.searx = { | 
					
						
							|  |  |  |       enable = true; | 
					
						
							| 
									
										
										
										
											2021-01-12 20:03:06 +01:00
										 |  |  |       # searx refuses to run if unchanged | 
					
						
							|  |  |  |       settings.server.secret_key = "somesecret"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-06 10:12:20 +01:00
										 |  |  |       runInUwsgi = true; | 
					
						
							|  |  |  |       uwsgiConfig = { | 
					
						
							|  |  |  |         # serve using the uwsgi protocol | 
					
						
							|  |  |  |         socket = "/run/searx/uwsgi.sock"; | 
					
						
							|  |  |  |         chmod-socket = "660"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         # use /searx as url "mountpoint" | 
					
						
							|  |  |  |         mount = "/searx=searx.webapp:application"; | 
					
						
							|  |  |  |         module = ""; | 
					
						
							|  |  |  |         manage-script-name = true; | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  |     }; | 
					
						
							| 
									
										
										
										
											2020-11-02 01:34:53 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-06 10:12:20 +01:00
										 |  |  |     # use nginx as reverse proxy | 
					
						
							|  |  |  |     services.nginx.enable = true; | 
					
						
							|  |  |  |     services.nginx.virtualHosts.localhost = { | 
					
						
							|  |  |  |       locations."/searx".extraConfig = | 
					
						
							|  |  |  |         ''
 | 
					
						
							|  |  |  |           include ${pkgs.nginx}/conf/uwsgi_params; | 
					
						
							|  |  |  |           uwsgi_pass unix:/run/searx/uwsgi.sock; | 
					
						
							|  |  |  |         '';
 | 
					
						
							|  |  |  |       locations."/searx/static/".alias = "${pkgs.searx}/share/static/"; | 
					
						
							| 
									
										
										
										
											2020-11-02 01:34:53 +01:00
										 |  |  |     }; | 
					
						
							| 
									
										
										
										
											2020-11-06 10:12:20 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # allow nginx access to the searx socket | 
					
						
							|  |  |  |     users.users.nginx.extraGroups = [ "searx" ]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-02 01:34:53 +01:00
										 |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   testScript = | 
					
						
							|  |  |  |     ''
 | 
					
						
							| 
									
										
										
										
											2020-11-06 10:12:20 +01:00
										 |  |  |       base.start() | 
					
						
							| 
									
										
										
										
											2020-11-02 01:34:53 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |       with subtest("Settings have been merged"): | 
					
						
							| 
									
										
										
										
											2020-11-06 10:12:20 +01:00
										 |  |  |           base.wait_for_unit("searx-init") | 
					
						
							|  |  |  |           base.wait_for_file("/run/searx/settings.yml") | 
					
						
							|  |  |  |           output = base.succeed( | 
					
						
							| 
									
										
										
										
											2021-01-25 12:11:59 +01:00
										 |  |  |               "${pkgs.yq-go}/bin/yq eval" | 
					
						
							|  |  |  |               " '.engines[] | select(.name==\"startpage\") | .shortcut'" | 
					
						
							|  |  |  |               " /run/searx/settings.yml" | 
					
						
							| 
									
										
										
										
											2020-11-02 01:34:53 +01:00
										 |  |  |           ).strip() | 
					
						
							|  |  |  |           assert output == "start", "Settings not merged" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       with subtest("Environment variables have been substituted"): | 
					
						
							| 
									
										
										
										
											2020-11-06 10:12:20 +01:00
										 |  |  |           base.succeed("grep -q somesecret /run/searx/settings.yml") | 
					
						
							|  |  |  |           base.succeed("grep -q sometoken /run/searx/settings.yml") | 
					
						
							|  |  |  |           base.copy_from_vm("/run/searx/settings.yml") | 
					
						
							| 
									
										
										
										
											2020-11-02 01:34:53 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-06 10:12:20 +01:00
										 |  |  |       with subtest("Basic setup is working"): | 
					
						
							|  |  |  |           base.wait_for_open_port(8080) | 
					
						
							|  |  |  |           base.wait_for_unit("searx") | 
					
						
							|  |  |  |           base.succeed( | 
					
						
							| 
									
										
										
										
											2020-11-02 01:34:53 +01:00
										 |  |  |               "${pkgs.curl}/bin/curl --fail http://localhost:8080" | 
					
						
							|  |  |  |           ) | 
					
						
							| 
									
										
										
										
											2020-11-06 10:12:20 +01:00
										 |  |  |           base.shutdown() | 
					
						
							| 
									
										
										
										
											2020-11-02 01:34:53 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-06 10:12:20 +01:00
										 |  |  |       with subtest("Nginx+uWSGI setup is working"): | 
					
						
							|  |  |  |           fancy.start() | 
					
						
							|  |  |  |           fancy.wait_for_open_port(80) | 
					
						
							|  |  |  |           fancy.wait_for_unit("uwsgi") | 
					
						
							|  |  |  |           fancy.succeed( | 
					
						
							|  |  |  |               "${pkgs.curl}/bin/curl --fail http://localhost/searx >&2" | 
					
						
							|  |  |  |           ) | 
					
						
							|  |  |  |           fancy.succeed( | 
					
						
							|  |  |  |               "${pkgs.curl}/bin/curl --fail http://localhost/searx/static/js/bootstrap.min.js >&2" | 
					
						
							|  |  |  |           ) | 
					
						
							| 
									
										
										
										
											2020-11-02 01:34:53 +01:00
										 |  |  |     '';
 | 
					
						
							|  |  |  | }) |