From 64145a1996554e4e81b694e9737421f34f44e212 Mon Sep 17 00:00:00 2001 From: Siddharth Balyan <52913345+alt-glitch@users.noreply.github.com> Date: Mon, 11 May 2026 12:59:57 +0530 Subject: [PATCH] fix(nix): replace chown -R with targeted find in container entrypoint (#23633) The container entrypoint ran `chown -R` on $HERMES_HOME every start. `chown` strips the setgid bit (kernel security behavior), destroying the 2770 permissions the NixOS activation script sets for group access by hostUsers. This caused PermissionError for interactive CLI users even though they were in the hermes group. Replace with `find ... ! -user $UID -exec chown` which only touches files with wrong ownership, leaving correctly-owned directories and their permission bits intact. Affects: container.enable + container.hostUsers + addToSystemPackages Related: #19795, #19788, #9383 --- nix/nixosModules.nix | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/nix/nixosModules.nix b/nix/nixosModules.nix index 475e5b5ba5a..f5c067a6398 100644 --- a/nix/nixosModules.nix +++ b/nix/nixosModules.nix @@ -117,9 +117,13 @@ chown "$HERMES_UID:$HERMES_GID" "$TARGET_HOME" chmod 0750 "$TARGET_HOME" - # Ensure HERMES_HOME is owned by the target user + # Ensure HERMES_HOME is owned by the target user. + # Use find instead of chown -R: chown strips the setgid bit (kernel + # behavior), destroying the 2770 permissions the NixOS activation + # script sets for group access by hostUsers. Only touch files with + # wrong ownership so correctly-owned dirs keep their permission bits. if [ -n "''${HERMES_HOME:-}" ] && [ -d "$HERMES_HOME" ]; then - chown -R "$HERMES_UID:$HERMES_GID" "$HERMES_HOME" + find "$HERMES_HOME" \! -user "$HERMES_UID" -exec chown "$HERMES_UID:$HERMES_GID" {} + fi # ── Provision apt packages (first boot only, cached in writable layer) ──