nginx: make module source trees writable

The config script of multiple nginx modules must be able to write into
its source tree, so let's accumulate this logic once in nginx instead of
in multiple modules.
This commit is contained in:
Martin Weinelt
2026-07-29 13:53:36 +02:00
parent 30538743b2
commit 8d6d3999f9
3 changed files with 10 additions and 20 deletions

View File

@@ -167,8 +167,7 @@ stdenv.mkDerivation {
++ lib.optional (
stdenv.buildPlatform != stdenv.hostPlatform
) "--crossbuild=${stdenv.hostPlatform.uname.system}::${stdenv.hostPlatform.uname.processor}"
++ configureFlags
++ map (mod: "--add-module=${mod}") modules;
++ configureFlags;
env = {
NIX_CFLAGS_COMPILE = toString (
@@ -209,6 +208,15 @@ stdenv.mkDerivation {
preConfigure = ''
setOutputFlags=
''
# Make all modules source trees writable
+ ''
for module in ${toString modules}; do
dst="$NIX_BUILD_TOP/$(basename "$module")"
cp --recursive "$module" "$dst"
chmod --recursive +w "$dst"
appendToVar configureFlags "--add-module=$dst"
done
''
+ preConfigure
+ lib.concatMapStringsSep "\n" (mod: mod.preConfigure or "") modules;

View File

@@ -21,13 +21,6 @@ mkNginxPlugin (finalAttrs: {
preConfigure = ''
export LUAJIT_LIB="${luajit_openresty}/lib"
export LUAJIT_INC="$(realpath ${luajit_openresty}/include/luajit-*)"
# make source directory writable to allow generating src/ngx_http_lua_autoconf.h
lua_src=$TMPDIR/lua-src
cp -r "${finalAttrs.src}/" "$lua_src"
chmod -R +w "$lua_src"
export configureFlags="''${configureFlags//"${finalAttrs.src}"/"$lua_src"}"
unset lua_src
'';
allowMemoryWriteExecute = true;

View File

@@ -18,17 +18,6 @@ mkNginxPlugin (finalAttrs: {
hash = "sha256-Ee55QKaeZ0mYGKUroKr/AYGoOCakEonU483qkhmZdzU=";
};
# 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/${finalAttrs.src}")
mkdir -p "$(dirname "$NJS_SOURCE_DIR")"
cp --recursive "${finalAttrs.src}" "$NJS_SOURCE_DIR"
chmod -R u+rwX,go+rX "$NJS_SOURCE_DIR"
export configureFlags="''${configureFlags/"${finalAttrs.src}"/"$NJS_SOURCE_DIR/nginx"} --with-ld-opt='-lz'"
unset NJS_SOURCE_DIR
'';
buildInputs = [
which
zlib