1 { pkgs, lib, config, ... }:
3 inherit (builtins) hasAttr;
4 inherit (builtins.extraBuiltins) pass-chomp;
5 inherit (config) networking;
6 inherit (config.services) openldap postfix dovecot2;
7 inherit (config.users) users groups;
8 inherit (pkgs.lib) unlines;
9 domain = "autogeree.net";
10 domainGroup = "autogeree";
11 domainOrg = "autogeree";
12 domainSuffix = "dc=" + lib.concatStringsSep ",dc=" (lib.splitString "." domain);
13 posixAccount = pkgs.callPackage (import ./posixAccount.nix) { inherit domain domainSuffix domainGroup; };
16 users.groups."${domainGroup}" = {
20 services.openldap.databases."${domainSuffix}" = {
21 # WARNING: newlines matter
23 dn: olcDatabase=mdb,cn=config
24 objectClass: olcDatabaseConfig
25 objectClass: olcMdbConfig
26 # Checkpoint the database periodically in case of system failure
27 # and to speed up slapd shutdown.
28 olcDbCheckpoint: 512 30
29 # Database max size is 1G
30 olcDbMaxSize: 1073741824
32 # Database superuser. Needed for syncrepl.
33 olcRootDN: cn=admin,${domainSuffix}
34 # Superuser password, generated with slappasswd -h "{SSHA}"
35 # Commented-out because SASL EXTERNAL mechanism is used.
36 #olcRootPW: {SSHA}COkATGNe7rs/g8vWcYP5rqt4u5sWdMgP
38 olcDbIndex: objectClass eq
40 olcDbIndex: uidNumber,gidNumber eq
41 olcDbIndex: member,memberUid eq
43 olcDbIndex: mailAlias eq
44 olcDbIndex: mailEnabled eq
46 olcAccess: to attrs=userPassword
49 by dn="gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth" write
51 olcAccess: to attrs=shadowLastChange
53 by dn="gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth" write
55 olcAccess: to dn.sub="ou=posix,${domainSuffix}"
57 ${lib.optionalString (hasAttr postfix.user users) ''by dn="gidNumber=${toString groups.postfix.gid}+uidNumber=${toString users.postfix.uid},cn=peercred,cn=external,cn=auth" read''}
58 ${lib.optionalString (hasAttr dovecot2.user users) ''by dn="gidNumber=${toString groups.dovecot2.gid}+uidNumber=${toString users.dovecot2.uid},cn=peercred,cn=external,cn=auth" read''}
59 by dn="gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth" read
68 objectClass: organization
71 dn: cn=admin,${domainSuffix}
72 objectClass: simpleSecurityObject
73 objectClass: organizationalRole
74 description: ${domainOrg} LDAP administrator
75 roleOccupant: ${domainSuffix}
78 dn: ou=posix,${domainSuffix}
80 objectClass: organizationalUnit
82 dn: ou=accounts,ou=posix,${domainSuffix}
84 objectClass: organizationalUnit
86 dn: ou=groups,ou=posix,${domainSuffix}
88 objectClass: organizationalUnit
91 + lib.concatMapStrings posixAccount [ rec
93 cn = "Julien Moutinho";
95 uidNumber = users.julm.uid;
96 gidNumber = groups.julm.gid;
97 mailAlias = [ "julien.moutinho" ];
98 userPassword = pass-chomp "members/julm/mail/hashedPassword";
99 mailStorageDirectory =
100 let stateDir = "/var/lib/dovecot";
103 # I'm personnaly using "maildir:" instead of "sdbox:" to be able to use a local (neo)mutt on it,
104 # bypassing IMAP because (neo)mutt support of IMAP is very bad
105 # (can't even have a decent $folder_format (with %n or %m) working,
106 # neither sorting them by date).
107 "maildir:/home/${uid}/mail/${d}/mail:LAYOUT=maildir++:UTF-8:CONTROL=${stateDir}/control/${d}/${uid}:INDEX=${stateDir}/index/${d}/${uid}";