diff mbox

gnu: Add varnish.

Message ID 20161127103416.16251-1-mbakke@fastmail.com
State New
Headers show

Commit Message

Marius Bakke Nov. 27, 2016, 10:34 a.m. UTC
* gnu/packages/web.scm (varnish): New variable.
---
 gnu/packages/web.scm | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 79 insertions(+)

Comments

Ricardo Wurmus Nov. 27, 2016, 3:11 p.m. UTC | #1
Marius Bakke <mbakke@fastmail.com> writes:

> * gnu/packages/web.scm (varnish): New variable.

[…]

> +         (add-after 'install 'wrap-binary
> +           (lambda* (#:key inputs outputs #:allow-other-keys)
> +             (let* ((out (assoc-ref outputs "out"))
> +                    (varnishd (string-append out "/sbin/varnishd"))
> +                    (PATH (string-append (assoc-ref inputs "binutils") "/bin"))
> +                    (LIBRARY_PATH (string-append (assoc-ref inputs "glibc") "/lib")))
> +               ;; Add binutils to PATH so gcc finds the 'as' executable.
> +               (wrap-program varnishd
> +                 `("PATH" ":" prefix (,PATH)))
> +               ;; Without this, we get an error such as "ld: cannot find crti.o"
> +               ;; when compiling VCL.
> +               (wrap-program varnishd
> +                 `("LIBRARY_PATH" ":" prefix (,LIBRARY_PATH)))
> +               #t))))))

What is VCL?  Is it always compiled from scratch at runtime?

> +    (inputs
> +     `(("binutils" ,binutils)
> +       ("gcc" ,gcc)
> +       ("glibc" ,glibc/linux)

These three inputs are implicitly available as native inputs when using
the gnu-build-system.  Should varnish get a gcc-toolchain as a runtime
input instead of these three separate inputs?

> +       ("jemalloc" ,jemalloc)
> +       ("ncurses" ,ncurses)
> +       ("pcre" ,pcre)
> +       ("python" ,python-wrapper)
> +       ("readline" ,readline)))
> +    (home-page "https://www.varnish-cache.org/")
> +    (synopsis "High-performance caching HTTP reverse proxy")
> +    (description
> +     "Varnish is a web application accelerator.  It acts as a caching
> +reverse proxy and load balancer.  You install it in front of any server
> +that speaks HTTP and configure it to cache the contents through an
> +extensive configuration language.")
> +    (license (list l:bsd-2           ; Main distribution.
> +                   l:zlib            ; lib/libvgz/*
> +                   l:public-domain   ; bin/varnishncsa/as64.c, include/miniobj.h
> +                   l:bsd-3           ; include/vqueue.h, lib/libvarnishcompat/daemon.c
> +                   l:expat           ; doc/html/_static/underscore.js
> +                   l:gpl2+))))       ; doc/html/_static/jquery.js is dual MIT/GPL2+

Very nice!
Marius Bakke Nov. 27, 2016, 8:24 p.m. UTC | #2
Ricardo Wurmus <rekado@elephly.net> writes:

>> +         (add-after 'install 'wrap-binary
>> +           (lambda* (#:key inputs outputs #:allow-other-keys)
>> +             (let* ((out (assoc-ref outputs "out"))
>> +                    (varnishd (string-append out "/sbin/varnishd"))
>> +                    (PATH (string-append (assoc-ref inputs "binutils") "/bin"))
>> +                    (LIBRARY_PATH (string-append (assoc-ref inputs "glibc") "/lib")))
>> +               ;; Add binutils to PATH so gcc finds the 'as' executable.
>> +               (wrap-program varnishd
>> +                 `("PATH" ":" prefix (,PATH)))
>> +               ;; Without this, we get an error such as "ld: cannot find crti.o"
>> +               ;; when compiling VCL.
>> +               (wrap-program varnishd
>> +                 `("LIBRARY_PATH" ":" prefix (,LIBRARY_PATH)))
>> +               #t))))))
>
> What is VCL?  Is it always compiled from scratch at runtime?

VCL is the Varnish Configuration Language. The configuration file is
compiled at startup and when loading other configs at runtime. It is
also possible to have inline C code in the VCL.

>
>> +    (inputs
>> +     `(("binutils" ,binutils)
>> +       ("gcc" ,gcc)
>> +       ("glibc" ,glibc/linux)
>
> These three inputs are implicitly available as native inputs when using
> the gnu-build-system.  Should varnish get a gcc-toolchain as a runtime
> input instead of these three separate inputs?

How would this work? Importing (gnu packages commencement) in web.scm
causes a bunch of "unbound variable" errors, probably due to conflicting
package names.

The 'as' requirement is actually from gcc, which should preferably be
compiled with '--with-as=<absolute-path-of-binutils-as>' (but does not
currently have binutils as input). I was surprised it used 'ld', which
probably works as a side effect after wrapping the binutils PATH.

The "LIBRARY_PATH" hack should possibly be fixed in binutils as well.

A custom toolchain sounds like a cleaner approach than these two
workarounds since those quirks can be worked out there, but not sure how
to go about making it.
Ricardo Wurmus Dec. 1, 2016, 9:02 a.m. UTC | #3
Marius Bakke <mbakke@fastmail.com> writes:

> Ricardo Wurmus <rekado@elephly.net> writes:
>
>>> +         (add-after 'install 'wrap-binary
>>> +           (lambda* (#:key inputs outputs #:allow-other-keys)
>>> +             (let* ((out (assoc-ref outputs "out"))
>>> +                    (varnishd (string-append out "/sbin/varnishd"))
>>> +                    (PATH (string-append (assoc-ref inputs "binutils") "/bin"))
>>> +                    (LIBRARY_PATH (string-append (assoc-ref inputs "glibc") "/lib")))
>>> +               ;; Add binutils to PATH so gcc finds the 'as' executable.
>>> +               (wrap-program varnishd
>>> +                 `("PATH" ":" prefix (,PATH)))
>>> +               ;; Without this, we get an error such as "ld: cannot find crti.o"
>>> +               ;; when compiling VCL.
>>> +               (wrap-program varnishd
>>> +                 `("LIBRARY_PATH" ":" prefix (,LIBRARY_PATH)))
>>> +               #t))))))
>>
>> What is VCL?  Is it always compiled from scratch at runtime?
>
> VCL is the Varnish Configuration Language. The configuration file is
> compiled at startup and when loading other configs at runtime. It is
> also possible to have inline C code in the VCL.
>
>>
>>> +    (inputs
>>> +     `(("binutils" ,binutils)
>>> +       ("gcc" ,gcc)
>>> +       ("glibc" ,glibc/linux)
>>
>> These three inputs are implicitly available as native inputs when using
>> the gnu-build-system.  Should varnish get a gcc-toolchain as a runtime
>> input instead of these three separate inputs?
>
> How would this work? Importing (gnu packages commencement) in web.scm
> causes a bunch of "unbound variable" errors, probably due to conflicting
> package names.
>
> The 'as' requirement is actually from gcc, which should preferably be
> compiled with '--with-as=<absolute-path-of-binutils-as>' (but does not
> currently have binutils as input). I was surprised it used 'ld', which
> probably works as a side effect after wrapping the binutils PATH.
>
> The "LIBRARY_PATH" hack should possibly be fixed in binutils as well.
>
> A custom toolchain sounds like a cleaner approach than these two
> workarounds since those quirks can be worked out there, but not sure how
> to go about making it.

Okay, thanks for explaining this.  About the problems with “as” and
“binutils” could you please also send a bug report to bug-guix@gnu.org?
diff mbox

Patch

diff --git a/gnu/packages/web.scm b/gnu/packages/web.scm
index 753a816..b1313ee 100644
--- a/gnu/packages/web.scm
+++ b/gnu/packages/web.scm
@@ -49,6 +49,7 @@ 
   #:use-module (guix build-system python)
   #:use-module (gnu packages)
   #:use-module (gnu packages apr)
+  #:use-module (gnu packages base)
   #:use-module (gnu packages documentation)
   #:use-module (gnu packages docbook)
   #:use-module (gnu packages autotools)
@@ -58,14 +59,17 @@ 
   #:use-module (gnu packages bison)
   #:use-module (gnu packages flex)
   #:use-module (gnu packages mit-krb5)
+  #:use-module (gnu packages gcc)
   #:use-module (gnu packages gd)
   #:use-module (gnu packages gettext)
   #:use-module (gnu packages glib)
   #:use-module (gnu packages gnome)
   #:use-module (gnu packages gperf)
+  #:use-module (gnu packages graphviz)
   #:use-module (gnu packages gtk)
   #:use-module (gnu packages icu4c)
   #:use-module (gnu packages image)
+  #:use-module (gnu packages jemalloc)
   #:use-module (gnu packages lua)
   #:use-module (gnu packages ncurses)
   #:use-module (gnu packages base)
@@ -77,6 +81,7 @@ 
   #:use-module (gnu packages xml)
   #:use-module (gnu packages curl)
   #:use-module (gnu packages perl)
+  #:use-module (gnu packages readline)
   #:use-module (gnu packages texinfo)
   #:use-module (gnu packages textutils)
   #:use-module (gnu packages tls)
@@ -3867,3 +3872,77 @@  useful for users behind restrictive firewalls.  As long as Web traffic is
 allowed, even through a HTTP-only proxy, httptunnel can be combined with other
 tools like SSH (Secure Shell) to reach the outside world.")
     (license l:gpl2+)))
+
+(define-public varnish
+  (package
+    (name "varnish")
+    (version "5.0.0")
+    (source (origin
+              (method url-fetch)
+              (uri (string-append "https://repo.varnish-cache.org/source/varnish-"
+                                  version ".tar.gz"))
+              (sha256
+               (base32
+                "0jizha1mwqk42zmkrh80y07vfl78mg1d9pp5w83qla4xn9ras0ai"))))
+    (build-system gnu-build-system)
+    (arguments
+     `(#:configure-flags (list (string-append "LDFLAGS=-Wl,-rpath=" %output "/lib")
+                               ;; Use absolute path of GCC so it's found at runtime.
+                               (string-append "PTHREAD_CC="
+                                              (assoc-ref %build-inputs "gcc")
+                                              "/bin/gcc")
+                               "--localstatedir=/var")
+       #:phases
+       (modify-phases %standard-phases
+         (add-after 'unpack 'patch-/bin/sh
+           (lambda _
+             (substitute* '("bin/varnishtest/vtc_varnish.c"
+                            "bin/varnishtest/vtc_process.c"
+                            "bin/varnishd/mgt/mgt_vcc.c")
+               (("/bin/sh") (which "sh")))
+             #t))
+         (add-after 'configure 'patch-Makefile
+           (lambda _
+             (substitute* "Makefile"
+               ;; Do not create /var/varnish during install.
+               (("^install-data-am: install-data-local") "install-data-am: "))
+             #t))
+         (add-after 'install 'wrap-binary
+           (lambda* (#:key inputs outputs #:allow-other-keys)
+             (let* ((out (assoc-ref outputs "out"))
+                    (varnishd (string-append out "/sbin/varnishd"))
+                    (PATH (string-append (assoc-ref inputs "binutils") "/bin"))
+                    (LIBRARY_PATH (string-append (assoc-ref inputs "glibc") "/lib")))
+               ;; Add binutils to PATH so gcc finds the 'as' executable.
+               (wrap-program varnishd
+                 `("PATH" ":" prefix (,PATH)))
+               ;; Without this, we get an error such as "ld: cannot find crti.o"
+               ;; when compiling VCL.
+               (wrap-program varnishd
+                 `("LIBRARY_PATH" ":" prefix (,LIBRARY_PATH)))
+               #t))))))
+    (native-inputs
+     `(("pkg-config" ,pkg-config)
+       ("rst2man" ,python-docutils)))
+    (inputs
+     `(("binutils" ,binutils)
+       ("gcc" ,gcc)
+       ("glibc" ,glibc/linux)
+       ("jemalloc" ,jemalloc)
+       ("ncurses" ,ncurses)
+       ("pcre" ,pcre)
+       ("python" ,python-wrapper)
+       ("readline" ,readline)))
+    (home-page "https://www.varnish-cache.org/")
+    (synopsis "High-performance caching HTTP reverse proxy")
+    (description
+     "Varnish is a web application accelerator.  It acts as a caching
+reverse proxy and load balancer.  You install it in front of any server
+that speaks HTTP and configure it to cache the contents through an
+extensive configuration language.")
+    (license (list l:bsd-2           ; Main distribution.
+                   l:zlib            ; lib/libvgz/*
+                   l:public-domain   ; bin/varnishncsa/as64.c, include/miniobj.h
+                   l:bsd-3           ; include/vqueue.h, lib/libvarnishcompat/daemon.c
+                   l:expat           ; doc/html/_static/underscore.js
+                   l:gpl2+))))       ; doc/html/_static/jquery.js is dual MIT/GPL2+