Subject: Add couchdb

From: Lars-Dominik Braun <[email-masked]>
Date: Tue, 3 Mar 2020 10:50:49 +0100

Hi,

these two patches add couchdb. First, an upgrade to erlang is essential, since
our version is quite outdated and has known issues with couchdb. I’m only
bumping to a newer maintenance release of 21.x for now. `guix refresh
--list-dependent` lists only elixir, which builds fine with the new version and
emacs-erlang, build from the same sources, seems to work too.

The second patch adds couchdb. I’ve got almost the entire test suite up and
running. It is very extensive and takes a lot of time (compared to
compilation). Some patching is required to unbundle Erlangs ERTS, so an update
to Erlang in the future might break 'install due to the hard-coded version. Any
thoughts?

Future work: Shepherd service.

Cheers,
Lars

>From c30c7d3ff91b8a442b48249af37dc05954fbb486 Mon Sep 17 00:00:00 2001
From: Lars-Dominik Braun <[email-masked]>
Date: Tue, 3 Mar 2020 09:41:08 +0100
Subject: [PATCH 1/2] gnu: erlang: Update to 21.3.8.13

* gnu/packages/erlang.scm (erlang): Update to 21.3.8.13
---
 gnu/packages/erlang.scm | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/gnu/packages/erlang.scm b/gnu/packages/erlang.scm
index 4e12bb4813..865895da78 100644
--- a/gnu/packages/erlang.scm
+++ b/gnu/packages/erlang.scm
@@ -40,7 +40,7 @@
 (define-public erlang
   (package
     (name "erlang")
-    (version "21.0.5")
+    (version "21.3.8.13")
     (source (origin
               (method git-fetch)
               ;; The tarball from http://erlang.org/download contains many
@@ -52,7 +52,7 @@
               (file-name (git-file-name name version))
               (sha256
                (base32
-                "0gv83i5ybj1z3ykbbldjzf7dbfjszp84c0yzrpshj611b9wp0176"))
+                "1dj37vk712dx76y25g13na24wbpn7a5ddmlpf4n51gm10sib54wj"))
               (patches (search-patches "erlang-man-path.patch"))))
     (build-system gnu-build-system)
     (native-inputs
@@ -68,7 +68,7 @@
                                (version-major+minor version) ".tar.gz"))
            (sha256
             (base32
-             "0cgv23q0215f6lvmhj4w9skx5m29khjs9mb890635s3yp520xgqh"))))))
+             "0wm1dg1psv1n3gpiwyms06yhsryrnr28p455fp0l1ak8hdf4nipm"))))))
     (inputs
      `(("ncurses" ,ncurses)
        ("openssl" ,openssl)
-- 
2.20.1

>From e3df880d9aa5cbdc983c1a5497cde536f1a13fe6 Mon Sep 17 00:00:00 2001
From: Lars-Dominik Braun <[email-masked]>
Date: Tue, 3 Mar 2020 10:38:40 +0100
Subject: [PATCH 2/2] gnu: Add couchdb

* gnu/packages/databases.scm (couchdb): New variable
---
 gnu/packages/databases.scm | 93 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 93 insertions(+)

diff --git a/gnu/packages/databases.scm b/gnu/packages/databases.scm
index d4891841e4..a4ccb599f6 100644
--- a/gnu/packages/databases.scm
+++ b/gnu/packages/databases.scm
@@ -74,14 +74,17 @@
   #:use-module (gnu packages cyrus-sasl)
   #:use-module (gnu packages dbm)
   #:use-module (gnu packages emacs)
+  #:use-module (gnu packages erlang)
   #:use-module (gnu packages flex)
   #:use-module (gnu packages gcc)
   #:use-module (gnu packages gettext)
   #:use-module (gnu packages glib)
   #:use-module (gnu packages gnupg)
+  #:use-module (gnu packages gnuzilla)
   #:use-module (gnu packages guile)
   #:use-module (gnu packages time)
   #:use-module (gnu packages golang)
+  #:use-module (gnu packages icu4c)
   #:use-module (gnu packages jemalloc)
   #:use-module (gnu packages language)
   #:use-module (gnu packages libevent)
@@ -3368,3 +3371,93 @@ The drivers officially supported by @code{libdbi} are:
 @end itemize")
     (home-page "http://libdbi-drivers.sourceforge.net/")
     (license license:lgpl2.1+)))
+
+(define-public couchdb
+  (package
+    (name "couchdb")
+    (version "3.0.0")
+    (source
+     (origin
+       (method url-fetch)
+       (uri (string-append
+             "mirror://apache/couchdb/source/" version
+             "/apache-couchdb-" version ".tar.gz"))
+       (sha256
+        (base32
+         "1nbz2vafzhp9jv8xna8cfnf99jwn22xs4ydzm426qx7yf0dbn2fi"))
+       (modules '((guix build utils)))
+       ;; remove pre-built binary, will be rebuilt
+       (snippet '(begin (delete-file "bin/rebar") #t))))
+    (build-system gnu-build-system)
+    (arguments
+     `(#:phases
+       (modify-phases %standard-phases
+         (add-after 'unpack 'fix-paths
+           (lambda* (#:key inputs #:allow-other-keys)
+             (substitute* "src/couch/rebar.config.script"
+               (("/usr/include/mozjs-60")
+                (string-append (assoc-ref inputs "mozjs") "/include/mozjs-60")))
+             (substitute* "Makefile"
+               ;; disable python-black code formatting
+               (("check: all python-black") "check: all")
+               ;; disable venv creation and package installation
+               (("python3 -m venv .venv") "true")
+               (("\\.venv/bin/python3 -m pip install -r requirements.txt") "true")
+               ;; do not test elixir, depends on `mix` and several external dependencies
+               (("@\\$\\(MAKE\\) elixir") "")
+               ;; use system python
+               (("\\.venv/bin/python3")
+                (string-append (assoc-ref inputs "python") "/bin/python3")))
+             #t))
+         (add-after 'unpack 'set-env
+           (lambda* (#:key inputs #:allow-other-keys)
+             ;; make sure rebar finds a C compiler
+             (setenv "CC" (string-append (assoc-ref inputs "gcc") "/bin/gcc"))
+             #t))
+         (replace 'configure
+           (lambda* (#:key inputs #:allow-other-keys)
+             (invoke "./configure" "--skip-deps" "--spidermonkey-version" "60")
+             #t))
+         (replace 'build
+           (lambda _
+             ;; create a release build
+             (invoke "make" "release")
+             #t))
+         (replace 'install
+           (lambda* (#:key inputs outputs #:allow-other-keys)
+             ;; couchdb tries to bundle erts, use our own copy
+             (let ((erts-version "10.3.5.9"))
+               (delete-file-recursively
+                (string-append "rel/couchdb/erts-" erts-version))
+               (substitute* '("rel/couchdb/bin/couchdb" "rel/couchdb/bin/remsh")
+                 (("ROOTDIR=\\$\\{ERTS_BIN_DIR%/\\*\\}")
+                  (string-append "ROOTDIR=" (assoc-ref outputs "out")))
+                 (("BINDIR=\"[^\"]+\"")
+                  (string-append
+                   "BINDIR=" (assoc-ref inputs "erlang")
+                   "/lib/erlang/erts-" erts-version "/bin")))
+               (copy-recursively "rel/couchdb" (assoc-ref outputs "out")))
+             #t)))))
+    (native-inputs
+     ;; for tests
+     `(("python" ,python)
+       ("python-nose" ,python-nose)
+       ("python-requests" ,python-requests)
+       ("python-hypothesis" ,python-hypothesis)
+       ("curl" ,curl)
+       ;; for documentation
+       ("python-sphinx" ,python-sphinx)))
+    (inputs
+     `(("erlang" ,erlang)
+       ("icu4c" ,icu4c)
+       ("openssl" ,openssl)
+       ("mozjs" ,mozjs-60)))
+    (home-page "https://couchdb.apache.org/")
+    (synopsis "Document-oriented NoSQL database, implemented in Erlang")
+    (description "CouchDB is a database that completely embraces the web.  Store
+your data with JSON documents.  Access your documents with your web browser, via
+HTTP.  Query, combine, and transform your documents with JavaScript.  CouchDB
+works well with modern web and mobile apps.  You can distribute your data,
+efficiently using CouchDB’s incremental replication.  CouchDB supports
+master-master setups with automatic conflict detection.")
+    (license license:asl2.0)))
-- 
2.20.1