From 888533c35fb0b46a8b537528b9990ab838ee3efc Mon Sep 17 00:00:00 2001 From: Hraban Luyat Date: Thu, 23 Nov 2023 14:54:06 -0500 Subject: [PATCH] fix: user shell path handling Properly detect the binary name (not just /nix/store/...-bash, but include the .../bin/bash), and use the symlinked name which also appears in /etc/shells. --- modules/users/default.nix | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/modules/users/default.nix b/modules/users/default.nix index 5712002..1c74840 100644 --- a/modules/users/default.nix +++ b/modules/users/default.nix @@ -24,6 +24,14 @@ let deletedUsers = filter (n: isDeleted cfg.users n) cfg.knownUsers; packageUsers = filterAttrs (_: u: u.packages != []) cfg.users; + + # convert a valid argument to user.shell into a string that points to a shell + # executable. Logic copied from modules/system/shells.nix. + shellPath = v: + if types.shellPackage.check v + then "/run/current-system/sw${v.shellPath}" + else v; + in { @@ -158,12 +166,14 @@ in 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}' - dscl . -create '/Users/${v.name}' UserShell '${v.shell}' ${optionalString v.createHome "createhomedir -cu '${v.name}'"} else if [ "$u" -ne ${toString v.uid} ]; then echo "warning: existing user '${v.name}' has unexpected uid $u, skipping..." >&2 fi + + # Always set the shell path, in case it was updated + dscl . -create '/Users/${v.name}' UserShell ${lib.escapeShellArg (shellPath v.shell)} fi '') createdUsers}