···
cfg = config.services.couchdb;
opt = options.services.couchdb;
+
database_dir = cfg.databaseDir;
+
uri_file = cfg.uriFile;
+
view_index_dir = cfg.viewIndexDir;
+
bind_address = cfg.bindAddress;
+
adminConfig = lib.optionalAttrs (cfg.adminPass != null) {
+
"${cfg.adminUser}" = cfg.adminPass;
+
appConfig = lib.recursiveUpdate (lib.recursiveUpdate baseConfig adminConfig) cfg.extraConfig;
+
optionsConfigFile = pkgs.writeText "couchdb.ini" (lib.generators.toINI { } appConfig);
+
# we are actually specifying 5 configuration files:
+
# 1. the preinstalled default.ini
+
# 2. the module configuration
+
# 3. the extraConfigFiles from the module options
+
# 4. the locally writable config file, which couchdb itself writes to
+
"${cfg.package}/etc/default.ini"
+
] ++ cfg.extraConfigFiles ++ [ cfg.configFile ];
+
executable = "${cfg.package}/bin/couchdb";
enable = lib.mkEnableOption "CouchDB Server";
package = lib.mkPackageOption pkgs "couchdb3" { };
···
extraConfig = lib.mkOption {
+
type = lib.types.attrs;
+
description = "Extra configuration options for CouchDB";
+
extraConfigFiles = lib.mkOption {
+
type = lib.types.listOf lib.types.path;
+
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 {
+
default = "/var/lib/couchdb/local.ini";
Configuration file for persisting runtime changes. File
needs to be readable and writable from couchdb user/group.
+
config = lib.mkIf cfg.enable {
environment.systemPackages = [ cfg.package ];
systemd.tmpfiles.rules = [
"d '${dirOf cfg.uriFile}' - ${cfg.user} ${cfg.group} - -"
···
+
ERL_FLAGS = ''-couch_ini ${lib.concatStringsSep " " configFiles}'';
+
COUCHDB_ARGS_FILE = ''${cfg.argsFile}'';
+
HOME = ''${cfg.databaseDir}'';
···
users.groups.couchdb.gid = config.ids.gids.couchdb;