1
0
Fork 0
mirror of https://github.com/LnL7/nix-darwin.git synced 2025-03-16 21:38:21 +00:00

users: use lib.escapeShellArg for createhomedir

This commit is contained in:
Michael Hoang 2024-10-22 10:20:43 +11:00
parent 8451125cf8
commit ea7e178ad4
2 changed files with 6 additions and 5 deletions
modules/users
tests

View file

@ -149,19 +149,20 @@ in
echo "setting up users..." >&2 echo "setting up users..." >&2
${concatMapStringsSep "\n" (v: let ${concatMapStringsSep "\n" (v: let
name = lib.escapeShellArg v.name;
dsclUser = lib.escapeShellArg "/Users/${v.name}"; dsclUser = lib.escapeShellArg "/Users/${v.name}";
in '' in ''
${optionalString cfg.forceRecreate '' ${optionalString cfg.forceRecreate ''
u=$(id -u ${lib.escapeShellArg v.name} 2> /dev/null) || true u=$(id -u ${name} 2> /dev/null) || true
if [[ "$u" -eq ${toString v.uid} ]]; then if [[ "$u" -eq ${toString v.uid} ]]; then
echo "deleting user ${v.name}..." >&2 echo "deleting user ${v.name}..." >&2
sysadminctl -deleteUser ${lib.escapeShellArg v.name} 2> /dev/null sysadminctl -deleteUser ${name} 2> /dev/null
else else
echo "warning: existing user '${v.name}' has unexpected uid $u, skipping..." >&2 echo "warning: existing user '${v.name}' has unexpected uid $u, skipping..." >&2
fi fi
''} ''}
u=$(id -u ${lib.escapeShellArg v.name} 2> /dev/null) || true u=$(id -u ${name} 2> /dev/null) || true
if [[ -n "$u" && "$u" -ne "${toString v.uid}" ]]; then if [[ -n "$u" && "$u" -ne "${toString v.uid}" ]]; then
echo "warning: existing user '${v.name}' has unexpected uid $u, skipping..." >&2 echo "warning: existing user '${v.name}' has unexpected uid $u, skipping..." >&2
else else
@ -169,7 +170,7 @@ in
echo "creating user ${v.name}..." >&2 echo "creating user ${v.name}..." >&2
sysadminctl -addUser ${lib.escapeShellArgs [ v.name "-UID" v.uid "-GID" v.gid "-fullName" v.description "-home" v.home "-shell" (shellPath v.shell) ]} sysadminctl -addUser ${lib.escapeShellArgs [ v.name "-UID" v.uid "-GID" v.gid "-fullName" v.description "-home" v.home "-shell" (shellPath v.shell) ]}
dscl . -create ${dsclUser} IsHidden ${if v.isHidden then "1" else "0"} dscl . -create ${dsclUser} IsHidden ${if v.isHidden then "1" else "0"}
${optionalString v.createHome "createhomedir -cu '${v.name}'"} ${optionalString v.createHome "createhomedir -cu ${name}"}
fi fi
# Always set the shell path, in case it was updated # Always set the shell path, in case it was updated
dscl . -create ${dsclUser} UserShell ${lib.escapeShellArg (shellPath v.shell)} dscl . -create ${dsclUser} UserShell ${lib.escapeShellArg (shellPath v.shell)}

View file

@ -44,7 +44,7 @@
# checking user creation in /activate # checking user creation in /activate
grep "sysadminctl -addUser ${lib.escapeShellArgs [ "foo" "-UID" 42000 "-GID" 42000 "-fullName" "Foo user" "-home" "/Users/foo" "-shell" "/run/current-system/sw/bin/bash" ]}" ${config.out}/activate grep "sysadminctl -addUser ${lib.escapeShellArgs [ "foo" "-UID" 42000 "-GID" 42000 "-fullName" "Foo user" "-home" "/Users/foo" "-shell" "/run/current-system/sw/bin/bash" ]}" ${config.out}/activate
grep "createhomedir -cu 'foo'" ${config.out}/activate grep "createhomedir -cu ${lib.escapeShellArg "foo"}" ${config.out}/activate
grep "sysadminctl -addUser ${lib.escapeShellArgs [ "created.user" "-UID" 42001 ]} .* ${lib.escapeShellArgs [ "-shell" "/sbin/nologin" ]}" ${config.out}/activate grep "sysadminctl -addUser ${lib.escapeShellArgs [ "created.user" "-UID" 42001 ]} .* ${lib.escapeShellArgs [ "-shell" "/sbin/nologin" ]}" ${config.out}/activate
grep -qv "sysadminctl -deleteUser ${lib.escapeShellArg "created.user"}" ${config.out}/activate grep -qv "sysadminctl -deleteUser ${lib.escapeShellArg "created.user"}" ${config.out}/activate
grep -qv "sysadminctl -deleteUser ${lib.escapeShellArg "created.user"}" ${config.out}/activate grep -qv "sysadminctl -deleteUser ${lib.escapeShellArg "created.user"}" ${config.out}/activate