2022-05-18 14:49:53 +00:00
|
|
|
outer@{ lib, stdenv, fetchurl, fetchpatch, openssl, zlib, pcre, libxml2, libxslt
|
|
|
|
, nginx-doc
|
2021-03-20 04:20:00 +00:00
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
, nixosTests
|
2023-11-16 04:20:00 +00:00
|
|
|
, installShellFiles, substituteAll, removeReferencesTo, gd, geoip, perl
|
2020-04-24 23:36:52 +00:00
|
|
|
, withDebug ? false
|
2024-06-05 15:53:02 +00:00
|
|
|
, withGeoIP ? false
|
|
|
|
, withImageFilter ? false
|
2024-01-02 11:29:13 +00:00
|
|
|
, withKTLS ? true
|
2020-04-24 23:36:52 +00:00
|
|
|
, withStream ? true
|
|
|
|
, withMail ? false
|
2020-06-15 15:56:04 +00:00
|
|
|
, withPerl ? true
|
2022-12-28 21:21:41 +00:00
|
|
|
, withSlice ? false
|
2020-04-24 23:36:52 +00:00
|
|
|
, modules ? []
|
|
|
|
, ...
|
|
|
|
}:
|
|
|
|
|
|
|
|
{ pname ? "nginx"
|
|
|
|
, version
|
|
|
|
, nginxVersion ? version
|
|
|
|
, src ? null # defaults to upstream nginx ${version}
|
2023-04-12 12:48:02 +00:00
|
|
|
, hash ? null # when not specifying src
|
2020-04-24 23:36:52 +00:00
|
|
|
, configureFlags ? []
|
2022-12-28 21:21:41 +00:00
|
|
|
, nativeBuildInputs ? []
|
2020-04-24 23:36:52 +00:00
|
|
|
, buildInputs ? []
|
2022-04-27 09:35:20 +00:00
|
|
|
, extraPatches ? []
|
2020-04-24 23:36:52 +00:00
|
|
|
, fixPatch ? p: p
|
2022-12-28 21:21:41 +00:00
|
|
|
, postPatch ? ""
|
2020-04-24 23:36:52 +00:00
|
|
|
, preConfigure ? ""
|
2024-01-02 11:29:13 +00:00
|
|
|
, preInstall ? ""
|
2022-06-16 17:23:12 +00:00
|
|
|
, postInstall ? ""
|
2020-04-24 23:36:52 +00:00
|
|
|
, meta ? null
|
2022-05-18 14:49:53 +00:00
|
|
|
, nginx-doc ? outer.nginx-doc
|
2021-10-28 06:52:43 +00:00
|
|
|
, passthru ? { tests = {}; }
|
2020-04-24 23:36:52 +00:00
|
|
|
}:
|
|
|
|
|
|
|
|
let
|
|
|
|
|
2022-12-17 10:02:37 +00:00
|
|
|
moduleNames = map (mod: mod.name or (throw "The nginx module with source ${toString mod.src} does not have a `name` attribute. This prevents duplicate module detection and is no longer supported."))
|
|
|
|
modules;
|
|
|
|
|
2023-02-16 17:41:37 +00:00
|
|
|
mapModules = attrPath: lib.flip lib.concatMap modules
|
2020-04-24 23:36:52 +00:00
|
|
|
(mod:
|
|
|
|
let supports = mod.supports or (_: true);
|
|
|
|
in
|
|
|
|
if supports nginxVersion then mod.${attrPath} or []
|
|
|
|
else throw "Module at ${toString mod.src} does not support nginx version ${nginxVersion}!");
|
|
|
|
|
|
|
|
in
|
|
|
|
|
2023-02-16 17:41:37 +00:00
|
|
|
assert lib.assertMsg (lib.unique moduleNames == moduleNames)
|
|
|
|
"nginx: duplicate modules: ${lib.concatStringsSep ", " moduleNames}. A common cause for this is that services.nginx.additionalModules adds a module which the nixos module itself already adds.";
|
2022-12-17 10:02:37 +00:00
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
stdenv.mkDerivation {
|
2022-12-28 21:21:41 +00:00
|
|
|
inherit pname version nginxVersion;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2023-11-16 04:20:00 +00:00
|
|
|
outputs = [ "out" "doc" ];
|
2022-05-18 14:49:53 +00:00
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
src = if src != null then src else fetchurl {
|
|
|
|
url = "https://nginx.org/download/nginx-${version}.tar.gz";
|
2023-04-12 12:48:02 +00:00
|
|
|
inherit hash;
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
2023-11-16 04:20:00 +00:00
|
|
|
nativeBuildInputs = [
|
|
|
|
installShellFiles
|
|
|
|
removeReferencesTo
|
|
|
|
] ++ nativeBuildInputs;
|
2022-12-28 21:21:41 +00:00
|
|
|
|
2024-06-05 15:53:02 +00:00
|
|
|
buildInputs = [ openssl zlib pcre libxml2 libxslt perl ]
|
2020-04-24 23:36:52 +00:00
|
|
|
++ buildInputs
|
2024-06-05 15:53:02 +00:00
|
|
|
++ mapModules "inputs"
|
|
|
|
++ lib.optional withGeoIP geoip
|
|
|
|
++ lib.optional withImageFilter gd;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
configureFlags = [
|
2024-01-02 11:29:13 +00:00
|
|
|
"--sbin-path=bin/nginx"
|
2020-04-24 23:36:52 +00:00
|
|
|
"--with-http_ssl_module"
|
|
|
|
"--with-http_v2_module"
|
|
|
|
"--with-http_realip_module"
|
|
|
|
"--with-http_addition_module"
|
|
|
|
"--with-http_xslt_module"
|
|
|
|
"--with-http_sub_module"
|
|
|
|
"--with-http_dav_module"
|
|
|
|
"--with-http_flv_module"
|
|
|
|
"--with-http_mp4_module"
|
|
|
|
"--with-http_gunzip_module"
|
|
|
|
"--with-http_gzip_static_module"
|
|
|
|
"--with-http_auth_request_module"
|
|
|
|
"--with-http_random_index_module"
|
|
|
|
"--with-http_secure_link_module"
|
|
|
|
"--with-http_degradation_module"
|
|
|
|
"--with-http_stub_status_module"
|
|
|
|
"--with-threads"
|
|
|
|
"--with-pcre-jit"
|
2020-05-15 21:57:56 +00:00
|
|
|
"--http-log-path=/var/log/nginx/access.log"
|
|
|
|
"--error-log-path=/var/log/nginx/error.log"
|
|
|
|
"--pid-path=/var/log/nginx/nginx.pid"
|
2022-12-02 08:20:57 +00:00
|
|
|
"--http-client-body-temp-path=/tmp/nginx_client_body"
|
|
|
|
"--http-proxy-temp-path=/tmp/nginx_proxy"
|
|
|
|
"--http-fastcgi-temp-path=/tmp/nginx_fastcgi"
|
|
|
|
"--http-uwsgi-temp-path=/tmp/nginx_uwsgi"
|
|
|
|
"--http-scgi-temp-path=/tmp/nginx_scgi"
|
2023-02-16 17:41:37 +00:00
|
|
|
] ++ lib.optionals withDebug [
|
2020-04-24 23:36:52 +00:00
|
|
|
"--with-debug"
|
2023-02-16 17:41:37 +00:00
|
|
|
] ++ lib.optionals withKTLS [
|
2021-12-25 05:07:40 +00:00
|
|
|
"--with-openssl-opt=enable-ktls"
|
2023-02-16 17:41:37 +00:00
|
|
|
] ++ lib.optionals withStream [
|
2020-04-24 23:36:52 +00:00
|
|
|
"--with-stream"
|
|
|
|
"--with-stream_realip_module"
|
|
|
|
"--with-stream_ssl_module"
|
|
|
|
"--with-stream_ssl_preread_module"
|
2023-02-16 17:41:37 +00:00
|
|
|
] ++ lib.optionals withMail [
|
2020-04-24 23:36:52 +00:00
|
|
|
"--with-mail"
|
|
|
|
"--with-mail_ssl_module"
|
2023-02-16 17:41:37 +00:00
|
|
|
] ++ lib.optionals withPerl [
|
2020-04-24 23:36:52 +00:00
|
|
|
"--with-http_perl_module"
|
|
|
|
"--with-perl=${perl}/bin/perl"
|
|
|
|
"--with-perl_modules_path=lib/perl5"
|
2024-06-05 15:53:02 +00:00
|
|
|
] ++ lib.optional withImageFilter "--with-http_image_filter_module"
|
|
|
|
++ lib.optional withSlice "--with-http_slice_module"
|
|
|
|
++ lib.optionals withGeoIP ([ "--with-http_geoip_module" ] ++ lib.optional withStream "--with-stream_geoip_module")
|
2023-02-16 17:41:37 +00:00
|
|
|
++ lib.optional (with stdenv.hostPlatform; isLinux || isFreeBSD) "--with-file-aio"
|
2020-04-24 23:36:52 +00:00
|
|
|
++ configureFlags
|
|
|
|
++ map (mod: "--add-module=${mod.src}") modules;
|
|
|
|
|
2023-03-04 12:14:45 +00:00
|
|
|
env.NIX_CFLAGS_COMPILE = toString ([
|
2020-04-24 23:36:52 +00:00
|
|
|
"-I${libxml2.dev}/include/libxml2"
|
|
|
|
"-Wno-error=implicit-fallthrough"
|
2023-02-16 17:41:37 +00:00
|
|
|
] ++ lib.optionals (stdenv.cc.isGNU && lib.versionAtLeast stdenv.cc.version "11") [
|
2022-04-27 09:35:20 +00:00
|
|
|
# fix build vts module on gcc11
|
|
|
|
"-Wno-error=stringop-overread"
|
2024-01-02 11:29:13 +00:00
|
|
|
] ++ lib.optionals stdenv.isDarwin [
|
|
|
|
"-Wno-error=deprecated-declarations"
|
|
|
|
"-Wno-error=gnu-folding-constant"
|
|
|
|
"-Wno-error=unused-but-set-variable"
|
2024-06-05 15:53:02 +00:00
|
|
|
] ++ lib.optionals stdenv.hostPlatform.isMusl [
|
|
|
|
# fix sys/cdefs.h is deprecated
|
|
|
|
"-Wno-error=cpp"
|
2024-01-02 11:29:13 +00:00
|
|
|
]);
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
configurePlatforms = [];
|
|
|
|
|
2022-05-18 14:49:53 +00:00
|
|
|
# Disable _multioutConfig hook which adds --bindir=$out/bin into configureFlags,
|
|
|
|
# which breaks build, since nginx does not actually use autoconf.
|
|
|
|
preConfigure = ''
|
|
|
|
setOutputFlags=
|
|
|
|
'' + preConfigure
|
2023-02-16 17:41:37 +00:00
|
|
|
+ lib.concatMapStringsSep "\n" (mod: mod.preConfigure or "") modules;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2020-05-15 21:57:56 +00:00
|
|
|
patches = map fixPatch ([
|
|
|
|
(substituteAll {
|
2020-04-24 23:36:52 +00:00
|
|
|
src = ./nix-etag-1.15.4.patch;
|
|
|
|
preInstall = ''
|
|
|
|
export nixStoreDir="$NIX_STORE" nixStoreDirLen="''${#NIX_STORE}"
|
|
|
|
'';
|
2020-05-15 21:57:56 +00:00
|
|
|
})
|
|
|
|
./nix-skip-check-logs-path.patch
|
2023-02-16 17:41:37 +00:00
|
|
|
] ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [
|
2020-05-15 21:57:56 +00:00
|
|
|
(fetchpatch {
|
2021-09-22 15:38:15 +00:00
|
|
|
url = "https://raw.githubusercontent.com/openwrt/packages/c057dfb09c7027287c7862afab965a4cd95293a3/net/nginx/patches/102-sizeof_test_fix.patch";
|
2020-05-15 21:57:56 +00:00
|
|
|
sha256 = "0i2k30ac8d7inj9l6bl0684kjglam2f68z8lf3xggcc2i5wzhh8a";
|
|
|
|
})
|
|
|
|
(fetchpatch {
|
2021-09-22 15:38:15 +00:00
|
|
|
url = "https://raw.githubusercontent.com/openwrt/packages/c057dfb09c7027287c7862afab965a4cd95293a3/net/nginx/patches/101-feature_test_fix.patch";
|
2020-05-15 21:57:56 +00:00
|
|
|
sha256 = "0v6890a85aqmw60pgj3mm7g8nkaphgq65dj4v9c6h58wdsrc6f0y";
|
|
|
|
})
|
|
|
|
(fetchpatch {
|
2021-09-22 15:38:15 +00:00
|
|
|
url = "https://raw.githubusercontent.com/openwrt/packages/c057dfb09c7027287c7862afab965a4cd95293a3/net/nginx/patches/103-sys_nerr.patch";
|
2020-05-15 21:57:56 +00:00
|
|
|
sha256 = "0s497x6mkz947aw29wdy073k8dyjq8j99lax1a1mzpikzr4rxlmd";
|
|
|
|
})
|
2022-04-27 09:35:20 +00:00
|
|
|
] ++ mapModules "patches")
|
|
|
|
++ extraPatches;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2022-12-28 21:21:41 +00:00
|
|
|
inherit postPatch;
|
|
|
|
|
2023-02-16 17:41:37 +00:00
|
|
|
hardeningEnable = lib.optional (!stdenv.isDarwin) "pie";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
enableParallelBuilding = true;
|
|
|
|
|
2022-05-18 14:49:53 +00:00
|
|
|
preInstall = ''
|
|
|
|
mkdir -p $doc
|
|
|
|
cp -r ${nginx-doc}/* $doc
|
2023-11-16 04:20:00 +00:00
|
|
|
|
|
|
|
# TODO: make it unconditional when `openresty` and `nginx` are not
|
|
|
|
# sharing this code.
|
|
|
|
if [[ -e man/nginx.8 ]]; then
|
|
|
|
installManPage man/nginx.8
|
|
|
|
fi
|
2024-01-02 11:29:13 +00:00
|
|
|
'' + preInstall;
|
2022-05-18 14:49:53 +00:00
|
|
|
|
2022-06-16 17:23:12 +00:00
|
|
|
disallowedReferences = map (m: m.src) modules;
|
|
|
|
|
|
|
|
postInstall =
|
|
|
|
let
|
2024-01-02 11:29:13 +00:00
|
|
|
noSourceRefs = lib.concatMapStrings (m: "remove-references-to -t ${m.src} $out/bin/nginx\n") modules;
|
2022-06-16 17:23:12 +00:00
|
|
|
in noSourceRefs + postInstall;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
passthru = {
|
2023-05-24 13:37:59 +00:00
|
|
|
inherit modules;
|
2021-04-15 00:37:46 +00:00
|
|
|
tests = {
|
2024-01-25 14:12:00 +00:00
|
|
|
inherit (nixosTests) nginx nginx-auth nginx-etag nginx-etag-compression nginx-globalredirect nginx-http3 nginx-proxyprotocol nginx-pubhtml nginx-sso nginx-status-page nginx-unix-socket;
|
2021-04-15 00:37:46 +00:00
|
|
|
variants = lib.recurseIntoAttrs nixosTests.nginx-variants;
|
2021-05-20 23:08:51 +00:00
|
|
|
acme-integration = nixosTests.acme;
|
2021-10-28 06:52:43 +00:00
|
|
|
} // passthru.tests;
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
2023-02-16 17:41:37 +00:00
|
|
|
meta = if meta != null then meta else with lib; {
|
2020-04-24 23:36:52 +00:00
|
|
|
description = "A reverse proxy and lightweight webserver";
|
2024-04-21 15:54:59 +00:00
|
|
|
mainProgram = "nginx";
|
2020-04-24 23:36:52 +00:00
|
|
|
homepage = "http://nginx.org";
|
2023-05-24 13:37:59 +00:00
|
|
|
license = [ licenses.bsd2 ]
|
|
|
|
++ concatMap (m: m.meta.license) modules;
|
2020-04-24 23:36:52 +00:00
|
|
|
platforms = platforms.all;
|
2024-01-02 11:29:13 +00:00
|
|
|
maintainers = with maintainers; [ fpletz raitobezarius ] ++ teams.helsinki-systems.members;
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
}
|