Skip to content

Commit 6d046e1

Browse files
emilazythoughtpolice
authored andcommitted
openresty: rebase on top of nginx package
The primary motivation of this change was to allow third-party modules to be used with OpenResty, but it also results in a significant reduction of code duplication.
1 parent db3182a commit 6d046e1

4 files changed

Lines changed: 72 additions & 71 deletions

File tree

pkgs/servers/http/nginx/generic.nix

Lines changed: 46 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,20 @@
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

1124
with stdenv.lib;
@@ -16,21 +29,23 @@ let
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

2235
in
2336

2437
stdenv.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;
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{ callPackage, ... }@args:
22

3-
callPackage ./generic.nix (args // {
3+
callPackage ./generic.nix args {
44
version = "1.17.8";
55
sha256 = "0nwn4md8sxhks2j77qq1nvk5pfz3yykfhh2b507b6l2idp7kxllp";
6-
})
6+
}

pkgs/servers/http/nginx/stable.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{ callPackage, ... } @ args:
22

3-
callPackage ./generic.nix (args // {
3+
callPackage ./generic.nix args {
44
version = "1.16.1";
55
sha256 = "0az3vf463b538ajvaq94hsz9ipmjgnamfj1jy0v5flfks5njl77i";
6-
})
6+
}
Lines changed: 22 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,35 @@
1-
{ stdenv, fetchurl, openssl, zlib, pcre, postgresql, libxml2, libxslt,
2-
gd, geoip, perl }:
3-
4-
with stdenv.lib;
5-
6-
stdenv.mkDerivation rec {
1+
{ callPackage
2+
, runCommand
3+
, lib
4+
, fetchurl
5+
, postgresql
6+
, ...
7+
}@args:
8+
9+
callPackage ../nginx/generic.nix args rec {
710
pname = "openresty";
8-
version = "1.15.8.2";
11+
nginxVersion = "1.15.8";
12+
version = "${nginxVersion}.2";
913

1014
src = fetchurl {
1115
url = "https://openresty.org/download/openresty-${version}.tar.gz";
1216
sha256 = "05jxrb8hv758nm38jil8n63q1nhrz3d249bsrwc7maa7sn24wss3";
1317
};
1418

15-
buildInputs = [ openssl zlib pcre libxml2 libxslt gd geoip postgresql ];
16-
nativeBuildInputs = [ perl ];
19+
fixPatch = patch:
20+
runCommand "openresty-${patch.name}" { src = patch; } ''
21+
substitute $src $out \
22+
--replace "src/" "bundle/nginx-${nginxVersion}/src/"
23+
'';
1724

18-
NIX_CFLAGS_COMPILE = "-I${libxml2.dev}/include/libxml2";
25+
buildInputs = [ postgresql ];
26+
27+
configureFlags = [ "--with-http_postgres_module" ];
1928

2029
preConfigure = ''
2130
patchShebangs .
2231
'';
2332

24-
configureFlags = [
25-
"--with-pcre-jit"
26-
"--with-http_ssl_module"
27-
"--with-http_v2_module"
28-
"--with-http_realip_module"
29-
"--with-http_addition_module"
30-
"--with-http_xslt_module"
31-
"--with-http_image_filter_module"
32-
"--with-http_geoip_module"
33-
"--with-http_sub_module"
34-
"--with-http_dav_module"
35-
"--with-http_flv_module"
36-
"--with-http_mp4_module"
37-
"--with-http_gunzip_module"
38-
"--with-http_gzip_static_module"
39-
"--with-http_auth_request_module"
40-
"--with-http_random_index_module"
41-
"--with-http_secure_link_module"
42-
"--with-http_degradation_module"
43-
"--with-http_stub_status_module"
44-
"--with-http_postgres_module"
45-
"--with-ipv6"
46-
];
47-
48-
enableParallelBuilding = true;
49-
5033
postInstall = ''
5134
ln -s $out/luajit/bin/luajit-2.1.0-beta3 $out/bin/luajit-openresty
5235
ln -s $out/nginx/sbin/nginx $out/bin/nginx
@@ -55,8 +38,8 @@ stdenv.mkDerivation rec {
5538
meta = {
5639
description = "A fast web application server built on Nginx";
5740
homepage = http://openresty.org;
58-
license = licenses.bsd2;
59-
platforms = platforms.all;
60-
maintainers = with maintainers; [ thoughtpolice lblasc ];
41+
license = lib.licenses.bsd2;
42+
platforms = lib.platforms.all;
43+
maintainers = with lib.maintainers; [ thoughtpolice lblasc emily ];
6144
};
6245
}

0 commit comments

Comments
 (0)