diff --git a/src/libcmd/installables.cc b/src/libcmd/installables.cc index b93c7f7e8..0d42a62cc 100644 --- a/src/libcmd/installables.cc +++ b/src/libcmd/installables.cc @@ -21,7 +21,6 @@ #include "url.hh" #include "registry.hh" #include "build-result.hh" -#include "fs-input-accessor.hh" #include #include @@ -147,7 +146,7 @@ MixFlakeOptions::MixFlakeOptions() .category = category, .labels = {"flake-lock-path"}, .handler = {[&](std::string lockFilePath) { - lockFlags.referenceLockFilePath = getUnfilteredRootPath(CanonPath(absPath(lockFilePath))); + lockFlags.referenceLockFilePath = {makeFSSourceAccessor(), CanonPath(absPath(lockFilePath))}; }}, .completer = completePath }); diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index fbd846d14..6fd60084d 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -15,7 +15,6 @@ #include "function-trace.hh" #include "profiles.hh" #include "print.hh" -#include "fs-input-accessor.hh" #include "filtering-input-accessor.hh" #include "memory-source-accessor.hh" #include "signals.hh" @@ -400,14 +399,14 @@ EvalState::EvalState( , emptyBindings(0) , rootFS( evalSettings.restrictEval || evalSettings.pureEval - ? ref(AllowListInputAccessor::create(makeFSInputAccessor(), {}, + ? ref(AllowListInputAccessor::create(makeFSSourceAccessor(), {}, [](const CanonPath & path) -> RestrictedPathError { auto modeInformation = evalSettings.pureEval ? "in pure evaluation mode (use '--impure' to override)" : "in restricted mode"; throw RestrictedPathError("access to absolute path '%1%' is forbidden %2%", path, modeInformation); })) - : makeFSInputAccessor()) + : makeFSSourceAccessor()) , corepkgsFS(make_ref()) , internalFS(make_ref()) , derivationInternal{corepkgsFS->addFile( diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index a3ccc9771..109127d1d 100644 --- a/src/libexpr/primops.cc +++ b/src/libexpr/primops.cc @@ -15,7 +15,6 @@ #include "value-to-json.hh" #include "value-to-xml.hh" #include "primops.hh" -#include "fs-input-accessor.hh" #include "fetch-to-store.hh" #include diff --git a/src/libfetchers/fetch-to-store.cc b/src/libfetchers/fetch-to-store.cc index 398286065..c105fe1fc 100644 --- a/src/libfetchers/fetch-to-store.cc +++ b/src/libfetchers/fetch-to-store.cc @@ -14,7 +14,7 @@ StorePath fetchToStore( RepairFlag repair) { // FIXME: add an optimisation for the case where the accessor is - // an FSInputAccessor pointing to a store path. + // a `PosixSourceAccessor` pointing to a store path. std::optional cacheKey; diff --git a/src/libfetchers/fs-input-accessor.cc b/src/libfetchers/fs-input-accessor.cc deleted file mode 100644 index bd4e4e2cd..000000000 --- a/src/libfetchers/fs-input-accessor.cc +++ /dev/null @@ -1,34 +0,0 @@ -#include "fs-input-accessor.hh" -#include "posix-source-accessor.hh" -#include "store-api.hh" - -namespace nix { - -ref makeFSInputAccessor() -{ - return make_ref(); -} - -ref makeFSInputAccessor(std::filesystem::path root) -{ - return make_ref(std::move(root)); -} - -ref makeStorePathAccessor( - ref store, - const StorePath & storePath) -{ - // FIXME: should use `store->getFSAccessor()` - auto root = std::filesystem::path { store->toRealPath(storePath) }; - auto accessor = makeFSInputAccessor(root); - accessor->setPathDisplay(root.string()); - return accessor; -} - -SourcePath getUnfilteredRootPath(CanonPath path) -{ - static auto rootFS = makeFSInputAccessor(); - return {rootFS, path}; -} - -} diff --git a/src/libfetchers/git-utils.cc b/src/libfetchers/git-utils.cc index 5657a6b4f..a91587cb4 100644 --- a/src/libfetchers/git-utils.cc +++ b/src/libfetchers/git-utils.cc @@ -1,5 +1,4 @@ #include "git-utils.hh" -#include "fs-input-accessor.hh" #include "cache.hh" #include "finally.hh" #include "processes.hh" @@ -948,7 +947,7 @@ ref GitRepoImpl::getAccessor(const WorkdirInfo & wd, bool export wd.files.empty() ? makeEmptySourceAccessor() : AllowListInputAccessor::create( - makeFSInputAccessor(path), + makeFSSourceAccessor(path), std::set { wd.files }, std::move(makeNotAllowedError)).cast(); if (exportIgnore) diff --git a/src/libfetchers/path.cc b/src/libfetchers/path.cc index 1e9683ae1..68958d559 100644 --- a/src/libfetchers/path.cc +++ b/src/libfetchers/path.cc @@ -1,8 +1,7 @@ #include "fetchers.hh" #include "store-api.hh" #include "archive.hh" -#include "fs-input-accessor.hh" -#include "posix-source-accessor.hh" +#include "store-path-accessor.hh" namespace nix::fetchers { diff --git a/src/libfetchers/store-path-accessor.cc b/src/libfetchers/store-path-accessor.cc new file mode 100644 index 000000000..6eeeba3e8 --- /dev/null +++ b/src/libfetchers/store-path-accessor.cc @@ -0,0 +1,17 @@ +#include "store-path-accessor.hh" +#include "store-api.hh" + +namespace nix { + +ref makeStorePathAccessor( + ref store, + const StorePath & storePath) +{ + // FIXME: should use `store->getFSAccessor()` + auto root = std::filesystem::path { store->toRealPath(storePath) }; + auto accessor = makeFSSourceAccessor(root); + accessor->setPathDisplay(root.string()); + return accessor; +} + +} diff --git a/src/libfetchers/fs-input-accessor.hh b/src/libfetchers/store-path-accessor.hh similarity index 67% rename from src/libfetchers/fs-input-accessor.hh rename to src/libfetchers/store-path-accessor.hh index 80dc74725..4aa55c4df 100644 --- a/src/libfetchers/fs-input-accessor.hh +++ b/src/libfetchers/store-path-accessor.hh @@ -7,10 +7,6 @@ namespace nix { class StorePath; class Store; -ref makeFSInputAccessor(); - -ref makeFSInputAccessor(std::filesystem::path root); - ref makeStorePathAccessor( ref store, const StorePath & storePath); diff --git a/src/libfetchers/tarball.cc b/src/libfetchers/tarball.cc index 8ebc2c296..33c8f3c0c 100644 --- a/src/libfetchers/tarball.cc +++ b/src/libfetchers/tarball.cc @@ -8,8 +8,7 @@ #include "tarfile.hh" #include "types.hh" #include "split.hh" -#include "posix-source-accessor.hh" -#include "fs-input-accessor.hh" +#include "store-path-accessor.hh" #include "store-api.hh" #include "git-utils.hh" diff --git a/src/libfetchers/unix/git.cc b/src/libfetchers/unix/git.cc index be44b2eda..c8fd295c0 100644 --- a/src/libfetchers/unix/git.cc +++ b/src/libfetchers/unix/git.cc @@ -9,7 +9,6 @@ #include "pathlocks.hh" #include "processes.hh" #include "git.hh" -#include "fs-input-accessor.hh" #include "mounted-input-accessor.hh" #include "git-utils.hh" #include "logging.hh" diff --git a/src/libfetchers/unix/mercurial.cc b/src/libfetchers/unix/mercurial.cc index e85f7e854..4d95f54f0 100644 --- a/src/libfetchers/unix/mercurial.cc +++ b/src/libfetchers/unix/mercurial.cc @@ -6,8 +6,7 @@ #include "tarfile.hh" #include "store-api.hh" #include "url-parts.hh" -#include "fs-input-accessor.hh" -#include "posix-source-accessor.hh" +#include "store-path-accessor.hh" #include "fetch-settings.hh" #include @@ -211,10 +210,9 @@ struct MercurialInputScheme : InputScheme return files.count(file); }; - PosixSourceAccessor accessor; auto storePath = store->addToStore( input.getName(), - accessor, CanonPath { actualPath }, + *makeFSSourceAccessor(), CanonPath { actualPath }, FileIngestionMethod::Recursive, HashAlgorithm::SHA256, {}, filter); @@ -320,8 +318,7 @@ struct MercurialInputScheme : InputScheme deletePath(tmpDir + "/.hg_archival.txt"); - PosixSourceAccessor accessor; - auto storePath = store->addToStore(name, accessor, CanonPath { tmpDir }); + auto storePath = store->addToStore(name, *makeFSSourceAccessor(), CanonPath { tmpDir }); Attrs infoAttrs({ {"rev", input.getRev()->gitRev()}, diff --git a/src/libutil/posix-source-accessor.cc b/src/libutil/posix-source-accessor.cc index a589bfd3d..f7dffb871 100644 --- a/src/libutil/posix-source-accessor.cc +++ b/src/libutil/posix-source-accessor.cc @@ -166,4 +166,14 @@ void PosixSourceAccessor::assertNoSymlinks(CanonPath path) } } +ref makeFSSourceAccessor() +{ + static auto rootFS = make_ref(); + return rootFS; +} + +ref makeFSSourceAccessor(std::filesystem::path root) +{ + return make_ref(std::move(root)); +} } diff --git a/src/libutil/source-accessor.hh b/src/libutil/source-accessor.hh index 5f1afb946..548feddfd 100644 --- a/src/libutil/source-accessor.hh +++ b/src/libutil/source-accessor.hh @@ -194,4 +194,14 @@ ref makeEmptySourceAccessor(); */ MakeError(RestrictedPathError, Error); +/** + * Return an accessor for the root filesystem. + */ +ref makeFSSourceAccessor(); + +/** + * Return an accessor for the filesystem rooted at `root`. + */ +ref makeFSSourceAccessor(std::filesystem::path root); + } diff --git a/tests/unit/libexpr/primops.cc b/tests/unit/libexpr/primops.cc index 10c250d74..5b5898237 100644 --- a/tests/unit/libexpr/primops.cc +++ b/tests/unit/libexpr/primops.cc @@ -2,6 +2,7 @@ #include #include "eval-settings.hh" +#include "memory-source-accessor.hh" #include "tests/libexpr.hh"