nginxModules.njs: init at 0.7.8

This commit is contained in:
Henri Menke 2022-09-18 14:54:04 +02:00
parent 830a385b5f
commit 9ab02e1ec6
No known key found for this signature in database
GPG key ID: FB7AD61E3D806382
3 changed files with 51 additions and 1 deletions

View file

@ -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 {};

27
nixos/tests/nginx-njs.nix Normal file
View file

@ -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}'"
'';
})

View file

@ -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 {