55, withStream ? true
66, withMail ? false
77, modules ? [ ]
8- , version , sha256 , ...
8+ , ...
9+ } :
10+
11+ { pname ? "nginx"
12+ , version
13+ , nginxVersion ? version
14+ , src ? null # defaults to upstream nginx ${version}
15+ , sha256 ? null # when not specifying src
16+ , configureFlags ? [ ]
17+ , buildInputs ? [ ]
18+ , fixPatch ? p : p
19+ , preConfigure ? ""
20+ , postInstall ? null
21+ , meta ? null
922} :
1023
1124with stdenv . lib ;
1629 ( mod :
1730 let supports = mod . supports or ( _ : true ) ;
1831 in
19- if supports version then mod . ${ attrPath } or [ ]
20- else throw "Module at ${ toString mod . src } does not support nginx version ${ version } !" ) ;
32+ if supports nginxVersion then mod . ${ attrPath } or [ ]
33+ else throw "Module at ${ toString mod . src } does not support nginx version ${ nginxVersion } !" ) ;
2134
2235in
2336
2437stdenv . mkDerivation {
25- pname = "nginx" ;
38+ inherit pname ;
2639 inherit version ;
40+ inherit nginxVersion ;
2741
28- src = fetchurl {
42+ src = if src != null then src else fetchurl {
2943 url = "https://nginx.org/download/nginx-${ version } .tar.gz" ;
3044 inherit sha256 ;
3145 } ;
3246
3347 buildInputs = [ openssl zlib pcre libxml2 libxslt gd geoip perl ]
48+ ++ buildInputs
3449 ++ mapModules "inputs" ;
3550
3651 configureFlags = [
@@ -71,6 +86,7 @@ stdenv.mkDerivation {
7186 ]
7287 ++ optional ( gd != null ) "--with-http_image_filter_module"
7388 ++ optional ( with stdenv . hostPlatform ; isLinux || isFreeBSD ) "--with-file-aio"
89+ ++ configureFlags
7490 ++ map ( mod : "--add-module=${ mod . src } " ) modules ;
7591
7692 NIX_CFLAGS_COMPILE = toString ( [
@@ -80,33 +96,35 @@ stdenv.mkDerivation {
8096
8197 configurePlatforms = [ ] ;
8298
83- preConfigure = ( concatMapStringsSep "\n " ( mod : mod . preConfigure or "" ) modules ) ;
84-
85- patches = stdenv . lib . singleton ( substituteAll {
86- src = ./nix-etag-1.15.4.patch ;
87- preInstall = ''
88- export nixStoreDir="$NIX_STORE" nixStoreDirLen="'' ${#NIX_STORE}"
89- '' ;
90- } ) ++ stdenv . lib . optionals ( stdenv . hostPlatform != stdenv . buildPlatform ) [
91- ( fetchpatch {
92- url = "https://raw.githubusercontent.com/openwrt/packages/master/net/nginx/patches/102-sizeof_test_fix.patch" ;
93- sha256 = "0i2k30ac8d7inj9l6bl0684kjglam2f68z8lf3xggcc2i5wzhh8a" ;
94- } )
95- ( fetchpatch {
96- url = "https://raw.githubusercontent.com/openwrt/packages/master/net/nginx/patches/101-feature_test_fix.patch" ;
97- sha256 = "0v6890a85aqmw60pgj3mm7g8nkaphgq65dj4v9c6h58wdsrc6f0y" ;
98- } )
99- ( fetchpatch {
100- url = "https://raw.githubusercontent.com/openwrt/packages/master/net/nginx/patches/103-sys_nerr.patch" ;
101- sha256 = "0s497x6mkz947aw29wdy073k8dyjq8j99lax1a1mzpikzr4rxlmd" ;
102- } )
103- ] ++ mapModules "patches" ;
99+ preConfigure = preConfigure
100+ + concatMapStringsSep "\n " ( mod : mod . preConfigure or "" ) modules ;
101+
102+ patches = map fixPatch
103+ ( singleton ( substituteAll {
104+ src = ./nix-etag-1.15.4.patch ;
105+ preInstall = ''
106+ export nixStoreDir="$NIX_STORE" nixStoreDirLen="'' ${#NIX_STORE}"
107+ '' ;
108+ } ) ++ optionals ( stdenv . hostPlatform != stdenv . buildPlatform ) [
109+ ( fetchpatch {
110+ url = "https://raw.githubusercontent.com/openwrt/packages/master/net/nginx/patches/102-sizeof_test_fix.patch" ;
111+ sha256 = "0i2k30ac8d7inj9l6bl0684kjglam2f68z8lf3xggcc2i5wzhh8a" ;
112+ } )
113+ ( fetchpatch {
114+ url = "https://raw.githubusercontent.com/openwrt/packages/master/net/nginx/patches/101-feature_test_fix.patch" ;
115+ sha256 = "0v6890a85aqmw60pgj3mm7g8nkaphgq65dj4v9c6h58wdsrc6f0y" ;
116+ } )
117+ ( fetchpatch {
118+ url = "https://raw.githubusercontent.com/openwrt/packages/master/net/nginx/patches/103-sys_nerr.patch" ;
119+ sha256 = "0s497x6mkz947aw29wdy073k8dyjq8j99lax1a1mzpikzr4rxlmd" ;
120+ } )
121+ ] ++ mapModules "patches" ) ;
104122
105123 hardeningEnable = optional ( ! stdenv . isDarwin ) "pie" ;
106124
107125 enableParallelBuilding = true ;
108126
109- postInstall = ''
127+ postInstall = if postInstall != null then postInstall else ''
110128 mv $out/sbin $out/bin
111129 '' ;
112130
@@ -115,7 +133,7 @@ stdenv.mkDerivation {
115133 tests . nginx = nixosTests . nginx ;
116134 } ;
117135
118- meta = {
136+ meta = if meta != null then meta else {
119137 description = "A reverse proxy and lightweight webserver" ;
120138 homepage = http://nginx.org ;
121139 license = licenses . bsd2 ;
0 commit comments