Skip to content

Commit db0a0b1

Browse files
nixos/users-groups: split isSystemUser/isNormalUser and uid check into two
Before the error message only mentioned isSystemUser/isNormalUser which lead to a confusing situation when setting isNormalUser and an uid like 500 which would generate an error like: error: Failed assertions: - Exactly one of users.users.other.isSystemUser and users.users.other.isNormalUser must be set. from which you cannot know that setting the uid to 500 *and* setting isNormalUser is the actual problem. With this patch the error looks like: error: Failed assertions: - A user cannot have a users.users.fixme.uid set below 1000 and set users.users.fixme.isNormalUser. Either users.users.fixme.isSystemUser must be set to true instead of users.users.fixme.isNormalUser or users.users.fixme.uid must be changed to 1000 or above.
1 parent 9cd5d09 commit db0a0b1

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

nixos/modules/config/users-groups.nix

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -906,9 +906,18 @@ in {
906906
of /etc/shadow (file where hashes are stored) are colon-separated.
907907
Please check the value of option `users.users."${user.name}".hashedPassword`.'';
908908
}
909+
{
910+
assertion = user.isNormalUser && user.uid != null -> user.uid >= 1000;
911+
message = ''
912+
A user cannot have a users.users.${user.name}.uid set below 1000 and set users.users.${user.name}.isNormalUser.
913+
Either users.users.${user.name}.isSystemUser must be set to true instead of users.users.${user.name}.isNormalUser
914+
or users.users.${user.name}.uid must be changed to 1000 or above.
915+
'';
916+
}
909917
{
910918
assertion = let
911-
isEffectivelySystemUser = user.isSystemUser || (user.uid != null && user.uid < 1000);
919+
# we do an extra check on isNormalUser here, to not trigger this assertion when isNormalUser is set and uid to < 1000
920+
isEffectivelySystemUser = user.isSystemUser || (user.uid != null && user.uid < 1000 && !user.isNormalUser);
912921
in xor isEffectivelySystemUser user.isNormalUser;
913922
message = ''
914923
Exactly one of users.users.${user.name}.isSystemUser and users.users.${user.name}.isNormalUser must be set.

0 commit comments

Comments
 (0)