From f1d47fc2dd43166cd832cb618a43e575a3fe7d27 Mon Sep 17 00:00:00 2001 From: Hraban Luyat Date: Thu, 23 Nov 2023 20:11:18 -0500 Subject: fix: set shell for new users, and only known ones --- modules/users/default.nix | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'modules') diff --git a/modules/users/default.nix b/modules/users/default.nix index 1c74840..9648274 100644 --- a/modules/users/default.nix +++ b/modules/users/default.nix @@ -159,19 +159,18 @@ in u=$(dscl . -read '/Users/${v.name}' UniqueID 2> /dev/null) || true u=''${u#UniqueID: } - if [ -z "$u" ]; then - echo "creating user ${v.name}..." >&2 - dscl . -create '/Users/${v.name}' UniqueID ${toString v.uid} - dscl . -create '/Users/${v.name}' PrimaryGroupID ${toString v.gid} - dscl . -create '/Users/${v.name}' IsHidden ${if v.isHidden then "1" else "0"} - dscl . -create '/Users/${v.name}' RealName '${v.description}' - dscl . -create '/Users/${v.name}' NFSHomeDirectory '${v.home}' - ${optionalString v.createHome "createhomedir -cu '${v.name}'"} + if [[ -n "$u" && "$u" -ne "${toString v.uid}" ]]; then + echo "warning: existing user '${v.name}' has unexpected uid $u, skipping..." >&2 else - if [ "$u" -ne ${toString v.uid} ]; then - echo "warning: existing user '${v.name}' has unexpected uid $u, skipping..." >&2 + if [ -z "$u" ]; then + echo "creating user ${v.name}..." >&2 + dscl . -create '/Users/${v.name}' UniqueID ${toString v.uid} + dscl . -create '/Users/${v.name}' PrimaryGroupID ${toString v.gid} + dscl . -create '/Users/${v.name}' IsHidden ${if v.isHidden then "1" else "0"} + dscl . -create '/Users/${v.name}' RealName '${v.description}' + dscl . -create '/Users/${v.name}' NFSHomeDirectory '${v.home}' + ${optionalString v.createHome "createhomedir -cu '${v.name}'"} fi - # Always set the shell path, in case it was updated dscl . -create '/Users/${v.name}' UserShell ${lib.escapeShellArg (shellPath v.shell)} fi -- cgit v1.2.3