2014-04-14 15:26:48 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
2011-04-13 18:35:19 +01:00
|
|
|
|
2014-04-14 15:26:48 +01:00
|
|
|
with lib;
|
2011-04-13 18:35:19 +01:00
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.services.openldap;
|
|
|
|
openldap = pkgs.openldap;
|
|
|
|
|
|
|
|
configFile = pkgs.writeText "slapd.conf" cfg.extraConfig;
|
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2011-04-13 18:35:19 +01:00
|
|
|
services.openldap = {
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2011-04-13 18:35:19 +01:00
|
|
|
enable = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = "
|
|
|
|
Whether to enable the ldap server.
|
|
|
|
";
|
|
|
|
};
|
|
|
|
|
2013-11-28 21:21:50 +00:00
|
|
|
user = mkOption {
|
|
|
|
default = "openldap";
|
|
|
|
description = "User account under which slapd runs.";
|
|
|
|
};
|
|
|
|
|
|
|
|
group = mkOption {
|
|
|
|
default = "openldap";
|
|
|
|
description = "Group account under which slapd runs.";
|
|
|
|
};
|
|
|
|
|
2011-04-13 18:35:19 +01:00
|
|
|
extraConfig = mkOption {
|
|
|
|
default = "";
|
|
|
|
description = "
|
|
|
|
sldapd.conf configuration
|
|
|
|
";
|
|
|
|
};
|
|
|
|
};
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2011-04-13 18:35:19 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config = mkIf config.services.openldap.enable {
|
|
|
|
|
|
|
|
environment.systemPackages = [ openldap ];
|
|
|
|
|
2013-04-09 16:50:53 +01:00
|
|
|
systemd.services.openldap = {
|
|
|
|
description = "LDAP server";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
after = [ "network.target" ];
|
|
|
|
preStart = ''
|
|
|
|
mkdir -p /var/run/slapd
|
2013-11-28 21:21:50 +00:00
|
|
|
chown -R ${cfg.user}:${cfg.group} /var/run/slapd
|
|
|
|
mkdir -p /var/db/openldap
|
|
|
|
chown -R ${cfg.user}:${cfg.group} /var/db/openldap
|
2013-04-09 16:50:53 +01:00
|
|
|
'';
|
2013-11-28 21:21:50 +00:00
|
|
|
serviceConfig.ExecStart = "${openldap}/libexec/slapd -u openldap -g openldap -d 0 -f ${configFile}";
|
2013-04-09 16:50:53 +01:00
|
|
|
};
|
2011-04-13 18:35:19 +01:00
|
|
|
|
2013-11-28 21:21:50 +00:00
|
|
|
users.extraUsers = optionalAttrs (cfg.user == "openldap") (singleton
|
|
|
|
{ name = "openldap";
|
|
|
|
group = "openldap";
|
|
|
|
uid = config.ids.uids.openldap;
|
|
|
|
});
|
|
|
|
|
|
|
|
users.extraGroups = optionalAttrs (cfg.group == "openldap") (singleton
|
|
|
|
{ name = "openldap";
|
|
|
|
gid = config.ids.gids.openldap;
|
|
|
|
});
|
2011-04-13 18:35:19 +01:00
|
|
|
|
2013-11-28 21:21:50 +00:00
|
|
|
};
|
2011-04-13 18:35:19 +01:00
|
|
|
}
|