From f40b96137844fe474f9c7d73272313a3848b4ee5 Mon Sep 17 00:00:00 2001 From: timor Date: Fri, 10 Feb 2017 12:50:28 +0100 Subject: 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. --- nixos/modules/services/databases/couchdb.nix | 30 +++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) (limited to 'nixos') 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; }; }; -- cgit 1.4.1