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 {
|
2015-01-26 08:35:56 +00:00
|
|
|
type = types.bool;
|
2011-04-13 18:35:19 +01:00
|
|
|
default = false;
|
|
|
|
description = "
|
|
|
|
Whether to enable the ldap server.
|
|
|
|
";
|
|
|
|
};
|
|
|
|
|
2013-11-28 21:21:50 +00:00
|
|
|
user = mkOption {
|
2015-01-26 08:35:56 +00:00
|
|
|
type = types.string;
|
2013-11-28 21:21:50 +00:00
|
|
|
default = "openldap";
|
|
|
|
description = "User account under which slapd runs.";
|
|
|
|
};
|
|
|
|
|
|
|
|
group = mkOption {
|
2015-01-26 08:35:56 +00:00
|
|
|
type = types.string;
|
2013-11-28 21:21:50 +00:00
|
|
|
default = "openldap";
|
|
|
|
description = "Group account under which slapd runs.";
|
|
|
|
};
|
|
|
|
|
2016-05-21 12:49:14 +01:00
|
|
|
urlList = mkOption {
|
|
|
|
type = types.listOf types.string;
|
|
|
|
default = [ "ldap:///" ];
|
|
|
|
description = "URL list slapd should listen on.";
|
|
|
|
example = [ "ldaps:///" ];
|
|
|
|
};
|
|
|
|
|
2015-01-26 08:35:56 +00:00
|
|
|
dataDir = mkOption {
|
|
|
|
type = types.string;
|
|
|
|
default = "/var/db/openldap";
|
|
|
|
description = "The database directory.";
|
|
|
|
};
|
|
|
|
|
2016-10-06 09:01:38 +01:00
|
|
|
configDir = mkOption {
|
2016-10-23 14:58:37 +01:00
|
|
|
type = types.nullOr types.path;
|
2016-10-23 12:55:23 +01:00
|
|
|
default = null;
|
2016-10-06 09:01:38 +01:00
|
|
|
description = "Use this optional config directory instead of using slapd.conf";
|
|
|
|
example = "/var/db/slapd.d";
|
|
|
|
};
|
|
|
|
|
2011-04-13 18:35:19 +01:00
|
|
|
extraConfig = mkOption {
|
2015-01-26 08:35:56 +00:00
|
|
|
type = types.lines;
|
2011-04-13 18:35:19 +01:00
|
|
|
default = "";
|
|
|
|
description = "
|
2016-05-21 12:49:14 +01:00
|
|
|
slapd.conf configuration
|
2011-04-13 18:35:19 +01:00
|
|
|
";
|
2016-06-05 06:40:26 +01:00
|
|
|
example = literalExample ''
|
|
|
|
'''
|
2017-03-01 10:22:34 +00:00
|
|
|
include ${pkgs.openldap.out}/etc/schema/core.schema
|
|
|
|
include ${pkgs.openldap.out}/etc/schema/cosine.schema
|
|
|
|
include ${pkgs.openldap.out}/etc/schema/inetorgperson.schema
|
|
|
|
include ${pkgs.openldap.out}/etc/schema/nis.schema
|
2016-01-17 18:34:55 +00:00
|
|
|
|
|
|
|
database bdb
|
|
|
|
suffix dc=example,dc=org
|
|
|
|
rootdn cn=admin,dc=example,dc=org
|
|
|
|
# NOTE: change after first start
|
|
|
|
rootpw secret
|
|
|
|
directory /var/db/openldap
|
2016-06-05 06:40:26 +01:00
|
|
|
'''
|
2016-01-17 18:34:55 +00:00
|
|
|
'';
|
2011-04-13 18:35:19 +01:00
|
|
|
};
|
|
|
|
};
|
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
|
2015-01-26 08:35:56 +00:00
|
|
|
mkdir -p ${cfg.dataDir}
|
|
|
|
chown -R ${cfg.user}:${cfg.group} ${cfg.dataDir}
|
2013-04-09 16:50:53 +01:00
|
|
|
'';
|
2016-10-23 12:55:23 +01:00
|
|
|
serviceConfig.ExecStart = "${openldap.out}/libexec/slapd -u ${cfg.user} -g ${cfg.group} -d 0 -h \"${concatStringsSep " " cfg.urlList}\" ${if cfg.configDir == null then "-f "+configFile else "-F "+cfg.configDir}";
|
2013-04-09 16:50:53 +01:00
|
|
|
};
|
2011-04-13 18:35:19 +01:00
|
|
|
|
2015-01-26 08:35:56 +00:00
|
|
|
users.extraUsers.openldap =
|
|
|
|
{ name = cfg.user;
|
2014-06-11 10:36:15 +01:00
|
|
|
group = cfg.group;
|
2013-11-28 21:21:50 +00:00
|
|
|
uid = config.ids.uids.openldap;
|
2015-01-26 08:35:56 +00:00
|
|
|
};
|
2013-11-28 21:21:50 +00:00
|
|
|
|
2015-01-26 08:35:56 +00:00
|
|
|
users.extraGroups.openldap =
|
|
|
|
{ name = cfg.group;
|
2013-11-28 21:21:50 +00:00
|
|
|
gid = config.ids.gids.openldap;
|
2015-01-26 08:35:56 +00:00
|
|
|
};
|
2011-04-13 18:35:19 +01:00
|
|
|
|
2013-11-28 21:21:50 +00:00
|
|
|
};
|
2011-04-13 18:35:19 +01:00
|
|
|
}
|