···
1
-
{ config, options, lib, pkgs, ... }:
cfg = config.services.couchdb;
opt = options.services.couchdb;
5
-
configFile = pkgs.writeText "couchdb.ini" (
8
-
database_dir = ${cfg.databaseDir}
9
-
uri_file = ${cfg.uriFile}
10
-
view_index_dir = ${cfg.viewIndexDir}
11
-
'' + (lib.optionalString (cfg.adminPass != null) ''
13
-
${cfg.adminUser} = ${cfg.adminPass}
18
-
port = ${toString cfg.port}
19
-
bind_address = ${cfg.bindAddress}
22
-
file = ${cfg.logFile}
24
-
executable = "${cfg.package}/bin/couchdb";
14
+
database_dir = cfg.databaseDir;
15
+
uri_file = cfg.uriFile;
16
+
view_index_dir = cfg.viewIndexDir;
20
+
bind_address = cfg.bindAddress;
26
+
adminConfig = lib.optionalAttrs (cfg.adminPass != null) {
28
+
"${cfg.adminUser}" = cfg.adminPass;
31
+
appConfig = lib.recursiveUpdate (lib.recursiveUpdate baseConfig adminConfig) cfg.extraConfig;
33
+
optionsConfigFile = pkgs.writeText "couchdb.ini" (lib.generators.toINI { } appConfig);
35
+
# we are actually specifying 5 configuration files:
36
+
# 1. the preinstalled default.ini
37
+
# 2. the module configuration
38
+
# 3. the extraConfigFiles from the module options
39
+
# 4. the locally writable config file, which couchdb itself writes to
41
+
"${cfg.package}/etc/default.ini"
43
+
] ++ cfg.extraConfigFiles ++ [ cfg.configFile ];
44
+
executable = "${cfg.package}/bin/couchdb";
enable = lib.mkEnableOption "CouchDB Server";
package = lib.mkPackageOption pkgs "couchdb3" { };
···
extraConfig = lib.mkOption {
131
-
type = lib.types.lines;
148
+
type = lib.types.attrs;
150
+
description = "Extra configuration options for CouchDB";
152
+
extraConfigFiles = lib.mkOption {
153
+
type = lib.types.listOf lib.types.path;
134
-
Extra configuration. Overrides any other configuration.
156
+
Extra configuration files. Overrides any other configuration. You can use this to setup the Admin user without putting the password in your nix store.
···
configFile = lib.mkOption {
171
+
default = "/var/lib/couchdb/local.ini";
Configuration file for persisting runtime changes. File
needs to be readable and writable from couchdb user/group.
161
-
config = lib.mkIf config.services.couchdb.enable {
182
+
config = lib.mkIf cfg.enable {
environment.systemPackages = [ cfg.package ];
165
-
services.couchdb.configFile = lib.mkDefault "/var/lib/couchdb/local.ini";
systemd.tmpfiles.rules = [
"d '${dirOf cfg.uriFile}' - ${cfg.user} ${cfg.group} - -"
···
188
-
# we are actually specifying 5 configuration files:
189
-
# 1. the preinstalled default.ini
190
-
# 2. the module configuration
191
-
# 3. the extraConfig from the module options
192
-
# 4. the locally writable config file, which couchdb itself writes to
193
-
ERL_FLAGS= ''-couch_ini ${cfg.package}/etc/default.ini ${configFile} ${pkgs.writeText "couchdb-extra.ini" cfg.extraConfig} ${cfg.configFile}'';
206
+
ERL_FLAGS = ''-couch_ini ${lib.concatStringsSep " " configFiles}'';
195
-
COUCHDB_ARGS_FILE=''${cfg.argsFile}'';
196
-
HOME =''${cfg.databaseDir}'';
208
+
COUCHDB_ARGS_FILE = ''${cfg.argsFile}'';
209
+
HOME = ''${cfg.databaseDir}'';
···
users.groups.couchdb.gid = config.ids.gids.couchdb;