git.iko.soy/typeable/nixpkgs
on master help sign in
nixos/openldap: make rootpw option optional

This allows to store passwords in external files outside of the world-readable nix store.

commitd43dc68db3f414a527cad632a3f1fb868fc1c902 authorJörg Thalheim <joerg@thalheim.io> dateTue 23 Apr 2019, 15:13 (8 years ago) parent9d127f2
1 file changed+28−5
nixos/modules/services/databases/openldap.nix+28−5
nixos/modules/services/databases/openldap.nix+28−5
@@ -18,7 +18,11 @@ let
1818 database ${cfg.database}
1919 suffix ${cfg.suffix}
2020 rootdn ${cfg.rootdn}
21− rootpw ${cfg.rootpw}
21+ ${if (cfg.rootpw != null) then ''
22+ rootpw ${cfg.rootpw}
23+ '' else ''
24+ include ${cfg.rootpwFile}
25+ ''}
2226 directory ${cfg.dataDir}
2327 ${cfg.extraDatabaseConfig}
2428 '');
@@ -106,10 +110,23 @@ in
106110 };
107111
108112 rootpw = mkOption {
109− type = types.str;
113+ type = types.nullOr types.str;
114+ default = null;
110115 description = ''
111116 Password for the root user.
112117 This setting will be ignored if configDir is set.
118+ Using this option will store the root password in plain text in the
119+ world-readable nix store. To avoid this the <literal>rootpwFile</literal> can be used.
120+ '';
121+ };
122+
123+ rootpwFile = mkOption {
124+ type = types.nullOr types.str;
125+ default = null;
126+ description = ''
127+ Password file for the root user.
128+ The file should contain the string <literal>rootpw</literal> followed by the password.
129+ e.g.: <literal>rootpw mysecurepassword</literal>
113130 '';
114131 };
115132
@@ -140,9 +157,9 @@ in
140157 include ${pkgs.openldap.out}/etc/schema/inetorgperson.schema
141158 include ${pkgs.openldap.out}/etc/schema/nis.schema
142159
143− database bdb
144− suffix dc=example,dc=org
145− rootdn cn=admin,dc=example,dc=org
160+ database bdb
161+ suffix dc=example,dc=org
162+ rootdn cn=admin,dc=example,dc=org
146163 # NOTE: change after first start
147164 rootpw secret
148165 directory /var/db/openldap
@@ -218,6 +235,12 @@ in
218235 ###### implementation
219236
220237 config = mkIf cfg.enable {
238+ assertions = [
239+ {
240+ assertion = cfg.rootpwFile != null || cfg.rootpw != null;
241+ message = "Either services.openldap.rootpw or services.openldap.rootpwFile must be set";
242+ }
243+ ];
221244
222245 environment.systemPackages = [ openldap ];
223246