From c0dd111af1999515b08bbfd95d8623a73b5fbc88 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 27 Mar 2024 20:47:51 +0100 Subject: [PATCH 1/3] Fix flake evaluation in chroot stores This is a temporary fix until we can pass `SourcePath`s rather than `StorePath`s to `call-flake.nix`. Fixes #10331. --- src/libexpr/flake/flake.cc | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/libexpr/flake/flake.cc b/src/libexpr/flake/flake.cc index bca473453..4a781beb8 100644 --- a/src/libexpr/flake/flake.cc +++ b/src/libexpr/flake/flake.cc @@ -10,6 +10,7 @@ #include "finally.hh" #include "fetch-settings.hh" #include "value-to-json.hh" +#include "local-fs-store.hh" namespace nix { @@ -755,7 +756,17 @@ void callFlake(EvalState & state, auto lockedNode = node.dynamic_pointer_cast(); - auto [storePath, subdir] = state.store->toStorePath(sourcePath.path.abs()); + // FIXME: This is a hack to support chroot stores. Remove this + // once we can pass a sourcePath rather than a storePath to + // call-flake.nix. + auto path = sourcePath.path.abs(); + if (auto store = state.store.dynamic_pointer_cast()) { + auto realStoreDir = store->getRealStoreDir(); + if (isInDir(path, realStoreDir)) + path = store->storeDir + path.substr(realStoreDir.size()); + } + + auto [storePath, subdir] = state.store->toStorePath(path); emitTreeAttrs( state, From dffc22f30fd5f25861809bc5d9ae8405390035df Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 29 Mar 2024 12:51:14 +0100 Subject: [PATCH 2/3] Rename local-store.sh -> chroot-store.sh --- tests/functional/{local-store.sh => chroot-store.sh} | 0 tests/functional/local.mk | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename tests/functional/{local-store.sh => chroot-store.sh} (100%) diff --git a/tests/functional/local-store.sh b/tests/functional/chroot-store.sh similarity index 100% rename from tests/functional/local-store.sh rename to tests/functional/chroot-store.sh diff --git a/tests/functional/local.mk b/tests/functional/local.mk index 8bb8e3600..ca9837d32 100644 --- a/tests/functional/local.mk +++ b/tests/functional/local.mk @@ -83,7 +83,7 @@ nix_tests = \ export.sh \ config.sh \ add.sh \ - local-store.sh \ + chroot-store.sh \ filter-source.sh \ misc.sh \ dump-db.sh \ From 89307728649cd96cb82fba739c014c1e78a6fc31 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 29 Mar 2024 13:19:36 +0100 Subject: [PATCH 3/3] Add regression test for #10331, #10267 --- tests/functional/chroot-store.sh | 41 +++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/tests/functional/chroot-store.sh b/tests/functional/chroot-store.sh index f7c8eb3f1..9e589d04b 100644 --- a/tests/functional/chroot-store.sh +++ b/tests/functional/chroot-store.sh @@ -1,22 +1,45 @@ source common.sh -cd $TEST_ROOT +echo example > $TEST_ROOT/example.txt +mkdir -p $TEST_ROOT/x -echo example > example.txt -mkdir -p ./x +export NIX_STORE_DIR=/nix2/store -NIX_STORE_DIR=$TEST_ROOT/x +CORRECT_PATH=$(cd $TEST_ROOT && nix-store --store ./x --add example.txt) -CORRECT_PATH=$(nix-store --store ./x --add example.txt) +[[ $CORRECT_PATH =~ ^/nix2/store/.*-example.txt$ ]] -PATH1=$(nix path-info --store ./x $CORRECT_PATH) +PATH1=$(cd $TEST_ROOT && nix path-info --store ./x $CORRECT_PATH) [ $CORRECT_PATH == $PATH1 ] -PATH2=$(nix path-info --store "$PWD/x" $CORRECT_PATH) +PATH2=$(nix path-info --store "$TEST_ROOT/x" $CORRECT_PATH) [ $CORRECT_PATH == $PATH2 ] -PATH3=$(nix path-info --store "local?root=$PWD/x" $CORRECT_PATH) +PATH3=$(nix path-info --store "local?root=$TEST_ROOT/x" $CORRECT_PATH) [ $CORRECT_PATH == $PATH3 ] # Ensure store info trusted works with local store -nix --store ./x store info --json | jq -e '.trusted' +nix --store $TEST_ROOT/x store info --json | jq -e '.trusted' + +# Test building in a chroot store. +if canUseSandbox; then + + flakeDir=$TEST_ROOT/flake + mkdir -p $flakeDir + + cat > $flakeDir/flake.nix <