Skip to content

Commit

Permalink
nixos/users-groups: move home dir creation to systemd tmpfiles
Browse files Browse the repository at this point in the history
Fixes NixOS#6481

When the home directory is on a separate mount the user home
directories were not created.

Using systemd tmpfiles solves the race condition.
  • Loading branch information
jsoo1 committed Mar 30, 2023
1 parent f53f95f commit ef27743
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
2 changes: 2 additions & 0 deletions nixos/doc/manual/release-notes/rl-2305.section.md
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,8 @@ In addition to numerous new and upgraded packages, this release has the followin

- `boot.initrd.luks.device.<name>` has a new `tryEmptyPassphrase` option, this is useful for OEM's who need to install an encrypted disk with a future settable passphrase

- `users.users.<name>.home` directories are created with systemd tmpfiles rules instead of activation scripts. This fixes a bug where home directories were not created when home directories were on a separate mount. (See issue [#6481](https://github.com/NixOS/nixpkgs/issues/6481))

## Detailed migration information {#sec-release-23.05-migration}

### Pipewire configuration overrides {#sec-release-23.05-migration-pipewire}
Expand Down
7 changes: 0 additions & 7 deletions nixos/modules/config/update-users-groups.pl
Original file line number Diff line number Diff line change
Expand Up @@ -224,13 +224,6 @@ sub parseUser {
}
}

# Ensure home directory incl. ownership and permissions.
if ($u->{createHome} and !$is_dry) {
make_path($u->{home}, { mode => oct($u->{homeMode}) }) if ! -e $u->{home};
chown $u->{uid}, $u->{gid}, $u->{home};
chmod oct($u->{homeMode}), $u->{home};
}

if (defined $u->{passwordFile}) {
if (-e $u->{passwordFile}) {
$u->{hashedPassword} = read_file($u->{passwordFile});
Expand Down
6 changes: 6 additions & 0 deletions nixos/modules/config/users-groups.nix
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,12 @@ in {
else null
));

systemd.tmpfiles.rules = lib.concatLists (lib.mapAttrsToList
(_: user:
lib.optionals user.createHome [
"d ${lib.escapeShellArg user.home} ${user.homeMode} ${user.name} ${user.group}"
])
config.users.users);
};

}

0 comments on commit ef27743

Please sign in to comment.