1 { pkgs, lib, config, ... }:
3 inherit (builtins) hasAttr;
4 inherit (config.services) openldap postfix dovecot2;
5 inherit (config.users) users groups;
6 domain = "autogeree.net";
7 domainGroup = "autogeree";
8 domainOrg = "autogeree";
9 domainSuffix = "dc=" + lib.concatStringsSep ",dc=" (lib.splitString "." domain);
10 posixAccount = pkgs.callPackage (import ./posixAccount.nix) { inherit domain domainSuffix domainGroup; };
13 users.groups."${domainGroup}" = {
20 # sudo ldapsearch -LLL -H ldapi:// -D cn=admin,cn=config -Y EXTERNAL -b 'olcDatabase={2}mdb,cn=config' -s sub
21 settings.children."olcDatabase={2}mdb".attrs = {
22 objectClass = [ "olcDatabaseConfig" "olcMdbConfig" ];
23 olcDatabase = "{2}mdb";
24 olcSuffix = domainSuffix;
25 olcDbDirectory = "/var/lib/openldap/${domainSuffix}";
29 "uidNumber,gidNumber eq"
36 ''to attrs=userPassword
39 by dn="gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth" write
42 ''to attrs=shadowLastChange
44 by dn="gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth" write
47 ''to dn.sub="ou=posix,${domainSuffix}"
49 ${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''}
50 ${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''}
51 by dn="gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth" read
58 # Checkpoint the database periodically in case of system failure
59 # and to speed up slapd shutdown.
60 olcDbCheckpoint = "512 30";
61 # Database max size is 1G
62 olcDbMaxSize = "1073741824";
64 # Database superuser. Needed for syncrepl.
65 olcRootDN = "cn=admin,${domainSuffix}";
66 # Superuser password, generated with slappasswd -h "{SSHA}"
67 # Commented-out because SASL EXTERNAL mechanism is used.
68 #olcRootPW = "{SSHA}COkATGNe7rs/g8vWcYP5rqt4u5sWdMgP";
70 # sudo ldapsearch -LLL -H ldapi:// -D cn=admin,cn=config -Y EXTERNAL -b 'ou=posix,dc=autogeree,dc=net' -s sub
71 declarativeContents."${domainSuffix}" = ''
75 objectClass: organization
78 dn: cn=admin,${domainSuffix}
79 objectClass: simpleSecurityObject
80 objectClass: organizationalRole
81 description: ${domainOrg} LDAP administrator
82 roleOccupant: ${domainSuffix}
85 dn: ou=posix,${domainSuffix}
87 objectClass: organizationalUnit
89 dn: ou=accounts,ou=posix,${domainSuffix}
91 objectClass: organizationalUnit
93 dn: ou=groups,ou=posix,${domainSuffix}
95 objectClass: organizationalUnit
99 dn: cn=${domainGroup},ou=groups,ou=posix,${domainSuffix}
101 objectClass: posixGroup
105 dn: cn=autogeree,ou=groups,ou=posix,${domainSuffix}
107 objectClass: posixGroup
111 + lib.concatMapStrings posixAccount [
114 cn = "Julien Moutinho";
116 uidNumber = users."julm".uid;
117 gidNumber = groups."users".gid;
118 mailAlias = [ "julien.moutinho" ];
119 userPassword = builtins.readFile (./. + "/${domain}/${uid}/hashedPassword.clear");
120 mailHomeDirectory = "/home/${uid}/mail/${domain}";
122 mailStorageDirectory =
123 let stateDir = "/var/lib/dovecot"; in
124 # I'm personnaly using "maildir:" instead of "sdbox:" to be able to use a local (neo)mutt on it,
125 # bypassing IMAP because (neo)mutt support of IMAP is very bad
126 # (can't even have a decent $folder_format (with %n or %m) working,
127 # neither sorting them by date).
128 # WARNING: regarding the atomicity of backuping,
129 # it's not a good idea to put the mails
130 # and the index/control on different ZFS datasets like here.
131 "maildir:/home/${uid}/mail/${domain}/mail:LAYOUT=maildir++:UTF-8:CONTROL=${stateDir}/control/${domain}/${uid}:INDEX=${stateDir}/index/${domain}/${uid}";