libstore: make diff-hooks work for non-root users

it's kind of weird to not allow diff-hooks in single user mode unless
that user is root. maybe that's why we have no tests for them? we can
at least add a test that diff hooks are run at all when we expect it.

Change-Id: I54d623b5416acda1c205cc062b0f3a33c9f4aaa7
This commit is contained in:
eldritch horrors
2026-01-22 15:23:38 +00:00
parent 36168de584
commit d7b0d322f7
3 changed files with 15 additions and 4 deletions
+4 -4
View File
@@ -72,8 +72,8 @@
namespace nix {
static kj::Promise<Result<void>> handleDiffHook(
uid_t uid,
uid_t gid,
std::optional<uid_t> uid,
std::optional<uid_t> gid,
const Path & tryA,
const Path & tryB,
const Path & drvPath,
@@ -1773,8 +1773,8 @@ try {
movePath(actualPath, dst);
TRY_AWAIT(handleDiffHook(
buildUser ? buildUser->getUID() : getuid(),
buildUser ? buildUser->getGID() : getgid(),
buildUser ? std::optional(buildUser->getUID()) : std::nullopt,
buildUser ? std::optional(buildUser->getGID()) : std::nullopt,
finalDestPath,
dst,
worker.store.printStorePath(drvPath),
+8
View File
@@ -139,3 +139,11 @@ nix-store -q --references "$obtained" >/dev/null
nix-build check.nix -A nondeterministic --no-out-link
nix-build check.nix -A nondeterministic -A hashmismatch --no-out-link --check --keep-going || status=$?
[ "$status" = "110" ]
# basic check that diff hooks are started at all
STDERR=$(expectStderr 104 nix-build check.nix -A nondeterministic \
--diff-hook "$PWD/diff-hook.sh" \
--run-diff-hook \
--check 2>&1)
grep "diff-hook ran" <<<"$STDERR"
+3
View File
@@ -0,0 +1,3 @@
#!/usr/bin/env bash
echo diff-hook ran