1 { flakes, 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 = "autogeree.net";
9 domainGroup = "autogeree";
10 domainOrg = "autogeree";
11 domainSuffix = "dc=" + lib.concatStringsSep ",dc=" (lib.splitString "." domain);
12 posixAccount = pkgs.callPackage (import ./posixAccount.nix) { inherit domain domainSuffix domainGroup; };
15 users.groups."${domainGroup}" = {
21 services.openldap.databases."${domainSuffix}" = {
22 # WARNING: newlines matter
24 dn: olcDatabase=mdb,cn=config
25 objectClass: olcDatabaseConfig
26 objectClass: olcMdbConfig
27 # Checkpoint the database periodically in case of system failure
28 # and to speed up slapd shutdown.
29 olcDbCheckpoint: 512 30
30 # Database max size is 1G
31 olcDbMaxSize: 1073741824
33 # Database superuser. Needed for syncrepl.
34 olcRootDN: cn=admin,${domainSuffix}
35 # Superuser password, generated with slappasswd -h "{SSHA}"
36 # Commented-out because SASL EXTERNAL mechanism is used.
37 #olcRootPW: {SSHA}COkATGNe7rs/g8vWcYP5rqt4u5sWdMgP
39 olcDbIndex: objectClass eq
41 olcDbIndex: uidNumber,gidNumber eq
42 olcDbIndex: member,memberUid eq
44 olcDbIndex: mailAlias eq
45 olcDbIndex: mailEnabled eq
47 olcAccess: to attrs=userPassword
50 by dn="gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth" write
52 olcAccess: to attrs=shadowLastChange
54 by dn="gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth" write
56 olcAccess: to dn.sub="ou=posix,${domainSuffix}"
58 ${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''}
59 ${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''}
60 by dn="gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth" read
69 objectClass: organization
72 dn: cn=admin,${domainSuffix}
73 objectClass: simpleSecurityObject
74 objectClass: organizationalRole
75 description: ${domainOrg} LDAP administrator
76 roleOccupant: ${domainSuffix}
79 dn: ou=posix,${domainSuffix}
81 objectClass: organizationalUnit
83 dn: ou=accounts,ou=posix,${domainSuffix}
85 objectClass: organizationalUnit
87 dn: ou=groups,ou=posix,${domainSuffix}
89 objectClass: organizationalUnit
92 + lib.concatMapStrings posixAccount [ rec
94 cn = "Julien Moutinho";
96 uidNumber = users."julm".uid;
97 gidNumber = groups."users".gid;
98 mailAlias = [ "julien.moutinho" ];
99 userPassword = builtins.readFile (flakes.secrets + "/members/mail/julm/hashedPassword");
100 mailHomeDirectory = "/home/${uid}/mail/${domain}";
101 mailStorageDirectory =
102 let stateDir = "/var/lib/dovecot"; in
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 # WARNING: regarding the atomicity of backuping,
108 # it's not a good idea to put the mails
109 # and the index/control on different ZFS datasets like here.
110 "maildir:/home/${uid}/mail/${domain}/mail:LAYOUT=maildir++:UTF-8:CONTROL=${stateDir}/control/${domain}/${uid}:INDEX=${stateDir}/index/${domain}/${uid}";