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