From 9ab02e1ec6e7a9a44a087a8b131e65f77e924c0d Mon Sep 17 00:00:00 2001 From: Henri Menke Date: Sun, 18 Sep 2022 14:54:04 +0200 Subject: [PATCH] nginxModules.njs: init at 0.7.8 --- nixos/tests/all-tests.nix | 1 + nixos/tests/nginx-njs.nix | 27 +++++++++++++++++++++++++++ pkgs/servers/http/nginx/modules.nix | 24 +++++++++++++++++++++++- 3 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 nixos/tests/nginx-njs.nix diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index 380f1a7d27e2..fbbebc2520a3 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -429,6 +429,7 @@ in { nginx-etag = handleTest ./nginx-etag.nix {}; nginx-http3 = handleTest ./nginx-http3.nix {}; nginx-modsecurity = handleTest ./nginx-modsecurity.nix {}; + nginx-njs = handleTest ./nginx-njs.nix {}; nginx-pubhtml = handleTest ./nginx-pubhtml.nix {}; nginx-sandbox = handleTestOn ["x86_64-linux"] ./nginx-sandbox.nix {}; nginx-sso = handleTest ./nginx-sso.nix {}; diff --git a/nixos/tests/nginx-njs.nix b/nixos/tests/nginx-njs.nix new file mode 100644 index 000000000000..72be16384f1b --- /dev/null +++ b/nixos/tests/nginx-njs.nix @@ -0,0 +1,27 @@ +import ./make-test-python.nix ({ pkgs, lib, ... }: { + name = "nginx-njs"; + + nodes.machine = { config, lib, pkgs, ... }: { + services.nginx = { + enable = true; + additionalModules = [ pkgs.nginxModules.njs ]; + commonHttpConfig = '' + js_import http from ${builtins.toFile "http.js" '' + function hello(r) { + r.return(200, "Hello world!"); + } + export default {hello}; + ''}; + ''; + virtualHosts."localhost".locations."/".extraConfig = '' + js_content http.hello; + ''; + }; + }; + testScript = '' + machine.wait_for_unit("nginx") + + response = machine.wait_until_succeeds("curl -fvvv -s http://127.0.0.1/") + assert "Hello world!" == response, f"Expected 'Hello world!', got '{response}'" + ''; +}) diff --git a/pkgs/servers/http/nginx/modules.nix b/pkgs/servers/http/nginx/modules.nix index 09f58becbab4..7d8a6716bc97 100644 --- a/pkgs/servers/http/nginx/modules.nix +++ b/pkgs/servers/http/nginx/modules.nix @@ -1,4 +1,4 @@ -{ fetchFromGitHub, fetchFromGitLab, lib, pkgs }: +{ fetchFromGitHub, fetchFromGitLab, fetchhg, lib, pkgs }: let @@ -290,6 +290,28 @@ in } + "/naxsi_src"; }; + njs = rec { + src = fetchhg { + url = "https://hg.nginx.org/njs"; + rev = "0.7.8"; + sha256 = "sha256-jsR8EOeW8tAo2utKznuUaCG4hK0oU0ZJSnnGmI5HUDk="; + name = "nginx-njs"; + }; + + # njs module sources have to be writable during nginx build, so we copy them + # to a temporary directory and change the module path in the configureFlags + preConfigure = '' + NJS_SOURCE_DIR=$(readlink -m "$TMPDIR/${src}") + mkdir -p "$(dirname "$NJS_SOURCE_DIR")" + cp --recursive "${src}" "$NJS_SOURCE_DIR" + chmod -R u+rwX,go+rX "$NJS_SOURCE_DIR" + export configureFlags="''${configureFlags/"${src}"/"$NJS_SOURCE_DIR/nginx"}" + unset NJS_SOURCE_DIR + ''; + + inputs = [ pkgs.which ]; + }; + opentracing = { src = let src' = fetchFromGitHub {