]> Git — Sourcephile - sourcephile-nix.git/blob - servers/mermet/openldap/sourcephile.fr.nix
direnv: use flock
[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 users.groups."${domainGroup}" = {
17 gid = 20000;
18 members = ["julm"];
19 };
20 # DEBUG: echo "$(nixops show-option mermet -d production services.openldap.databases."g".data)"
21 services.openldap.databases."${domainSuffix}" = {
22 # DEBUG: sudo ldapsearch -LLL -H ldapi:// -D cn=admin,cn=config -Y EXTERNAL -b 'olcDatabase={1}mdb,cn=config' -s sub
23 # WARNING: newlines matter
24 conf = ''
25 dn: olcDatabase=mdb,cn=config
26 objectClass: olcDatabaseConfig
27 objectClass: olcMdbConfig
28 # Checkpoint the database periodically in case of system failure
29 # and to speed up slapd shutdown.
30 olcDbCheckpoint: 512 30
31 # Database max size is 1G
32 olcDbMaxSize: 1073741824
33 olcLastMod: TRUE
34 # Database superuser. Needed for syncrepl.
35 olcRootDN: cn=admin,${domainSuffix}
36 # Superuser password, generated with slappasswd -h "{SSHA}"
37 # Commented-out because SASL EXTERNAL mechanism is used.
38 #olcRootPW: {SSHA}COkATGNe7rs/g8vWcYP5rqt4u5sWdMgP
39 #
40 olcDbIndex: objectClass eq
41 olcDbIndex: cn,uid eq
42 olcDbIndex: uidNumber,gidNumber eq
43 olcDbIndex: member,memberUid eq
44 olcDbIndex: mail eq
45 olcDbIndex: mailAlias eq
46 olcDbIndex: mailEnabled eq
47 #
48 olcAccess: to attrs=userPassword
49 by self write
50 by anonymous auth
51 by dn="gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth" write
52 by * none
53 olcAccess: to attrs=shadowLastChange
54 by self write
55 by dn="gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth" write
56 by * none
57 olcAccess: to dn.sub="ou=posix,${domainSuffix}"
58 by self read
59 by dn="gidNumber=${toString groups.nslcd.gid}+uidNumber=${toString users.nslcd.uid},cn=peercred,cn=external,cn=auth" read
60 ${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''}
61 ${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''}
62 by dn="gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth" read
63 olcAccess: to *
64 by self read
65 by * none
66 '';
67 data = ''
68 dn: ${domainSuffix}
69 objectClass: top
70 objectClass: dcObject
71 objectClass: organization
72 o: ${domainOrg}
73
74 dn: cn=admin,${domainSuffix}
75 objectClass: simpleSecurityObject
76 objectClass: organizationalRole
77 description: ${domainOrg} LDAP administrator
78 roleOccupant: ${domainSuffix}
79 userPassword:
80
81 dn: ou=posix,${domainSuffix}
82 objectClass: top
83 objectClass: organizationalUnit
84
85 dn: ou=accounts,ou=posix,${domainSuffix}
86 objectClass: top
87 objectClass: organizationalUnit
88
89 dn: ou=groups,ou=posix,${domainSuffix}
90 objectClass: top
91 objectClass: organizationalUnit
92
93 ''
94 /*
95 dn: cn=${domainGroup},ou=groups,ou=posix,${domainSuffix}
96 objectClass: top
97 objectClass: posixGroup
98 gidNumber: 20000
99 memberUid: julm
100
101 dn: cn=autogeree,ou=groups,ou=posix,${domainSuffix}
102 objectClass: top
103 objectClass: posixGroup
104 gidNumber: 20001
105 memberUid: julm
106 */
107 + lib.concatMapStrings posixAccount [ rec
108 { uid = "julm";
109 cn = "Julien Moutinho";
110 sn = uid;
111 uidNumber = users.julm.uid;
112 gidNumber = groups.julm.gid;
113 mailAlias = [ "julien.moutinho" ];
114 userPassword = pass-chomp "members/julm/mail/hashedPassword";
115 mailStorageDirectory =
116 let stateDir = "/var/lib/dovecot";
117 d=domain;
118 in
119 # I'm personnaly using "maildir:" instead of "sdbox:" to be able to use a local (neo)mutt on it,
120 # bypassing IMAP because (neo)mutt support of IMAP is very bad
121 # (can't even have a decent $folder_format (with %n or %m) working,
122 # neither sorting them by date).
123 "maildir:${stateDir}/home/${d}/${uid}/mail:LAYOUT=maildir++:UTF-8:CONTROL=${stateDir}/control/${d}/${uid}:INDEX=${stateDir}/index/${d}/${uid}";
124 }
125 #{ uid="sevy"; uidNumber=10001; cn="Séverine Popek"; sn="sévy";
126 # mailAlias = ["severine.popek" "ouais-ouais"]; }
127 #{ uid="nomail"; uidNumber=10002; mailAlias = ["noalias"]; mailEnabled = false; }
128 #{ uid="post"; mailForwardingAddress = ["ju@${domain}"]; }
129 #{ uid="host"; mailForwardingAddress = ["ju@${domain}"]; }
130 ];
131 };
132 }