unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / Atom feed
* [bug#43933] [PATCH 1/8] gnu: Add lua-resty-core.
  2020-10-11 18:19 [bug#43933] [PATCH 0/8] services: nginx: Add lua module Oleg Pykhalov
@ 2020-10-11 18:30 ` Oleg Pykhalov
  2020-10-11 18:30   ` [bug#43933] [PATCH 3/8] gnu: Add lua-resty-signal Oleg Pykhalov
                     ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Oleg Pykhalov @ 2020-10-11 18:30 UTC (permalink / raw)
  To: 43933; +Cc: Oleg Pykhalov

* gnu/packages/lua.scm (lua-resty-core): New variable.
---
 gnu/packages/lua.scm | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)

diff --git a/gnu/packages/lua.scm b/gnu/packages/lua.scm
index 5479b891bd..774df85170 100644
--- a/gnu/packages/lua.scm
+++ b/gnu/packages/lua.scm
@@ -880,3 +880,40 @@ on numbers.")
      "Selene is a simple C++11 header-only library enabling seamless
  interoperability between C++ and Lua programming language.")
     (license license:zlib)))
+
+(define-public lua-resty-core
+  (package
+    (name "lua-resty-core")
+    (version "0.1.17")
+    (source (origin
+              (method git-fetch)
+              (uri (git-reference
+                    (url "https://github.com/openresty/lua-resty-core")
+                    (commit (string-append "v" version))))
+              (file-name (git-file-name name version))
+              (sha256
+               (base32
+                "11fyli6yrg7b91nv9v2sbrc6y7z3h9lgf4lrrhcjk2bb906576a0"))))
+    (build-system trivial-build-system)
+    (arguments
+     `(#:modules ((guix build utils))
+       #:builder
+       (begin
+         (use-modules (guix build utils))
+         (let* ((luajit-major+minor ,(version-major+minor (package-version lua)))
+                (package-lua-resty (lambda (input output)
+                                     (mkdir-p (string-append output "/lib/lua"))
+                                     (copy-recursively (string-append input "/lib/resty")
+                                                       (string-append output "/lib/lua/resty"))
+                                     (copy-recursively (string-append input "/lib/ngx")
+                                                       (string-append output "/lib/ngx"))
+                                     (symlink (string-append output "/lib/lua/resty")
+                                              (string-append output "/lib/resty")))))
+           (package-lua-resty (assoc-ref %build-inputs "source")
+                              (assoc-ref %outputs "out")))
+         #t)))
+    (home-page "https://github.com/openresty/lua-resty-core")
+    (synopsis "Lua API for NGINX")
+    (description "This package provides a FFI-based Lua API for
+@code{ngx_http_lua_module} or @code{ngx_stream_lua_module}.")
+    (license license:bsd-2)))
-- 
2.28.0





^ permalink raw reply	[flat|nested] 6+ messages in thread

* [bug#43933] [PATCH 3/8] gnu: Add lua-resty-signal.
  2020-10-11 18:30 ` [bug#43933] [PATCH 1/8] gnu: Add lua-resty-core Oleg Pykhalov
@ 2020-10-11 18:30   ` Oleg Pykhalov
  2020-10-11 18:30   ` [bug#43933] [PATCH 4/8] gnu: Add lua-tablepool Oleg Pykhalov
                     ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Oleg Pykhalov @ 2020-10-11 18:30 UTC (permalink / raw)
  To: 43933; +Cc: Oleg Pykhalov

* gnu/packages/lua.scm (lua-resty-signal): New variable.
---
 gnu/packages/lua.scm | 40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)

diff --git a/gnu/packages/lua.scm b/gnu/packages/lua.scm
index 59d449dfe5..60f88c1536 100644
--- a/gnu/packages/lua.scm
+++ b/gnu/packages/lua.scm
@@ -952,3 +952,43 @@ on numbers.")
     (description
      "This package provides Lua LRU cache based on the LuaJIT FFI.")
     (license license:bsd-2)))
+
+(define-public lua-resty-signal
+  (package
+    (name "lua-resty-signal")
+    (version "0.02")
+    (source (origin
+              (method git-fetch)
+              (uri (git-reference
+                    (url "https://github.com/openresty/lua-resty-signal")
+                    (commit (string-append "v" version))))
+              (file-name (git-file-name name version))
+              (sha256
+               (base32
+                "13y1pqn45y49mhqwywasfdsid46d0c33yi6mrnracbnmvyxz1cif"))))
+    (build-system gnu-build-system)
+    (arguments
+     `(#:tests? #f ;TODO: Run the test suite.
+       #:make-flags (list "CC=gcc"
+                          (string-append "PREFIX=" %output))
+       #:phases
+       (modify-phases %standard-phases
+         (delete 'configure)
+         (add-after 'install 'install-lua
+           (lambda* (#:key inputs outputs #:allow-other-keys)
+             (use-modules (guix build utils))
+             (let* ((luajit-major+minor ,(version-major+minor (package-version lua)))
+                    (package-lua-resty (lambda (input output)
+                                         (mkdir-p (string-append output "/lib/lua/" luajit-major+minor))
+                                         (copy-recursively (string-append input "/lib/resty")
+                                                           (string-append output "/lib/lua/" luajit-major+minor  "/resty"))
+                                         (symlink (string-append output "/lib/lua/" luajit-major+minor "/resty")
+                                                  (string-append output "/lib/resty")))))
+               (package-lua-resty (assoc-ref inputs "source")
+                                  (assoc-ref outputs "out")))
+             #t)))))
+    (home-page "https://github.com/openresty/lua-resty-signal")
+    (synopsis "Lua library for killing or sending signals to Linux processes")
+    (description "This package provides Lua library for killing or sending
+signals to Linux processes.")
+    (license license:bsd-3)))
-- 
2.28.0





^ permalink raw reply	[flat|nested] 6+ messages in thread

* [bug#43933] [PATCH 4/8] gnu: Add lua-tablepool.
  2020-10-11 18:30 ` [bug#43933] [PATCH 1/8] gnu: Add lua-resty-core Oleg Pykhalov
  2020-10-11 18:30   ` [bug#43933] [PATCH 3/8] gnu: Add lua-resty-signal Oleg Pykhalov
@ 2020-10-11 18:30   ` Oleg Pykhalov
  2020-10-11 18:30   ` [bug#43933] [PATCH 7/8] gnu: Add nginx-lua-module Oleg Pykhalov
                     ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Oleg Pykhalov @ 2020-10-11 18:30 UTC (permalink / raw)
  To: 43933; +Cc: Oleg Pykhalov

* gnu/packages/lua.scm (lua-tablepool): New variable.
---
 gnu/packages/lua.scm | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/gnu/packages/lua.scm b/gnu/packages/lua.scm
index 60f88c1536..d30692d2df 100644
--- a/gnu/packages/lua.scm
+++ b/gnu/packages/lua.scm
@@ -992,3 +992,35 @@ on numbers.")
     (description "This package provides Lua library for killing or sending
 signals to Linux processes.")
     (license license:bsd-3)))
+
+(define-public lua-tablepool
+  (package
+    (name "lua-tablepool")
+    (version "0.01")
+    (source (origin
+              (method git-fetch)
+              (uri (git-reference
+                    (url "https://github.com/openresty/lua-tablepool")
+                    (commit (string-append "v" version))))
+              (file-name (git-file-name name version))
+              (sha256
+               (base32
+                "03yjj3w6znvj6843prg84m0lkrn49l901f9hj9bgy3cj9s0awl6y"))))
+    (build-system trivial-build-system)
+    (arguments
+     `(#:modules ((guix build utils))
+       #:builder
+       (begin
+         (use-modules (guix build utils))
+         (let* ((luajit-major+minor ,(version-major+minor (package-version lua)))
+                (package-lua-resty (lambda (input output)
+                                     (mkdir-p (string-append output "/lib/lua/" luajit-major+minor))
+                                     (copy-recursively (string-append input "/lib")
+                                                       (string-append output "/lib")))))
+           (package-lua-resty (assoc-ref %build-inputs "source")
+                              (assoc-ref %outputs "out")))
+         #t)))
+    (home-page "https://github.com/openresty/lua-tablepool")
+    (synopsis "Lua table recycling pools for LuaJIT")
+    (description "This package provides Lua table recycling pools for LuaJIT.")
+    (license license:bsd-2)))
-- 
2.28.0





^ permalink raw reply	[flat|nested] 6+ messages in thread

* [bug#43933] [PATCH 7/8] gnu: Add nginx-lua-module.
  2020-10-11 18:30 ` [bug#43933] [PATCH 1/8] gnu: Add lua-resty-core Oleg Pykhalov
  2020-10-11 18:30   ` [bug#43933] [PATCH 3/8] gnu: Add lua-resty-signal Oleg Pykhalov
  2020-10-11 18:30   ` [bug#43933] [PATCH 4/8] gnu: Add lua-tablepool Oleg Pykhalov
@ 2020-10-11 18:30   ` Oleg Pykhalov
  2020-10-11 18:30   ` [bug#43933] [PATCH 8/8] services: nginx: Add lua module Oleg Pykhalov
  2020-10-14 20:43   ` bug#43933: [PATCH 1/8] gnu: Add lua-resty-core Oleg Pykhalov
  4 siblings, 0 replies; 6+ messages in thread
From: Oleg Pykhalov @ 2020-10-11 18:30 UTC (permalink / raw)
  To: 43933; +Cc: Oleg Pykhalov

* gnu/packages/web.scm (nginx-lua-module): New variable.
---
 gnu/packages/web.scm | 63 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 63 insertions(+)

diff --git a/gnu/packages/web.scm b/gnu/packages/web.scm
index f7330aa749..d2177d2229 100644
--- a/gnu/packages/web.scm
+++ b/gnu/packages/web.scm
@@ -560,6 +560,69 @@ documentation.")
        (patches (append (search-patches "nginx-socket-cloexec.patch")
                         (origin-patches (package-source nginx))))))))
 
+(define-public nginx-lua-module
+  (package
+    (inherit nginx)
+    (name "nginx-lua-module")
+    (version "0.10.15")
+    (source
+     (origin
+       (method git-fetch)
+       (uri (git-reference
+             (url "https://github.com/openresty/lua-nginx-module")
+             (commit (string-append "v" version))))
+       (file-name (git-file-name "lua-nginx-module" version))
+       (sha256
+        (base32
+         "1j216isp0546hycklbr5wi8mlga5hq170hk7f2sm16sfavlkh5gz"))))
+    (build-system gnu-build-system)
+    (inputs
+     `(("nginx-sources" ,(package-source nginx-socket-cloexec))
+       ("luajit" ,luajit)
+       ,@(package-inputs nginx)))
+    (arguments
+     (substitute-keyword-arguments
+         `(#:configure-flags '("--add-dynamic-module=.")
+           #:make-flags '("modules")
+           #:modules ((guix build utils)
+                      (guix build gnu-build-system)
+                      (ice-9 popen)
+                      (ice-9 regex)
+                      (ice-9 textual-ports))
+           ,@(package-arguments nginx))
+       ((#:phases phases)
+        `(modify-phases ,phases
+           (add-after 'unpack 'unpack-nginx-sources
+             (lambda* (#:key inputs native-inputs #:allow-other-keys)
+               (begin
+                 ;; The nginx source code is part of the module’s source.
+                 (format #t "decompressing nginx source code~%")
+                 (let ((tar (assoc-ref inputs "tar"))
+                       (nginx-srcs (assoc-ref inputs "nginx-sources")))
+                   (invoke (string-append tar "/bin/tar")
+                           "xvf" nginx-srcs "--strip-components=1"))
+                 #t)))
+           (add-before 'configure 'set-luajit-env
+             (lambda* (#:key inputs #:allow-other-keys)
+               (let ((luajit (assoc-ref inputs "luajit")))
+                 (setenv "LUAJIT_LIB"
+                         (string-append luajit "/lib"))
+                 (setenv "LUAJIT_INC"
+                         (string-append luajit "/include/luajit-2.1"))
+                 #t)))
+           (replace 'install
+             (lambda* (#:key outputs #:allow-other-keys)
+               (let ((modules-dir (string-append (assoc-ref outputs "out") "/etc/nginx/modules")))
+                 (mkdir-p modules-dir)
+                 (copy-file "objs/ngx_http_lua_module.so"
+                            (string-append modules-dir "/ngx_http_lua_module.so"))
+                 #t)))
+           (delete 'fix-root-dirs)
+           (delete 'install-man-page)))))
+    (synopsis "NGINX module for Lua programming language support")
+    (description "This NGINX module provides a scripting support with Lua
+programming language.")))
+
 (define-public lighttpd
   (package
     (name "lighttpd")
-- 
2.28.0





^ permalink raw reply	[flat|nested] 6+ messages in thread

* [bug#43933] [PATCH 8/8] services: nginx: Add lua module.
  2020-10-11 18:30 ` [bug#43933] [PATCH 1/8] gnu: Add lua-resty-core Oleg Pykhalov
                     ` (2 preceding siblings ...)
  2020-10-11 18:30   ` [bug#43933] [PATCH 7/8] gnu: Add nginx-lua-module Oleg Pykhalov
@ 2020-10-11 18:30   ` Oleg Pykhalov
  2020-10-14 20:43   ` bug#43933: [PATCH 1/8] gnu: Add lua-resty-core Oleg Pykhalov
  4 siblings, 0 replies; 6+ messages in thread
From: Oleg Pykhalov @ 2020-10-11 18:30 UTC (permalink / raw)
  To: 43933; +Cc: Oleg Pykhalov

* gnu/services/web.scm (<nginx-configuration>)
[lua-package-path, lua-package-cpath]: New record types.
* gnu/services/web.scm (default-nginx-config): Use them.
* doc/guix.texi (Web Services): Document this.
* doc/guix-cookbook.texi (System Configuration): Document this.
---
 doc/guix-cookbook.texi | 58 ++++++++++++++++++++++++++++++++++++++++++
 doc/guix.texi          | 24 ++++++++++++++++-
 gnu/services/web.scm   | 25 ++++++++++++++----
 3 files changed, 101 insertions(+), 6 deletions(-)

diff --git a/doc/guix-cookbook.texi b/doc/guix-cookbook.texi
index a783c0ae4c..6577c340d9 100644
--- a/doc/guix-cookbook.texi
+++ b/doc/guix-cookbook.texi
@@ -1352,6 +1352,7 @@ reference.
 * Running Guix on a Linode Server:: Running Guix on a Linode Server
 * Setting up a bind mount:: Setting up a bind mount in the file-systems definition.
 * Getting substitutes from Tor:: Configuring Guix daemon to get substitutes through Tor.
+* Setting up NGINX with Lua:: Configuring NGINX web-server to load Lua modules.
 @end menu
 
 @node Customizing the Kernel
@@ -2113,6 +2114,63 @@ sudo herd set-http-proxy guix-daemon http://localhost:9250
 guix build --substitute-urls=https://bp7o7ckwlewr4slm.onion …
 @end example
 
+@node Setting up NGINX with Lua
+@section Setting up NGINX with Lua
+@cindex nginx, lua, openresty, resty
+
+NGINX could be extended with Lua scripts.
+
+Guix provides NGINX service with ability to load Lua module and specific
+Lua packages, and reply to requests by evaluating Lua scripts.
+
+The following example demonstrates system definition with configuration
+to evaluate @file{index.lua} Lua script on HTTP request to
+@uref{http://localhost/hello} endpoint:
+
+@example
+local shell = require "resty.shell"
+
+local stdin = ""
+local timeout = 1000  -- ms
+local max_size = 4096  -- byte
+
+local ok, stdout, stderr, reason, status =
+   shell.run([[/run/current-system/profile/bin/ls /tmp]], stdin, timeout, max_size)
+
+ngx.say(stdout)
+@end example
+
+@lisp
+(use-modules (gnu))
+(use-service-modules #;… web)
+(use-package-modules #;… lua)
+(operating-system
+  ;; …
+  (services
+   ;; …
+   (service nginx-service-type
+            (nginx-configuration
+             (modules
+              (list
+               (file-append nginx-lua-module "/etc/nginx/modules/ngx_http_lua_module.so")))
+             (lua-package-path (list lua-resty-core
+                                     lua-resty-lrucache
+                                     lua-resty-signal
+                                     lua-tablepool
+                                     lua-resty-shell))
+             (lua-package-cpath (list lua-resty-signal))
+             (server-blocks
+              (list (nginx-server-configuration
+                     (server-name '("localhost"))
+                     (listen '("80"))
+                     (root "/etc")
+                     (locations (list
+                                 (nginx-location-configuration
+                                  (uri "/hello")
+                                  (body (list #~(format #f "content_by_lua_file ~s;"
+                                                        #$(local-file "index.lua"))))))))))))))
+@end lisp
+
 @c *********************************************************************
 @node Advanced package management
 @chapter Advanced package management
diff --git a/doc/guix.texi b/doc/guix.texi
index 8514dfe86f..c8e5928590 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -21903,7 +21903,29 @@ names of loadable modules, as in this example:
 (modules
  (list
   (file-append nginx-accept-language-module "\
-/etc/nginx/modules/ngx_http_accept_language_module.so")))
+/etc/nginx/modules/ngx_http_accept_language_module.so")
+  (file-append nginx-lua-module "\
+/etc/nginx/modules/ngx_http_lua_module.so")))
+@end lisp
+
+@item @code{lua-package-path} (default: @code{'()})
+List of nginx lua packages to load.  This should be a list of package
+names of loadable lua modules, as in this example:
+
+@lisp
+(lua-package-path (list lua-resty-core
+                        lua-resty-lrucache
+                        lua-resty-signal
+                        lua-tablepool
+                        lua-resty-shell))
+@end lisp
+
+@item @code{lua-package-cpath} (default: @code{'()})
+List of nginx lua C packages to load.  This should be a list of package
+names of loadable lua C modules, as in this example:
+
+@lisp
+(lua-package-cpath (list lua-resty-signal))
 @end lisp
 
 @item @code{global-directives} (default: @code{'((events . ()))})
diff --git a/gnu/services/web.scm b/gnu/services/web.scm
index c8ffc19d83..d17faa2b59 100644
--- a/gnu/services/web.scm
+++ b/gnu/services/web.scm
@@ -13,6 +13,7 @@
 ;;; Copyright © 2020 Ricardo Wurmus <rekado@elephly.net>
 ;;; Copyright © 2020 Tobias Geerinckx-Rice <me@tobias.gr>
 ;;; Copyright © 2020 Arun Isaac <arunisaac@systemreboot.net>
+;;; Copyright © 2020 Oleg Pykhalov <go.wigust@gmail.com>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -525,6 +526,10 @@
   (modules nginx-configuration-modules (default '()))
   (global-directives nginx-configuration-global-directives
                      (default '((events . ()))))
+  (lua-package-path nginx-lua-package-path ;list of <package>
+                    (default #f))
+  (lua-package-cpath nginx-lua-package-cpath ;list of <package>
+                     (default #f))
   (extra-content nginx-configuration-extra-content
                  (default ""))
   (file          nginx-configuration-file         ;#f | string | file-like
@@ -630,6 +635,8 @@ of index files."
                  server-names-hash-bucket-max-size
                  modules
                  global-directives
+                 lua-package-path
+                 lua-package-cpath
                  extra-content)
    (apply mixed-text-file "nginx.conf"
           (flatten
@@ -646,11 +653,19 @@ of index files."
            "    scgi_temp_path " run-directory "/scgi_temp;\n"
            "    access_log " log-directory "/access.log;\n"
            "    include " nginx "/share/nginx/conf/mime.types;\n"
-           (if server-names-hash-bucket-size
-               (string-append
-                "    server_names_hash_bucket_size "
-                (number->string server-names-hash-bucket-size)
-                ";\n")
+           (if lua-package-path
+               #~(format #f "    lua_package_path ~s;~%"
+                         (string-join (map (lambda (path)
+                                             (string-append path "/lib/?.lua"))
+                                           '#$lua-package-path)
+                                      ";"))
+               "")
+           (if lua-package-cpath
+               #~(format #f "    lua_package_cpath ~s;~%"
+                         (string-join (map (lambda (cpath)
+                                             (string-append cpath "/lib/lua/?.lua"))
+                                           '#$lua-package-cpath)
+                                      ";"))
                "")
            (if server-names-hash-bucket-max-size
                (string-append
-- 
2.28.0





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#43933: [PATCH 1/8] gnu: Add lua-resty-core.
  2020-10-11 18:30 ` [bug#43933] [PATCH 1/8] gnu: Add lua-resty-core Oleg Pykhalov
                     ` (3 preceding siblings ...)
  2020-10-11 18:30   ` [bug#43933] [PATCH 8/8] services: nginx: Add lua module Oleg Pykhalov
@ 2020-10-14 20:43   ` Oleg Pykhalov
  4 siblings, 0 replies; 6+ messages in thread
From: Oleg Pykhalov @ 2020-10-14 20:43 UTC (permalink / raw)
  To: 43933-done

[-- Attachment #1: Type: text/plain, Size: 25 bytes --]

Pushed to master.

Oleg.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 861 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-10-14 20:44 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-11 18:19 [bug#43933] [PATCH 0/8] services: nginx: Add lua module Oleg Pykhalov
2020-10-11 18:30 ` [bug#43933] [PATCH 1/8] gnu: Add lua-resty-core Oleg Pykhalov
2020-10-11 18:30   ` [bug#43933] [PATCH 3/8] gnu: Add lua-resty-signal Oleg Pykhalov
2020-10-11 18:30   ` [bug#43933] [PATCH 4/8] gnu: Add lua-tablepool Oleg Pykhalov
2020-10-11 18:30   ` [bug#43933] [PATCH 7/8] gnu: Add nginx-lua-module Oleg Pykhalov
2020-10-11 18:30   ` [bug#43933] [PATCH 8/8] services: nginx: Add lua module Oleg Pykhalov
2020-10-14 20:43   ` bug#43933: [PATCH 1/8] gnu: Add lua-resty-core Oleg Pykhalov

unofficial mirror of guix-patches@gnu.org 

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://yhetil.org/guix-patches/1 guix-patches/git/1.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 guix-patches guix-patches/ https://yhetil.org/guix-patches \
		guix-patches@gnu.org
	public-inbox-index guix-patches

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://news.yhetil.org/yhetil.gnu.guix.patches


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git