>From 9ec69c888b978cb870a5873af8e327541fe4ef7a Mon Sep 17 00:00:00 2001
From: Florian Pelz
Date: Sun, 6 Oct 2019 20:45:34 +0200
Subject: [PATCH 1/2] [wip] gnu: Add ngx_http_accept_language_module.
* gnu/packages/web-xyz.scm: New file.
* gnu/local.mk (GNU_SYSTEM_MODULES): Add package.
---
gnu/local.mk | 1 +
gnu/packages/web-xyz.scm | 175 +++++++++++++++++++++++++++++++++++++++
2 files changed, 176 insertions(+)
create mode 100644 gnu/packages/web-xyz.scm
diff --git a/gnu/local.mk b/gnu/local.mk
index 54ae09f619..96a6c0087a 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -497,6 +497,7 @@ GNU_SYSTEM_MODULES = \
%D%/packages/wdiff.scm \
%D%/packages/web.scm \
%D%/packages/web-browsers.scm \
+ %D%/packages/web-xyz.scm \
%D%/packages/webkit.scm \
%D%/packages/wget.scm \
%D%/packages/wicd.scm \
diff --git a/gnu/packages/web-xyz.scm b/gnu/packages/web-xyz.scm
new file mode 100644
index 0000000000..61e7f847a7
--- /dev/null
+++ b/gnu/packages/web-xyz.scm
@@ -0,0 +1,175 @@
+;;; GNU Guix --- Functional package management for GNU
+;;;; TODO should I really add copyright lines for people I copied from??
+;;; Copyright © 2014, 2015 Mark H Weaver
+;;; Copyright © 2016 Tobias Geerinckx-Rice
+;;; Copyright © 2017, 2018 Marius Bakke
+
+;;; Copyright © 2019 Florian Pelz
+;;;
+;;; This file is part of GNU Guix.
+;;;
+;;; GNU Guix is free software; you can redistribute it and/or modify it
+;;; under the terms of the GNU General Public License as published by
+;;; the Free Software Foundation; either version 3 of the License, or (at
+;;; your option) any later version.
+;;;
+;;; GNU Guix is distributed in the hope that it will be useful, but
+;;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;;; GNU General Public License for more details.
+;;;
+;;; You should have received a copy of the GNU General Public License
+;;; along with GNU Guix. If not, see .
+
+(define-module (gnu packages web-xyz)
+ #:use-module (guix build-system gnu)
+ #:use-module (guix gexp)
+ #:use-module (guix git-download)
+ #:use-module ((guix licenses) #:prefix license:)
+ #:use-module (guix packages)
+ #:use-module (gnu packages base)
+ #:use-module (gnu packages compression)
+ #:use-module (gnu packages pcre)
+ #:use-module (gnu packages tls)
+ #:use-module (gnu packages web)
+ #:use-module (ice-9 match)
+ #:use-module ((srfi srfi-1) #:select (delete-duplicates)))
+
+(define-public nginx-mod-accept-language
+ (let ((commit "2f69842f83dac77f7d98b41a2b31b13b87aeaba7")
+ (revision "1"))
+ (package
+ (name "nginx-mod-accept-language")
+ (version (git-version "0.0.0" ;upstream has no version number
+ revision commit))
+ (source
+ (origin
+ (method git-fetch)
+ (uri (git-reference
+ (url "https://github.com/giom/nginx_accept_language_module.git")
+ (commit commit)))
+ (file-name (git-file-name name version))
+ (sha256
+ (base32 "1hjysrl15kh5233w7apq298cc2bp4q1z5mvaqcka9pdl90m0vhbw"))
+ (modules '((guix build utils)
+ (ice-9 popen)))
+ (snippet
+ #~(begin
+ ;; the nginx source code is part of the module’s source
+ (format #t "decompressing nginx source code~%")
+ (call-with-output-file "nginx.tar"
+ (lambda (out)
+ (let ((pipe (open-pipe* OPEN_READ
+ #+(file-append gzip "/bin/gzip") "-cd"
+ #$(package-source nginx))))
+ (dump-port pipe out)
+ (unless (= (status:exit-val (close-pipe pipe)) 0)
+ (error "gzip decompress failed")))))
+ (invoke #+(file-append tar "/bin/tar") "xvf" "nginx.tar"
+ "--strip-components=1")
+ (delete-file "nginx.tar")
+ #t))))
+ (build-system gnu-build-system)
+ (inputs `(("openssl" ,openssl)
+ ("pcre" ,pcre)
+ ("zlib" ,zlib)))
+ (arguments
+ `(#:tests? #f ; no test target
+ #:make-flags (list "modules")
+ #:modules ((guix build utils)
+ (guix build gnu-build-system)
+ (ice-9 regex)
+ (ice-9 textual-ports))
+ #:phases
+ (modify-phases %standard-phases
+ (add-after 'unpack 'convert-to-dynamic-module
+ (lambda _
+ (begin
+ (with-atomic-file-replacement "config"
+ (lambda (in out)
+ ;; cf. https://www.nginx.com/resources/wiki/extending/new_config/
+ (format out "ngx_module_type=HTTP~%")
+ (format out "ngx_module_name=\
+ngx_http_accept_language_module~%")
+ (let* ((str (get-string-all in))
+ (rx (make-regexp
+ "NGX_ADDON_SRCS=\"\\$NGX_ADDON_SRCS (.*)\""))
+ (m (regexp-exec rx str))
+ (srcs (match:substring m 1)))
+ (format out (string-append "ngx_module_srcs=\""
+ srcs "\"~%")))
+ (format out ". auto/module~%")
+ (format out "ngx_addon_name=$ngx_module_name~%"))))))
+ (add-before 'configure 'patch-/bin/sh
+ (lambda _
+ (substitute* "auto/feature"
+ (("/bin/sh") (which "sh")))
+ #t))
+ (replace 'configure
+ (lambda* (#:key outputs #:allow-other-keys)
+ (let ((flags
+ (list ;; A copy of nginx’ flags follows, otherwise we
+ ;; get a binary compatibility error. FIXME: Code
+ ;; duplication is bad.
+ (string-append "--prefix=" (assoc-ref outputs "out"))
+ "--with-http_ssl_module"
+ "--with-http_v2_module"
+ "--with-pcre-jit"
+ "--with-debug"
+ ;; Even when not cross-building, we pass the
+ ;; --crossbuild option to avoid customizing for the
+ ;; kernel version on the build machine.
+ ,(let ((system "Linux") ; uname -s
+ (release "3.2.0") ; uname -r
+ ;; uname -m
+ (machine (match (or (%current-target-system)
+ (%current-system))
+ ("x86_64-linux" "x86_64")
+ ("i686-linux" "i686")
+ ("mips64el-linux" "mips64")
+ ;; Prevent errors when querying
+ ;; this package on unsupported
+ ;; platforms, e.g. when running
+ ;; "guix package --search="
+ (_ "UNSUPPORTED"))))
+ (string-append "--crossbuild="
+ system ":" release ":" machine))
+ ;; The following are the args decribed on
+ ;; .
+ ;; Enabling --with-compat here and in the nginx package
+ ;; would ensure binary compatibility even when using
+ ;; different configure options from the main nginx
+ ;; package. This is not needed for Guix.
+ ;; "--with-compat"
+ "--add-dynamic-module=.")))
+ (setenv "CC" "gcc")
+ (format #t "environment variable `CC' set to `gcc'~%")
+ (format #t "configure flags: ~s~%" flags)
+ (apply invoke "./configure" flags)
+ #t)))
+ (replace 'install
+ (lambda* (#:key outputs #:allow-other-keys)
+ (let* ((out (assoc-ref outputs "out"))
+ (modules-dir (string-append out "/etc/nginx/modules"))
+ (doc-dir (string-append
+ out "/share/doc/nginx-mod-accept-language")))
+ (mkdir-p modules-dir)
+ (copy-file "objs/ngx_http_accept_language_module.so"
+ (string-append
+ modules-dir "/ngx_http_accept_language_module.so"))
+ (mkdir-p doc-dir)
+ (copy-file "README.textile"
+ (string-append doc-dir "/README.textile"))
+ #t))))))
+ (home-page
+ "https://www.nginx.com/resources/wiki/modules/accept_language/")
+ (synopsis "Nginx module for parsing the Accept-Language HTTP header")
+ (description
+ "Nginx module that parses the Accept-Language field in HTTP headers and
+chooses the most suitable locale for the user from the list of locales
+supported at your website.")
+ (license (delete-duplicates
+ (cons license:bsd-2 ;license of nginx-mod-accept-language
+ (package-license nginx))))))) ;the module’s code is linked
+ ;statically with nginx, therefore
+ ;nginx’ licenses apply to its binary
--
2.23.0