summary refs log tree commit diff
path: root/nixos/modules/services/databases/couchdb.nix
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 /nixos/modules/services/databases/couchdb.nix
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.
Diffstat (limited to 'nixos/modules/services/databases/couchdb.nix')
-rw-r--r--nixos/modules/services/databases/couchdb.nix30
1 files changed, 25 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;
       };
     };