]> Git — Sourcephile - sourcephile-nix.git/blob - servers/mermet/openldap/sourcephile.fr.nix
openldap: use PR#79286
[sourcephile-nix.git] / servers / mermet / openldap / sourcephile.fr.nix
1 { pkgs, lib, config, ... }:
2 let
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 = "sourcephile.fr";
10 domainGroup = "sourcephile";
11 domainOrg = "sourcephile";
12 domainSuffix = "dc=" + lib.concatStringsSep ",dc=" (lib.splitString "." domain);
13 posixAccount = pkgs.callPackage (import ./posixAccount.nix) { inherit domain domainSuffix domainGroup; };
14 in
15 {
16 # DEBUG: echo "$(nixops show-option mermet -d production services.openldap.databases."g".data)"
17 services.openldap.databases."${domainSuffix}" = {
18 # DEBUG: sudo ldapsearch -LLL -H ldapi:// -D cn=admin,cn=config -Y EXTERNAL -b 'olcDatabase={1}mdb,cn=config' -s sub
19 # WARNING: newlines matter
20 conf = ''
21 dn: olcBackend=mdb,cn=config
22 objectClass: olcBackendConfig
23
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
32 olcLastMod: TRUE
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
38 #
39 olcDbIndex: objectClass eq
40 olcDbIndex: cn,uid eq
41 olcDbIndex: uidNumber,gidNumber eq
42 olcDbIndex: member,memberUid eq
43 olcDbIndex: mail eq
44 olcDbIndex: mailAlias eq
45 olcDbIndex: mailEnabled eq
46 #
47 olcAccess: to attrs=userPassword
48 by self write
49 by anonymous auth
50 by dn="gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth" write
51 by * none
52 olcAccess: to attrs=shadowLastChange
53 by self write
54 by dn="gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth" write
55 by * none
56 olcAccess: to dn.sub="ou=posix,${domainSuffix}"
57 by self read
58 by dn="gidNumber=${toString groups.nslcd.gid}+uidNumber=${toString users.nslcd.uid},cn=peercred,cn=external,cn=auth" read
59 ${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''}
60 ${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''}
61 by dn="gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth" read
62 olcAccess: to *
63 by self read
64 by * none
65 '';
66 data = ''
67 dn: ${domainSuffix}
68 objectClass: top
69 objectClass: dcObject
70 objectClass: organization
71 o: ${domainOrg}
72
73 dn: cn=admin,${domainSuffix}
74 objectClass: simpleSecurityObject
75 objectClass: organizationalRole
76 description: ${domainOrg} LDAP administrator
77 roleOccupant: ${domainSuffix}
78 userPassword:
79
80 dn: ou=posix,${domainSuffix}
81 objectClass: top
82 objectClass: organizationalUnit
83
84 dn: ou=accounts,ou=posix,${domainSuffix}
85 objectClass: top
86 objectClass: organizationalUnit
87
88 dn: ou=groups,ou=posix,${domainSuffix}
89 objectClass: top
90 objectClass: organizationalUnit
91
92 dn: cn=${domainGroup},ou=groups,ou=posix,${domainSuffix}
93 objectClass: top
94 objectClass: posixGroup
95 gidNumber: 20000
96 memberUid: julm
97 memberUid: sevy
98
99 ''
100 + lib.concatMapStrings posixAccount [ rec
101 { uid = "julm";
102 cn = "Julien Moutinho";
103 sn = uid;
104 uidNumber = users.julm.uid;
105 gidNumber = groups.julm.gid;
106 mailAlias = [ "julien.moutinho" ];
107 userPassword = pass-chomp "members/julm/mail/hashedPassword";
108 mailStorageDirectory =
109 let stateDir = "/var/lib/dovecot";
110 d=domain;
111 in
112 # I'm personnaly using "maildir:" instead of "sdbox:" to be able to use a local (neo)mutt on it,
113 # bypassing IMAP because (neo)mutt support of IMAP is very bad
114 # (can't even have a decent $folder_format (with %n or %m) working,
115 # neither sorting them by date).
116 "maildir:${stateDir}/mail/${d}/${uid}/mail.d:LAYOUT=maildir++:UTF-8:CONTROL=${stateDir}/control/${d}/${uid}:INDEX=${stateDir}/index/${d}/${uid}";
117 }
118 #{ uid="sevy"; uidNumber=10001; cn="Séverine Popek"; sn="sévy";
119 # mailAlias = ["severine.popek" "ouais-ouais"]; }
120 #{ uid="nomail"; uidNumber=10002; mailAlias = ["noalias"]; mailEnabled = false; }
121 #{ uid="post"; mailForwardingAddress = ["ju@${domain}"]; }
122 #{ uid="host"; mailForwardingAddress = ["ju@${domain}"]; }
123 ];
124 };
125 }