2014-04-14 16:26:48 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
2011-04-13 19:35:19 +02:00
|
|
|
|
2014-04-14 16:26:48 +02:00
|
|
|
with lib;
|
2011-04-13 19:35:19 +02:00
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.services.openldap;
|
|
|
|
openldap = pkgs.openldap;
|
|
|
|
|
|
|
|
configFile = pkgs.writeText "slapd.conf" cfg.extraConfig;
|
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2011-04-13 19:35:19 +02:00
|
|
|
services.openldap = {
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2011-04-13 19:35:19 +02:00
|
|
|
enable = mkOption {
|
2015-01-26 09:35:56 +01:00
|
|
|
type = types.bool;
|
2011-04-13 19:35:19 +02:00
|
|
|
default = false;
|
|
|
|
description = "
|
|
|
|
Whether to enable the ldap server.
|
|
|
|
";
|
2015-01-25 21:15:22 +01:00
|
|
|
example = literalExample ''
|
|
|
|
openldap.enable = true;
|
|
|
|
openldap.extraConfig = '''
|
|
|
|
include ''${pkgs.openldap}/etc/openldap/schema/core.schema
|
|
|
|
include ''${pkgs.openldap}/etc/openldap/schema/cosine.schema
|
|
|
|
include ''${pkgs.openldap}/etc/openldap/schema/inetorgperson.schema
|
|
|
|
include ''${pkgs.openldap}/etc/openldap/schema/nis.schema
|
|
|
|
|
|
|
|
database bdb
|
|
|
|
suffix dc=example,dc=org
|
|
|
|
rootdn cn=admin,dc=example,dc=org
|
|
|
|
# NOTE: change after first start
|
|
|
|
rootpw secret
|
2015-01-26 10:03:17 +01:00
|
|
|
directory /var/db/openldap
|
2015-01-25 21:15:22 +01:00
|
|
|
''';
|
|
|
|
'';
|
2011-04-13 19:35:19 +02:00
|
|
|
};
|
|
|
|
|
2013-11-28 22:21:50 +01:00
|
|
|
user = mkOption {
|
2015-01-26 09:35:56 +01:00
|
|
|
type = types.string;
|
2013-11-28 22:21:50 +01:00
|
|
|
default = "openldap";
|
|
|
|
description = "User account under which slapd runs.";
|
|
|
|
};
|
|
|
|
|
|
|
|
group = mkOption {
|
2015-01-26 09:35:56 +01:00
|
|
|
type = types.string;
|
2013-11-28 22:21:50 +01:00
|
|
|
default = "openldap";
|
|
|
|
description = "Group account under which slapd runs.";
|
|
|
|
};
|
|
|
|
|
2015-01-26 09:35:56 +01:00
|
|
|
dataDir = mkOption {
|
|
|
|
type = types.string;
|
|
|
|
default = "/var/db/openldap";
|
|
|
|
description = "The database directory.";
|
|
|
|
};
|
|
|
|
|
2011-04-13 19:35:19 +02:00
|
|
|
extraConfig = mkOption {
|
2015-01-26 09:35:56 +01:00
|
|
|
type = types.lines;
|
2011-04-13 19:35:19 +02:00
|
|
|
default = "";
|
|
|
|
description = "
|
|
|
|
sldapd.conf configuration
|
|
|
|
";
|
|
|
|
};
|
|
|
|
};
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2011-04-13 19:35:19 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config = mkIf config.services.openldap.enable {
|
|
|
|
|
|
|
|
environment.systemPackages = [ openldap ];
|
|
|
|
|
2013-04-09 17:50:53 +02:00
|
|
|
systemd.services.openldap = {
|
|
|
|
description = "LDAP server";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
after = [ "network.target" ];
|
|
|
|
preStart = ''
|
|
|
|
mkdir -p /var/run/slapd
|
2013-11-28 22:21:50 +01:00
|
|
|
chown -R ${cfg.user}:${cfg.group} /var/run/slapd
|
2015-01-26 09:35:56 +01:00
|
|
|
mkdir -p ${cfg.dataDir}
|
|
|
|
chown -R ${cfg.user}:${cfg.group} ${cfg.dataDir}
|
2013-04-09 17:50:53 +02:00
|
|
|
'';
|
2015-01-26 09:35:56 +01:00
|
|
|
serviceConfig.ExecStart = "${openldap}/libexec/slapd -u ${cfg.user} -g ${cfg.group} -d 0 -f ${configFile}";
|
2013-04-09 17:50:53 +02:00
|
|
|
};
|
2011-04-13 19:35:19 +02:00
|
|
|
|
2015-01-26 09:35:56 +01:00
|
|
|
users.extraUsers.openldap =
|
|
|
|
{ name = cfg.user;
|
2014-06-11 11:36:15 +02:00
|
|
|
group = cfg.group;
|
2013-11-28 22:21:50 +01:00
|
|
|
uid = config.ids.uids.openldap;
|
2015-01-26 09:35:56 +01:00
|
|
|
};
|
2013-11-28 22:21:50 +01:00
|
|
|
|
2015-01-26 09:35:56 +01:00
|
|
|
users.extraGroups.openldap =
|
|
|
|
{ name = cfg.group;
|
2013-11-28 22:21:50 +01:00
|
|
|
gid = config.ids.gids.openldap;
|
2015-01-26 09:35:56 +01:00
|
|
|
};
|
2011-04-13 19:35:19 +02:00
|
|
|
|
2013-11-28 22:21:50 +01:00
|
|
|
};
|
2011-04-13 19:35:19 +02:00
|
|
|
}
|