about summary refs log tree commit diff
diff options
context:
space:
mode:
author7c6f434c <7c6f434c@mail.ru>2022-05-12 09:21:41 +0000
committerGitHub <noreply@github.com>2022-05-12 09:21:41 +0000
commit12697a1621da942e4b12f864b3bdd57d9ddcbea0 (patch)
tree392f36617bc7ab9261d1f74128aabbfa57ea7e8a
parentc47a0e0d39e047230424744e4a1f9061067288e4 (diff)
parentaa9eb4509c2bb0c258f84d3d465096888c1e0565 (diff)
Merge pull request #172016 from KAction/nginx-doc
nginx: build offline documentation
-rw-r--r--pkgs/data/documentation/nginx-doc/default.nix40
-rw-r--r--pkgs/data/documentation/nginx-doc/exclude-google-analytics.patch29
-rw-r--r--pkgs/servers/http/nginx/generic.nix19
-rw-r--r--pkgs/top-level/all-packages.nix2
4 files changed, 87 insertions, 3 deletions
diff --git a/pkgs/data/documentation/nginx-doc/default.nix b/pkgs/data/documentation/nginx-doc/default.nix
new file mode 100644
index 0000000000000..c367912d6f982
--- /dev/null
+++ b/pkgs/data/documentation/nginx-doc/default.nix
@@ -0,0 +1,40 @@
+{ lib, stdenv, libxml2, libxslt, fetchhg }:
+
+# Upstream maintains documentation (sources of https://nginx.org) in separate
+# mercurial repository, which do not correspond to particular git commit, but at
+# least has "introduced in version X.Y" comments.
+#
+# In other words, documentation does not necessary matches capabilities of
+# $out/bin/nginx, but we have no better options.
+stdenv.mkDerivation {
+  pname = "nginx-doc-unstable";
+  version = "2022-05-05";
+  src = fetchhg {
+    url = "https://hg.nginx.org/nginx.org";
+    rev = "a3aee2697d4e";
+    sha256 = "029n4mnmjw94h01qalmjgf1c2h3h7wm798xv5knk3padxiy4m28b";
+  };
+  patches = [ ./exclude-google-analytics.patch ];
+  nativeBuildInputs = [ libxslt libxml2 ];
+
+  # Generated documentation is not local-friendly, since it assumes that link to directory
+  # is the same as link to index.html in that directory, which is not how browsers behave
+  # with local filesystem.
+  #
+  # TODO: patch all relative links that do not end with .html.
+
+  # /en subdirectory must exist, relative links expect it.
+  installPhase = ''
+    mkdir -p $out/share/doc/nginx
+    mv libxslt/en $out/share/doc/nginx
+  '';
+
+  meta = with lib; {
+    description = "A reverse proxy and lightweight webserver (documentation)";
+    homepage    = "https://nginx.org/";
+    license     = licenses.bsd2;
+    platforms   = platforms.all;
+    priority    = 6;
+    maintainers = with maintainers; [ kaction ];
+  };
+}
diff --git a/pkgs/data/documentation/nginx-doc/exclude-google-analytics.patch b/pkgs/data/documentation/nginx-doc/exclude-google-analytics.patch
new file mode 100644
index 0000000000000..c2f3f520c3d10
--- /dev/null
+++ b/pkgs/data/documentation/nginx-doc/exclude-google-analytics.patch
@@ -0,0 +1,29 @@
+Kill google analytics from local documentation.
+
+diff -r bb0a2fbdc886 xslt/ga.xslt
+--- a/xslt/ga.xslt	Mon Apr 06 11:17:11 2020 +0100
++++ b/xslt/ga.xslt	Thu Apr 09 10:29:02 2020 -0400
+@@ -6,23 +6,6 @@
+ <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
+ 
+ <xsl:template name="ga">
+-
+-    <script>
+-        (function(w, d, s, l, i) {
+-            w[l] = w[l] || [];
+-            w[l].push({
+-                'gtm.start': new Date().getTime(),
+-                event: 'gtm.js'
+-            });
+-            var f = d.getElementsByTagName(s)[0],
+-                j = d.createElement(s),
+-                dl = l != 'dataLayer' ? '&amp;l=' + l : '';
+-            j.async = true;
+-            j.src = '//www.googletagmanager.com/gtm.js?id=' + i + dl;
+-            f.parentNode.insertBefore(j, f);
+-        })(window, document, 'script', 'dataLayer', 'GTM-TPSP33');
+-    </script>
+-
+ </xsl:template>
+ 
+ </xsl:stylesheet>
diff --git a/pkgs/servers/http/nginx/generic.nix b/pkgs/servers/http/nginx/generic.nix
index f6b91d77511ec..e189a7d2fdff6 100644
--- a/pkgs/servers/http/nginx/generic.nix
+++ b/pkgs/servers/http/nginx/generic.nix
@@ -1,4 +1,5 @@
-{ lib, stdenv, fetchurl, fetchpatch, openssl, zlib, pcre, libxml2, libxslt
+outer@{ lib, stdenv, fetchurl, fetchpatch, openssl, zlib, pcre, libxml2, libxslt
+, nginx-doc
 
 , nixosTests
 , substituteAll, gd, geoip, perl
@@ -23,6 +24,7 @@
 , preConfigure ? ""
 , postInstall ? null
 , meta ? null
+, nginx-doc ? outer.nginx-doc
 , passthru ? { tests = {}; }
 }:
 
@@ -44,6 +46,8 @@ stdenv.mkDerivation {
   inherit version;
   inherit nginxVersion;
 
+  outputs = ["out" "doc"];
+
   src = if src != null then src else fetchurl {
     url = "https://nginx.org/download/nginx-${version}.tar.gz";
     inherit sha256;
@@ -114,8 +118,12 @@ stdenv.mkDerivation {
 
   configurePlatforms = [];
 
-  preConfigure = preConfigure
-    + concatMapStringsSep "\n" (mod: mod.preConfigure or "") modules;
+  # Disable _multioutConfig hook which adds --bindir=$out/bin into configureFlags,
+  # which breaks build, since nginx does not actually use autoconf.
+  preConfigure = ''
+    setOutputFlags=
+  '' + preConfigure
+     + concatMapStringsSep "\n" (mod: mod.preConfigure or "") modules;
 
   patches = map fixPatch ([
     (substituteAll {
@@ -145,6 +153,11 @@ stdenv.mkDerivation {
 
   enableParallelBuilding = true;
 
+  preInstall = ''
+    mkdir -p $doc
+    cp -r ${nginx-doc}/* $doc
+  '';
+
   postInstall = if postInstall != null then postInstall else ''
     mv $out/sbin $out/bin
   '';
diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix
index 289cee065e6ff..63f0bc9c9f779 100644
--- a/pkgs/top-level/all-packages.nix
+++ b/pkgs/top-level/all-packages.nix
@@ -21996,6 +21996,8 @@ with pkgs;
 
   nginx = nginxStable;
 
+  nginx-doc = callPackage ../data/documentation/nginx-doc { };
+
   nginxQuic = callPackage ../servers/http/nginx/quic.nix {
     zlib = zlib-ng.override { withZlibCompat = true; };
     withPerl = false;