summary refs log tree commit diff
diff options
context:
space:
mode:
authortimor <timor.dd@googlemail.com>2017-02-10 12:50:28 +0100
committertimor <timor.dd@googlemail.com>2017-03-06 11:42:02 +0100
commitf40b96137844fe474f9c7d73272313a3848b4ee5 (patch)
treee6c1916660954f2750fb5df50e0a0d176c1ac105
parent834de6ebaaa0af9044ae79bd2e8e3e18d0eb55c3 (diff)
downloadnixpkgs-f40b96137844fe474f9c7d73272313a3848b4ee5.tar
nixpkgs-f40b96137844fe474f9c7d73272313a3848b4ee5.tar.gz
nixpkgs-f40b96137844fe474f9c7d73272313a3848b4ee5.tar.bz2
nixpkgs-f40b96137844fe474f9c7d73272313a3848b4ee5.tar.lz
nixpkgs-f40b96137844fe474f9c7d73272313a3848b4ee5.tar.xz
nixpkgs-f40b96137844fe474f9c7d73272313a3848b4ee5.tar.zst
nixpkgs-f40b96137844fe474f9c7d73272313a3848b4ee5.zip
couchdb: add support for version 2.0.0
Version 2.0.0 is installed as a separate package called "couchdb2".
When setting the config option "package" attribute to pkgs.couchdb2, a
corresponding service configuration will be generated.  If a previous
1.6 installation exists, the databases can still be found on the local
port (default: 5986) and can be replicated from there.

Note that single-node or cluster setup still needs to be configured
manually, as described in
http://docs.couchdb.org/en/2.0.0/install/index.html.
-rw-r--r--nixos/modules/services/databases/couchdb.nix30
-rw-r--r--pkgs/servers/http/couchdb/2.0.0.nix53
-rw-r--r--pkgs/servers/http/couchdb/jsapi.patch60
-rw-r--r--pkgs/top-level/all-packages.nix4
4 files changed, 142 insertions, 5 deletions
diff --git a/nixos/modules/services/databases/couchdb.nix b/nixos/modules/services/databases/couchdb.nix
index d4d231456c5..52247bfb983 100644
--- a/nixos/modules/services/databases/couchdb.nix
+++ b/nixos/modules/services/databases/couchdb.nix
@@ -4,20 +4,29 @@ with lib;
 
 let
   cfg = config.services.couchdb;
-  configFile = pkgs.writeText "couchdb.ini"
+  useVersion2 = strings.versionAtLeast (strings.getVersion cfg.package) "2.0";
+  configFile = pkgs.writeText "couchdb.ini" (
     ''
       [couchdb]
       database_dir = ${cfg.databaseDir}
       uri_file = ${cfg.uriFile}
       view_index_dir = ${cfg.viewIndexDir}
-
+    '' + (if useVersion2 then
+    ''
+      [chttpd]
+    '' else
+    ''
       [httpd]
+    '') +
+    ''
       port = ${toString cfg.port}
       bind_address = ${cfg.bindAddress}
 
       [log]
       file = ${cfg.logFile}
-    '';
+    '');
+  executable = if useVersion2 then "${cfg.package}/bin/couchdb"
+    else ''${cfg.package}/bin/couchdb -a ${configFile} -a ${pkgs.writeText "couchdb-extra.ini" cfg.extraConfig} -a ${cfg.configFile}'';
 
 in {
 
@@ -130,7 +139,6 @@ in {
 
       configFile = mkOption {
         type = types.string;
-        default = "/var/lib/couchdb/couchdb.ini";
         description = ''
           Configuration file for persisting runtime changes. File
           needs to be readable and writable from couchdb user/group.
@@ -147,6 +155,9 @@ in {
 
     environment.systemPackages = [ cfg.package ];
 
+    services.couchdb.configFile = mkDefault
+      (if useVersion2 then "/var/lib/couchdb/local.ini" else "/var/lib/couchdb/couchdb.ini");
+
     systemd.services.couchdb = {
       description = "CouchDB Server";
       wantedBy = [ "multi-user.target" ];
@@ -170,11 +181,20 @@ in {
         fi
         '';
 
+      environment = mkIf useVersion2 {
+        # we are actually specifying 4 configuration files:
+        # 1. the preinstalled default.ini
+        # 2. the module configuration
+        # 3. the extraConfig from the module options
+        # 4. the locally writable config file, which couchdb itself writes to
+        ERL_FLAGS= ''-couch_ini ${cfg.package}/etc/default.ini ${configFile} ${pkgs.writeText "couchdb-extra.ini" cfg.extraConfig} ${cfg.configFile}'';
+      };
+
       serviceConfig = {
         PermissionsStartOnly = true;
         User = cfg.user;
         Group = cfg.group;
-        ExecStart = "${cfg.package}/bin/couchdb -a ${configFile} -a ${pkgs.writeText "couchdb-extra.ini" cfg.extraConfig} -a ${cfg.configFile}";
+        ExecStart = executable;
       };
     };
 
diff --git a/pkgs/servers/http/couchdb/2.0.0.nix b/pkgs/servers/http/couchdb/2.0.0.nix
new file mode 100644
index 00000000000..0481ebb9b8d
--- /dev/null
+++ b/pkgs/servers/http/couchdb/2.0.0.nix
@@ -0,0 +1,53 @@
+{ stdenv, fetchurl, erlang, icu, openssl, spidermonkey
+, coreutils, bash, makeWrapper }:
+
+stdenv.mkDerivation rec {
+  name = "couchdb-${version}";
+  version = "2.0.0";
+
+  src = fetchurl {
+    url = "mirror://apache/couchdb/source/${version}/apache-${name}.tar.gz";
+    sha256 = "1jkfx6g9anrgmkhrkcn50axcamragranwsciw1rhmi86rglkrbyc";
+  };
+
+  buildInputs = [ erlang icu openssl spidermonkey makeWrapper ];
+
+  patches = [ ./jsapi.patch ];
+  postPatch = ''
+    substituteInPlace src/couch/rebar.config.script --replace '-DHAVE_CURL -I/usr/local/include' "-DHAVE_CURL -I/usr/local/include $NIX_CFLAGS_COMPILE"
+
+    patch bin/rebar <<EOF
+    1c1
+    < #!/usr/bin/env escript
+    ---
+    > #!${coreutils}/bin/env escript
+    EOF
+
+  '';
+
+  # Configure a username.  The build system would use "couchdb" as
+  # default if none is provided.  Note that it is unclear where this
+  # username is actually used in the build, as any choice seems to be
+  # working.
+  configurePhase = ''
+    ./configure -u nobody
+  '';
+
+  buildPhase = ''
+    make release
+  '';
+
+  installPhase = ''
+    mkdir -p $out
+    cp -r rel/couchdb/* $out
+    wrapProgram $out/bin/couchdb --suffix PATH : ${bash}/bin
+  '';
+
+  meta = with stdenv.lib; {
+    description = "A database that uses JSON for documents, JavaScript for MapReduce queries, and regular HTTP for an API";
+    homepage = "http://couchdb.apache.org";
+    license = licenses.asl20;
+    platforms = platforms.all;
+    maintainers = with maintainers; [ garbas ];
+  };
+}
diff --git a/pkgs/servers/http/couchdb/jsapi.patch b/pkgs/servers/http/couchdb/jsapi.patch
new file mode 100644
index 00000000000..bb7d4ca610c
--- /dev/null
+++ b/pkgs/servers/http/couchdb/jsapi.patch
@@ -0,0 +1,60 @@
+diff -ru couch_js/http.c couch_js-patched/http.c
+--- apache-couchdb-2.0.0/src/couch/priv/couch_js/http.c	2016-09-12 11:28:51.000000000 +0200
++++ apache-couchdb-2.0.0-patched/src/couch/priv/couch_js/http.c	2017-02-10 10:52:33.025854045 +0100
+@@ -15,7 +15,7 @@
+ #include <string.h>
+ #include <sys/types.h>
+ #include <sys/stat.h>
+-#include <jsapi.h>
++#include <js/jsapi.h>
+ #include "config.h"
+ #include "utf8.h"
+ #include "util.h"
+diff -ru couch_js/main.c couch_js-patched/main.c
+--- apache-couchdb-2.0.0/src/couch/priv/couch_js/main.c	2016-09-12 11:28:51.000000000 +0200
++++ apache-couchdb-2.0.0-patched/src/couch/priv/couch_js/main.c	2017-02-10 10:52:33.001854154 +0100
+@@ -20,7 +20,7 @@
+ #include <unistd.h>
+ #endif
+ 
+-#include <jsapi.h>
++#include <js/jsapi.h>
+ #include "config.h"
+ #include "http.h"
+ #include "utf8.h"
+diff -ru couch_js/utf8.c couch_js-patched/utf8.c
+--- apache-couchdb-2.0.0/src/couch/priv/couch_js/utf8.c	2016-09-12 11:28:51.000000000 +0200
++++ apache-couchdb-2.0.0-patched/src/couch/priv/couch_js/utf8.c	2017-02-10 10:52:33.009854117 +0100
+@@ -10,7 +10,7 @@
+ // License for the specific language governing permissions and limitations under
+ // the License.
+ 
+-#include <jsapi.h>
++#include <js/jsapi.h>
+ #include "config.h"
+ 
+ static int
+diff -ru couch_js/util.c couch_js-patched/util.c
+--- apache-couchdb-2.0.0/src/couch/priv/couch_js/util.c	2016-09-12 11:28:51.000000000 +0200
++++ apache-couchdb-2.0.0-patched/src/couch/priv/couch_js/util.c	2017-02-10 10:52:33.017854081 +0100
+@@ -13,7 +13,7 @@
+ #include <stdlib.h>
+ #include <string.h>
+ 
+-#include <jsapi.h>
++#include <js/jsapi.h>
+ 
+ #include "help.h"
+ #include "util.h"
+diff -ru couch_js/util.h couch_js-patched/util.h
+--- apache-couchdb-2.0.0/src/couch/priv/couch_js/util.h	2016-09-12 11:28:51.000000000 +0200
++++ apache-couchdb-2.0.0-patched/src/couch/priv/couch_js/util.h	2017-02-10 10:52:32.988854212 +0100
+@@ -13,7 +13,7 @@
+ #ifndef COUCHJS_UTIL_H
+ #define COUCHJS_UTIL_H
+ 
+-#include <jsapi.h>
++#include <js/jsapi.h>
+ 
+ typedef struct {
+     int          no_eval;
diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix
index 079f3220015..36f98de5a51 100644
--- a/pkgs/top-level/all-packages.nix
+++ b/pkgs/top-level/all-packages.nix
@@ -10287,6 +10287,10 @@ with pkgs;
     erlang = erlangR16;
   };
 
+  couchdb2 = callPackage ../servers/http/couchdb/2.0.0.nix {
+    spidermonkey = spidermonkey_1_8_5;
+  };
+
   couchpotato = callPackage ../servers/couchpotato {};
 
   dico = callPackage ../servers/dico { };