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.
This commit is contained in:
@@ -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;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user