diff options
| author | Hraban Luyat <hraban@0brg.net> | 2023-11-23 20:11:18 -0500 |
|---|---|---|
| committer | Hraban Luyat <hraban@0brg.net> | 2024-01-20 11:03:15 -0500 |
| commit | f1d47fc2dd43166cd832cb618a43e575a3fe7d27 (patch) | |
| tree | 1518c6f7731dcd2254afc683af906eef1d1ac48e /modules | |
| parent | 888533c35fb0b46a8b537528b9990ab838ee3efc (diff) | |
fix: set shell for new users, and only known ones
Diffstat (limited to 'modules')
| -rw-r--r-- | modules/users/default.nix | 21 |
1 files changed, 10 insertions, 11 deletions
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 "[1;31mwarning: existing user '${v.name}' has unexpected uid $u, skipping...[0m" >&2 else - if [ "$u" -ne ${toString v.uid} ]; then - echo "[1;31mwarning: existing user '${v.name}' has unexpected uid $u, skipping...[0m" >&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 |
