summary refs log tree commit diff
path: root/nixos/modules/services
diff options
context:
space:
mode:
authorDaiderd Jordan <daiderd@gmail.com>2017-03-16 22:03:32 +0100
committerGitHub <noreply@github.com>2017-03-16 22:03:32 +0100
commit00ed0f792e9e69600c658a712e0aa88c442ba4e9 (patch)
treed14556327f00887d758990b4374fc0a6fc6ae7d7 /nixos/modules/services
parentf940d9f1fce568aaed15c86b54a5100c556d85a5 (diff)
parentf40b96137844fe474f9c7d73272313a3848b4ee5 (diff)
downloadnixlib-00ed0f792e9e69600c658a712e0aa88c442ba4e9.tar
nixlib-00ed0f792e9e69600c658a712e0aa88c442ba4e9.tar.gz
nixlib-00ed0f792e9e69600c658a712e0aa88c442ba4e9.tar.bz2
nixlib-00ed0f792e9e69600c658a712e0aa88c442ba4e9.tar.lz
nixlib-00ed0f792e9e69600c658a712e0aa88c442ba4e9.tar.xz
nixlib-00ed0f792e9e69600c658a712e0aa88c442ba4e9.tar.zst
nixlib-00ed0f792e9e69600c658a712e0aa88c442ba4e9.zip
Merge pull request #22897 from timor/couchdb-2.0.0
couchdb: add support for version 2.0.0
Diffstat (limited to 'nixos/modules/services')
-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 d4d231456c52..52247bfb983e 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;
       };
     };