2014-04-14 16:26:48 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
2014-01-17 01:30:16 +01:00
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.couchdb;
|
2017-02-10 12:50:28 +01:00
|
|
|
useVersion2 = strings.versionAtLeast (strings.getVersion cfg.package) "2.0";
|
|
|
|
configFile = pkgs.writeText "couchdb.ini" (
|
2014-01-17 01:30:16 +01:00
|
|
|
''
|
|
|
|
[couchdb]
|
|
|
|
database_dir = ${cfg.databaseDir}
|
|
|
|
uri_file = ${cfg.uriFile}
|
2014-01-18 19:24:03 +01:00
|
|
|
view_index_dir = ${cfg.viewIndexDir}
|
2017-02-10 12:50:28 +01:00
|
|
|
'' + (if useVersion2 then
|
|
|
|
''
|
|
|
|
[chttpd]
|
|
|
|
'' else
|
|
|
|
''
|
2014-01-17 01:30:16 +01:00
|
|
|
[httpd]
|
2017-02-10 12:50:28 +01:00
|
|
|
'') +
|
|
|
|
''
|
2014-01-17 01:30:16 +01:00
|
|
|
port = ${toString cfg.port}
|
|
|
|
bind_address = ${cfg.bindAddress}
|
|
|
|
|
|
|
|
[log]
|
|
|
|
file = ${cfg.logFile}
|
2017-02-10 12:50:28 +01:00
|
|
|
'');
|
|
|
|
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}'';
|
2014-01-17 01:30:16 +01:00
|
|
|
|
2014-03-10 11:06:48 +01:00
|
|
|
in {
|
2014-01-17 01:30:16 +01:00
|
|
|
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
services.couchdb = {
|
|
|
|
|
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Whether to run CouchDB Server.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
package = mkOption {
|
2014-02-27 14:33:50 +01:00
|
|
|
type = types.package;
|
2014-01-17 01:30:16 +01:00
|
|
|
default = pkgs.couchdb;
|
2016-01-17 19:34:55 +01:00
|
|
|
defaultText = "pkgs.couchdb";
|
2014-01-17 01:30:16 +01:00
|
|
|
example = literalExample "pkgs.couchdb";
|
|
|
|
description = ''
|
|
|
|
CouchDB package to use.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
user = mkOption {
|
2019-08-08 22:48:27 +02:00
|
|
|
type = types.str;
|
2014-01-17 01:30:16 +01:00
|
|
|
default = "couchdb";
|
|
|
|
description = ''
|
|
|
|
User account under which couchdb runs.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
group = mkOption {
|
2019-08-08 22:48:27 +02:00
|
|
|
type = types.str;
|
2014-01-17 01:30:16 +01:00
|
|
|
default = "couchdb";
|
|
|
|
description = ''
|
|
|
|
Group account under which couchdb runs.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
# couchdb options: http://docs.couchdb.org/en/latest/config/index.html
|
|
|
|
|
|
|
|
databaseDir = mkOption {
|
2014-02-27 14:33:50 +01:00
|
|
|
type = types.path;
|
2014-01-17 01:30:16 +01:00
|
|
|
default = "/var/lib/couchdb";
|
|
|
|
description = ''
|
|
|
|
Specifies location of CouchDB database files (*.couch named). This
|
|
|
|
location should be writable and readable for the user the CouchDB
|
|
|
|
service runs as (couchdb by default).
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
uriFile = mkOption {
|
2014-02-27 14:33:50 +01:00
|
|
|
type = types.path;
|
2018-12-19 22:35:41 +01:00
|
|
|
default = "/run/couchdb/couchdb.uri";
|
2014-01-17 01:30:16 +01:00
|
|
|
description = ''
|
|
|
|
This file contains the full URI that can be used to access this
|
|
|
|
instance of CouchDB. It is used to help discover the port CouchDB is
|
|
|
|
running on (if it was set to 0 (e.g. automatically assigned any free
|
|
|
|
one). This file should be writable and readable for the user that
|
|
|
|
runs the CouchDB service (couchdb by default).
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
viewIndexDir = mkOption {
|
2014-02-27 14:33:50 +01:00
|
|
|
type = types.path;
|
2014-01-17 01:30:16 +01:00
|
|
|
default = "/var/lib/couchdb";
|
|
|
|
description = ''
|
|
|
|
Specifies location of CouchDB view index files. This location should
|
|
|
|
be writable and readable for the user that runs the CouchDB service
|
|
|
|
(couchdb by default).
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
bindAddress = mkOption {
|
2019-08-08 22:48:27 +02:00
|
|
|
type = types.str;
|
2014-01-17 01:30:16 +01:00
|
|
|
default = "127.0.0.1";
|
|
|
|
description = ''
|
|
|
|
Defines the IP address by which CouchDB will be accessible.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
port = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 5984;
|
|
|
|
description = ''
|
|
|
|
Defined the port number to listen.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
logFile = mkOption {
|
2014-02-27 14:33:50 +01:00
|
|
|
type = types.path;
|
2014-01-17 01:30:16 +01:00
|
|
|
default = "/var/log/couchdb.log";
|
|
|
|
description = ''
|
|
|
|
Specifies the location of file for logging output.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
extraConfig = mkOption {
|
2014-02-27 14:34:19 +01:00
|
|
|
type = types.lines;
|
2014-01-17 01:30:16 +01:00
|
|
|
default = "";
|
|
|
|
description = ''
|
|
|
|
Extra configuration. Overrides any other cofiguration.
|
|
|
|
'';
|
|
|
|
};
|
2014-06-05 16:12:30 +02:00
|
|
|
|
|
|
|
configFile = mkOption {
|
2019-08-08 22:48:27 +02:00
|
|
|
type = types.path;
|
2014-06-05 16:12:30 +02:00
|
|
|
description = ''
|
2015-02-10 16:03:38 +01:00
|
|
|
Configuration file for persisting runtime changes. File
|
|
|
|
needs to be readable and writable from couchdb user/group.
|
2014-06-05 16:12:30 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2014-01-17 01:30:16 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config = mkIf config.services.couchdb.enable {
|
|
|
|
|
|
|
|
environment.systemPackages = [ cfg.package ];
|
|
|
|
|
2017-02-10 12:50:28 +01:00
|
|
|
services.couchdb.configFile = mkDefault
|
|
|
|
(if useVersion2 then "/var/lib/couchdb/local.ini" else "/var/lib/couchdb/couchdb.ini");
|
|
|
|
|
2019-03-17 18:04:44 +01:00
|
|
|
systemd.tmpfiles.rules = [
|
|
|
|
"d '${dirOf cfg.uriFile}' - ${cfg.user} ${cfg.group} - -"
|
2019-07-24 20:26:22 +02:00
|
|
|
"f '${cfg.logFile}' - ${cfg.user} ${cfg.group} - -"
|
2019-03-17 18:04:44 +01:00
|
|
|
"d '${cfg.databaseDir}' - ${cfg.user} ${cfg.group} - -"
|
|
|
|
"d '${cfg.viewIndexDir}' - ${cfg.user} ${cfg.group} - -"
|
|
|
|
];
|
|
|
|
|
2014-01-17 01:30:16 +01:00
|
|
|
systemd.services.couchdb = {
|
|
|
|
description = "CouchDB Server";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
|
2019-07-24 20:26:22 +02:00
|
|
|
preStart = ''
|
2014-06-05 16:12:30 +02:00
|
|
|
touch ${cfg.configFile}
|
2019-07-24 20:26:22 +02:00
|
|
|
'';
|
2014-01-17 01:30:16 +01:00
|
|
|
|
2017-02-10 12:50:28 +01:00
|
|
|
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}'';
|
|
|
|
};
|
|
|
|
|
2014-01-17 01:30:16 +01:00
|
|
|
serviceConfig = {
|
|
|
|
User = cfg.user;
|
|
|
|
Group = cfg.group;
|
2017-02-10 12:50:28 +01:00
|
|
|
ExecStart = executable;
|
2014-01-17 01:30:16 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2018-06-30 01:58:35 +02:00
|
|
|
users.users.couchdb = {
|
2014-01-17 01:30:16 +01:00
|
|
|
description = "CouchDB Server user";
|
|
|
|
group = "couchdb";
|
|
|
|
uid = config.ids.uids.couchdb;
|
|
|
|
};
|
|
|
|
|
2018-06-30 01:58:35 +02:00
|
|
|
users.groups.couchdb.gid = config.ids.gids.couchdb;
|
2014-01-17 01:30:16 +01:00
|
|
|
|
|
|
|
};
|
|
|
|
}
|