@@ -6,6 +6,12 @@ let
6 ids = config.ids;
6 ids = config.ids;
7 cfg = config.users;
7 cfg = config.users;
9+ isPasswdCompatible = str: !(hasInfix ":" str || hasInfix "\n" str);
10+ passwdEntry = type: lib.types.addCheck type isPasswdCompatible // {
11+ name = "passwdEntry ${type.name}";
12+ description = "${type.description}, not containing newlines or colons";
9 # Check whether a password hash will allow login.
15 # Check whether a password hash will allow login.
10 allowsLogin = hash:
16 allowsLogin = hash:
11 hash == "" # login without password
17 hash == "" # login without password
@@ -54,7 +60,7 @@ let
54 options = {
60 options = {
56 name = mkOption {
62 name = mkOption {
57− type = types.str;
63+ type = passwdEntry types.str;
58 apply = x: assert (builtins.stringLength x < 32 || abort "Username '${x}' is longer than 31 characters which is not allowed!"); x;
64 apply = x: assert (builtins.stringLength x < 32 || abort "Username '${x}' is longer than 31 characters which is not allowed!"); x;
59 description = ''
65 description = ''
60 The name of the user account. If undefined, the name of the
66 The name of the user account. If undefined, the name of the
@@ -63,7 +69,7 @@ let
65 description = mkOption {
71 description = mkOption {
66− type = types.str;
72+ type = passwdEntry types.str;
67 default = "";
73 default = "";
68 example = "Alice Q. User";
74 example = "Alice Q. User";
69 description = ''
75 description = ''
@@ -128,7 +134,7 @@ let
130 home = mkOption {
136 home = mkOption {
131− type = types.path;
137+ type = passwdEntry types.path;
132 default = "/var/empty";
138 default = "/var/empty";
133 description = "The user's home directory.";
139 description = "The user's home directory.";
@@ -157,7 +163,7 @@ let
159 shell = mkOption {
165 shell = mkOption {
160− type = types.nullOr (types.either types.shellPackage types.path);
166+ type = types.nullOr (types.either types.shellPackage (passwdEntry types.path));
161 default = pkgs.shadow;
167 default = pkgs.shadow;
162 defaultText = "pkgs.shadow";
168 defaultText = "pkgs.shadow";
163 example = literalExample "pkgs.bashInteractive";
169 example = literalExample "pkgs.bashInteractive";
@@ -217,7 +223,7 @@ let
219 hashedPassword = mkOption {
225 hashedPassword = mkOption {
220− type = with types; nullOr str;
226+ type = with types; nullOr (passwdEntry str);
221 default = null;
227 default = null;
222 description = ''
228 description = ''
223 Specifies the hashed password for the user.
229 Specifies the hashed password for the user.
@@ -251,7 +257,7 @@ let
253 initialHashedPassword = mkOption {
259 initialHashedPassword = mkOption {
254− type = with types; nullOr str;
260+ type = with types; nullOr (passwdEntry str);
255 default = null;
261 default = null;
256 description = ''
262 description = ''
257 Specifies the initial hashed password for the user, i.e. the
263 Specifies the initial hashed password for the user, i.e. the
@@ -323,7 +329,7 @@ let
323 options = {
329 options = {
325 name = mkOption {
331 name = mkOption {
326− type = types.str;
332+ type = passwdEntry types.str;
327 description = ''
333 description = ''
328 The name of the group. If undefined, the name of the attribute set
334 The name of the group. If undefined, the name of the attribute set
329 will be used.
335 will be used.
@@ -340,7 +346,7 @@ let
342 members = mkOption {
348 members = mkOption {
343− type = with types; listOf str;
349+ type = with types; listOf (passwdEntry str);
344 default = [];
350 default = [];
345 description = ''
351 description = ''
346 The user names of the group members, added to the
352 The user names of the group members, added to the