diff options
| author | Michael Hoang <enzime@users.noreply.github.com> | 2024-10-24 23:19:27 +1100 |
|---|---|---|
| committer | Michael Hoang <enzime@users.noreply.github.com> | 2024-10-27 21:26:19 +1100 |
| commit | bd161d61d6f322e1c16543b67b1dbd13934e763c (patch) | |
| tree | 352fe7e8263a4ebc9b258f39d6628c302ee8bab4 /modules/users | |
| parent | c9af5c2d1394d1bc34f4722998bcd51714ccd68c (diff) | |
users: allow `home` to be managed by macOS
Diffstat (limited to 'modules/users')
| -rw-r--r-- | modules/users/default.nix | 13 | ||||
| -rw-r--r-- | modules/users/user.nix | 14 |
2 files changed, 22 insertions, 5 deletions
diff --git a/modules/users/default.nix b/modules/users/default.nix index f293f77..0b2ffd9 100644 --- a/modules/users/default.nix +++ b/modules/users/default.nix @@ -236,7 +236,13 @@ in requireFDA ${name} "created" - sysadminctl -addUser ${lib.escapeShellArgs ([ v.name "-UID" v.uid "-GID" v.gid ] ++ (lib.optionals (v.description != null) [ "-fullName" v.description ]) ++ [ "-home" v.home "-shell" (shellPath v.shell) ])} 2> /dev/null + sysadminctl -addUser ${lib.escapeShellArgs ([ + v.name + "-UID" v.uid + "-GID" v.gid ] + ++ (lib.optionals (v.description != null) [ "-fullName" v.description ]) + ++ (lib.optionals (v.home != null) [ "-home" v.home ]) + ++ [ "-shell" (shellPath v.shell) ])} 2> /dev/null # We need to check as `sysadminctl -addUser` still exits with exit code 0 when there's an error if ! id ${name} &> /dev/null; then @@ -245,7 +251,10 @@ in fi dscl . -create ${dsclUser} IsHidden ${if v.isHidden then "1" else "0"} - ${optionalString v.createHome "createhomedir -cu ${name}"} + + # `sysadminctl -addUser` won't create the home directory if we use the `-home` + # flag so we need to do it ourselves + ${optionalString (v.home != null && v.createHome) "createhomedir -cu ${name} > /dev/null"} fi # Update properties on known users to keep them inline with configuration diff --git a/modules/users/user.nix b/modules/users/user.nix index a0c8aab..b9c9799 100644 --- a/modules/users/user.nix +++ b/modules/users/user.nix @@ -53,9 +53,17 @@ # }; home = mkOption { - type = types.path; - default = "/var/empty"; - description = "The user's home directory."; + type = types.nullOr types.path; + default = null; + description = '' + The user's home directory. This defaults to `null`. + + When this is set to `null`, the value is managed by macOS instead of + `nix-darwin`. This means if the user has not been created yet, + `sysadminctl` will be called without the `-home` flag which means the + user will have a default home directory of `/Users/<name>` which will + be created by `sysadminctl`. + ''; }; createHome = mkOption { |
