2014-04-14 18:26:48 +04:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
2014-01-17 04:30:16 +04:00
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.couchdb;
|
|
|
|
configFile = pkgs.writeText "couchdb.ini"
|
|
|
|
''
|
|
|
|
[couchdb]
|
|
|
|
database_dir = ${cfg.databaseDir}
|
|
|
|
uri_file = ${cfg.uriFile}
|
2014-01-18 22:24:03 +04:00
|
|
|
view_index_dir = ${cfg.viewIndexDir}
|
2014-01-17 04:30:16 +04:00
|
|
|
|
|
|
|
[httpd]
|
|
|
|
port = ${toString cfg.port}
|
|
|
|
bind_address = ${cfg.bindAddress}
|
|
|
|
|
|
|
|
[log]
|
|
|
|
file = ${cfg.logFile}
|
|
|
|
'';
|
|
|
|
|
2014-03-10 14:06:48 +04:00
|
|
|
in {
|
2014-01-17 04:30:16 +04:00
|
|
|
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
services.couchdb = {
|
|
|
|
|
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Whether to run CouchDB Server.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
package = mkOption {
|
2014-02-27 17:33:50 +04:00
|
|
|
type = types.package;
|
2014-01-17 04:30:16 +04:00
|
|
|
default = pkgs.couchdb;
|
|
|
|
example = literalExample "pkgs.couchdb";
|
|
|
|
description = ''
|
|
|
|
CouchDB package to use.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
user = mkOption {
|
|
|
|
type = types.string;
|
|
|
|
default = "couchdb";
|
|
|
|
description = ''
|
|
|
|
User account under which couchdb runs.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
group = mkOption {
|
|
|
|
type = types.string;
|
|
|
|
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 17:33:50 +04:00
|
|
|
type = types.path;
|
2014-01-17 04:30:16 +04: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 17:33:50 +04:00
|
|
|
type = types.path;
|
2014-01-17 04:30:16 +04:00
|
|
|
default = "/var/run/couchdb/couchdb.uri";
|
|
|
|
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 17:33:50 +04:00
|
|
|
type = types.path;
|
2014-01-17 04:30:16 +04: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 {
|
|
|
|
type = types.string;
|
|
|
|
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 17:33:50 +04:00
|
|
|
type = types.path;
|
2014-01-17 04:30:16 +04:00
|
|
|
default = "/var/log/couchdb.log";
|
|
|
|
description = ''
|
|
|
|
Specifies the location of file for logging output.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
extraConfig = mkOption {
|
2014-02-27 17:34:19 +04:00
|
|
|
type = types.lines;
|
2014-01-17 04:30:16 +04:00
|
|
|
default = "";
|
|
|
|
description = ''
|
|
|
|
Extra configuration. Overrides any other cofiguration.
|
|
|
|
'';
|
|
|
|
};
|
2014-06-05 18:12:30 +04:00
|
|
|
|
|
|
|
configFile = mkOption {
|
|
|
|
type = types.string;
|
|
|
|
default = "/var/lib/couchdb/couchdb.ini";
|
|
|
|
description = ''
|
2015-02-10 18:03:38 +03:00
|
|
|
Configuration file for persisting runtime changes. File
|
|
|
|
needs to be readable and writable from couchdb user/group.
|
2014-06-05 18:12:30 +04:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2014-01-17 04:30:16 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config = mkIf config.services.couchdb.enable {
|
|
|
|
|
|
|
|
environment.systemPackages = [ cfg.package ];
|
|
|
|
|
|
|
|
systemd.services.couchdb = {
|
|
|
|
description = "CouchDB Server";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
|
|
|
|
preStart =
|
|
|
|
''
|
2014-02-27 17:34:19 +04:00
|
|
|
mkdir -p `dirname ${cfg.uriFile}`;
|
|
|
|
mkdir -p `dirname ${cfg.logFile}`;
|
|
|
|
mkdir -p ${cfg.databaseDir};
|
|
|
|
mkdir -p ${cfg.viewIndexDir};
|
2014-06-05 18:12:30 +04:00
|
|
|
touch ${cfg.configFile}
|
2015-02-10 18:03:38 +03:00
|
|
|
touch -a ${cfg.logFile}
|
2014-03-10 14:06:48 +04:00
|
|
|
|
|
|
|
if [ "$(id -u)" = 0 ]; then
|
2015-02-10 18:03:38 +03:00
|
|
|
chown ${cfg.user}:${cfg.group} `dirname ${cfg.uriFile}`;
|
|
|
|
(-f ${cfg.uriFile} && chown ${cfg.user}:${cfg.group} ${cfg.uriFile}) || true
|
2014-03-10 14:06:48 +04:00
|
|
|
chown ${cfg.user}:${cfg.group} ${cfg.databaseDir}
|
|
|
|
chown ${cfg.user}:${cfg.group} ${cfg.viewIndexDir}
|
2014-06-05 18:12:30 +04:00
|
|
|
chown ${cfg.user}:${cfg.group} ${cfg.configFile}
|
2015-02-10 18:03:38 +03:00
|
|
|
chown ${cfg.user}:${cfg.group} ${cfg.logFile}
|
2014-03-10 14:06:48 +04:00
|
|
|
fi
|
2014-01-17 04:30:16 +04:00
|
|
|
'';
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
PermissionsStartOnly = true;
|
|
|
|
User = cfg.user;
|
|
|
|
Group = cfg.group;
|
2014-06-05 18:12:30 +04:00
|
|
|
ExecStart = "${cfg.package}/bin/couchdb -a ${configFile} -a ${pkgs.writeText "couchdb-extra.ini" cfg.extraConfig} -a ${cfg.configFile}";
|
2014-01-17 04:30:16 +04:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
users.extraUsers.couchdb = {
|
|
|
|
description = "CouchDB Server user";
|
|
|
|
group = "couchdb";
|
|
|
|
uid = config.ids.uids.couchdb;
|
|
|
|
};
|
|
|
|
|
|
|
|
users.extraGroups.couchdb.gid = config.ids.gids.couchdb;
|
|
|
|
|
|
|
|
};
|
|
|
|
}
|