Skip to content

Commit

Permalink
users: ensure all users' home directories in the config are correct
Browse files Browse the repository at this point in the history
  • Loading branch information
Enzime committed Oct 26, 2024
1 parent 7ffb6c7 commit 4a04398
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions modules/users/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@ in
};

config = {
assertions = [
{
# We don't check `root` like the rest of the users as on some systems `root`'s
# home directory is set to `/var/root /private/var/root`
assertion = cfg.users ? root -> (cfg.users.root.home == null || cfg.users.root.home == "/var/root");
message = "`users.users.root.home` must be set to either `null` or `/var/root`.";
}
];

users.gids = mkMerge gids;
users.uids = mkMerge uids;
Expand Down Expand Up @@ -158,6 +166,21 @@ in
if [ -z "$u" ]; then
requireFDA ${name} created
fi
${optionalString (v.home != null && v.name != "root") ''
homeDirectory=$(dscl . -read ${dsclUser} NFSHomeDirectory)
homeDirectory=''${homeDirectory#NFSHomeDirectory: }
if [[ ${lib.escapeShellArg v.home} != "$homeDirectory" ]]; then
printf >&2 '\e[1;31merror: config contains the wrong home directory for %s, aborting activation\e[0m\n' ${name}
printf >&2 'nix-darwin does not support changing the home directory for the calling user (%s).\n' "$SUDO_USER"
printf >&2 '\n'
printf >&2 'Please set:\n'
printf >&2 '\n'
printf >&2 ' users.users.%s.home = "%s";\n' ${name} "$homeDirectory"
printf >&2 '\n'
printf >&2 'or remove it from your configuration.\n'
exit 1
fi
''}
fi
'') createdUsers}
Expand Down

0 comments on commit 4a04398

Please sign in to comment.