From 5f68eed0a3bac8e09817e3d9330b16f65e8e8ca2 Mon Sep 17 00:00:00 2001 From: John Soo Date: Thu, 30 Mar 2023 09:46:32 -0700 Subject: [PATCH] nixos/users-groups: move home dir creation to systemd tmpfiles Fixes https://github.com/NixOS/nixpkgs/issues/6481 When the home directory is on a separate mount the user home directories were not created. Using systemd tmpfiles solve the race condition. --- nixos/modules/config/update-users-groups.pl | 7 ------- nixos/modules/config/users-groups.nix | 6 ++++++ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/nixos/modules/config/update-users-groups.pl b/nixos/modules/config/update-users-groups.pl index 232f886789d38ba..a71691617db38ab 100644 --- a/nixos/modules/config/update-users-groups.pl +++ b/nixos/modules/config/update-users-groups.pl @@ -222,13 +222,6 @@ sub parseUser { } } - # Ensure home directory incl. ownership and permissions. - if ($u->{createHome}) { - make_path($u->{home}, { mode => 0700 }) if ! -e $u->{home} and ! $is_dry; - chown $u->{uid}, $u->{gid}, $u->{home}; - chmod 0700, $u->{home}; - } - if (defined $u->{passwordFile}) { if (-e $u->{passwordFile}) { $u->{hashedPassword} = read_file($u->{passwordFile}); diff --git a/nixos/modules/config/users-groups.nix b/nixos/modules/config/users-groups.nix index a34d28143418575..b535b73b560a5ed 100644 --- a/nixos/modules/config/users-groups.nix +++ b/nixos/modules/config/users-groups.nix @@ -685,6 +685,12 @@ in { else null )); + systemd.tmpfiles.rules = lib.concatLists (lib.mapAttrsToList + (_: user: + lib.optionals user.createHome [ + "d ${lib.escapeShellArg user.home} 0700 ${user.name} ${user.group}" + ]) + config.users.users); }; }