mirror of
https://github.com/ilyakooo0/nixpkgs.git
synced 2024-12-30 23:34:12 +03:00
openldap module: allow defining contents declaratively
This commit is contained in:
parent
cca9ec2a66
commit
aeef7c91f1
@ -7,6 +7,7 @@ let
|
||||
cfg = config.services.openldap;
|
||||
openldap = pkgs.openldap;
|
||||
|
||||
dataFile = pkgs.writeText "ldap-contents.ldif" cfg.declarativeContents;
|
||||
configFile = pkgs.writeText "slapd.conf" cfg.extraConfig;
|
||||
configOpts = if cfg.configDir == null then "-f ${configFile}"
|
||||
else "-F ${cfg.configDir}";
|
||||
@ -82,6 +83,34 @@ in
|
||||
'''
|
||||
'';
|
||||
};
|
||||
|
||||
declarativeContents = mkOption {
|
||||
type = with types; nullOr lines;
|
||||
default = null;
|
||||
description = ''
|
||||
Declarative contents for the LDAP database, in LDIF format.
|
||||
|
||||
Note a few facts when using it. First, the database
|
||||
<emphasis>must</emphasis> be stored in the directory defined by
|
||||
<code>dataDir</code>. Second, all <code>dataDir</code> will be erased
|
||||
when starting the LDAP server. Third, modifications to the database
|
||||
are not prevented, they are just dropped on the next reboot of the
|
||||
server. Finally, performance-wise the database and indexes are rebuilt
|
||||
on each server startup, so this will slow down server startup,
|
||||
especially with large databases.
|
||||
'';
|
||||
example = ''
|
||||
dn: dc=example,dc=org
|
||||
objectClass: domain
|
||||
dc: example
|
||||
|
||||
dn: ou=users,dc=example,dc=org
|
||||
objectClass = organizationalUnit
|
||||
ou: users
|
||||
|
||||
# ...
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
};
|
||||
@ -100,7 +129,13 @@ in
|
||||
preStart = ''
|
||||
mkdir -p /var/run/slapd
|
||||
chown -R "${cfg.user}:${cfg.group}" /var/run/slapd
|
||||
${optionalString (cfg.declarativeContents != null) ''
|
||||
rm -Rf "${cfg.dataDir}"
|
||||
''}
|
||||
mkdir -p "${cfg.dataDir}"
|
||||
${optionalString (cfg.declarativeContents != null) ''
|
||||
${openldap.out}/bin/slapadd ${configOpts} -l ${dataFile}
|
||||
''}
|
||||
chown -R "${cfg.user}:${cfg.group}" "${cfg.dataDir}"
|
||||
'';
|
||||
serviceConfig.ExecStart =
|
||||
|
Loading…
Reference in New Issue
Block a user