diff --git a/src/libexpr-c/nix_api_external.cc b/src/libexpr-c/nix_api_external.cc index ff2950448c6..ee500619fc1 100644 --- a/src/libexpr-c/nix_api_external.cc +++ b/src/libexpr-c/nix_api_external.cc @@ -153,7 +153,7 @@ class NixCExternalValue : public nix::ExternalValueBase bool location, nix::XMLWriter & doc, nix::NixStringContext & context, - nix::PathSet & drvsSeen, + nix::StringSet & drvsSeen, const nix::PosIdx pos) const override { if (!desc.printValueAsXML) { diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index dddc87ff512..b51c8fa303a 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -368,7 +368,7 @@ EvalState::EvalState( EvalState::~EvalState() {} -void EvalState::allowPathLegacy(const Path & path) +void EvalState::allowPathLegacy(const std::string & path) { if (auto rootFS2 = rootFS.dynamic_pointer_cast()) rootFS2->allowPrefix(CanonPath(path)); diff --git a/src/libexpr/include/nix/expr/eval-settings.hh b/src/libexpr/include/nix/expr/eval-settings.hh index ceddff9ef82..b6aacc1186d 100644 --- a/src/libexpr/include/nix/expr/eval-settings.hh +++ b/src/libexpr/include/nix/expr/eval-settings.hh @@ -268,7 +268,7 @@ struct EvalSettings : Config See [Using the `eval-profiler`](@docroot@/advanced-topics/eval-profiler.md). )"}; - Setting evalProfileFile{ + Setting evalProfileFile{ this, "nix.profile", "eval-profile-file", diff --git a/src/libexpr/include/nix/expr/eval.hh b/src/libexpr/include/nix/expr/eval.hh index 68ed79fcde6..35c023b05e3 100644 --- a/src/libexpr/include/nix/expr/eval.hh +++ b/src/libexpr/include/nix/expr/eval.hh @@ -548,7 +548,7 @@ public: /** * Variant which accepts relative paths too. */ - SourcePath rootPath(PathView path); + SourcePath rootPath(std::string_view path); /** * Return a `SourcePath` that refers to `path` in the store. @@ -565,7 +565,7 @@ public: * Only for restrict eval: pure eval just whitelist store paths, * never arbitrary paths. */ - void allowPathLegacy(const Path & path); + void allowPathLegacy(const std::string & path); /** * Allow access to a store path. Note that this gets remapped to diff --git a/src/libexpr/include/nix/expr/value.hh b/src/libexpr/include/nix/expr/value.hh index 3a478c4bfd2..e1b2bc4e25a 100644 --- a/src/libexpr/include/nix/expr/value.hh +++ b/src/libexpr/include/nix/expr/value.hh @@ -155,7 +155,7 @@ public: bool location, XMLWriter & doc, NixStringContext & context, - PathSet & drvsSeen, + StringSet & drvsSeen, const PosIdx pos) const; virtual ~ExternalValueBase() {}; diff --git a/src/libexpr/parser.y b/src/libexpr/parser.y index da042d7fb58..e5e4241ea7b 100644 --- a/src/libexpr/parser.y +++ b/src/libexpr/parser.y @@ -422,6 +422,7 @@ path_start .pos = state->positions[CUR_POS] }); }); + /* Absolute paths are always interpreted relative to the root filesystem accessor, rather than the accessor of the current Nix expression. */ @@ -463,7 +464,7 @@ path_start .pos = state->positions[CUR_POS] }); }); - Path path(getHome().string() + std::string($1.p + 1, $1.l - 1)); + auto path(getHome().string() + std::string($1.p + 1, $1.l - 1)); $$ = state->exprs.add(state->exprs.alloc, state->rootFS, path); } ; diff --git a/src/libexpr/paths.cc b/src/libexpr/paths.cc index a8d2d39b70d..08c2a45abb0 100644 --- a/src/libexpr/paths.cc +++ b/src/libexpr/paths.cc @@ -10,7 +10,7 @@ SourcePath EvalState::rootPath(CanonPath path) return {rootFS, std::move(path)}; } -SourcePath EvalState::rootPath(PathView path) +SourcePath EvalState::rootPath(std::string_view path) { return {rootFS, CanonPath(absPath(path).string())}; } diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index 57a2656ab14..22fc911cb70 100644 --- a/src/libexpr/primops.cc +++ b/src/libexpr/primops.cc @@ -2827,7 +2827,7 @@ static void addPath( std::unique_ptr filter; if (filterFun) - filter = std::make_unique([&](const Path & p) { + filter = std::make_unique([&](const std::string & p) { auto p2 = CanonPath(p); return state.callPathFilter(filterFun, {path.accessor, p2}, pos); }); diff --git a/src/libexpr/value-to-xml.cc b/src/libexpr/value-to-xml.cc index 974927c7e67..f2b004753a6 100644 --- a/src/libexpr/value-to-xml.cc +++ b/src/libexpr/value-to-xml.cc @@ -21,7 +21,7 @@ static void printValueAsXML( Value & v, XMLWriter & doc, NixStringContext & context, - PathSet & drvsSeen, + StringSet & drvsSeen, const PosIdx pos); static void posToXML(EvalState & state, XMLAttrs & xmlAttrs, const Pos & pos) @@ -39,7 +39,7 @@ static void showAttrs( const Bindings & attrs, XMLWriter & doc, NixStringContext & context, - PathSet & drvsSeen) + StringSet & drvsSeen) { StringSet names; @@ -61,7 +61,7 @@ static void printValueAsXML( Value & v, XMLWriter & doc, NixStringContext & context, - PathSet & drvsSeen, + StringSet & drvsSeen, const PosIdx pos) { checkInterrupt(); @@ -99,7 +99,7 @@ static void printValueAsXML( if (state.isDerivation(v)) { XMLAttrs xmlAttrs; - Path drvPath; + std::string drvPath; if (auto a = v.attrs()->get(state.s.drvPath)) { if (strict) state.forceValue(*a->value, a->pos); @@ -185,7 +185,7 @@ void ExternalValueBase::printValueAsXML( bool location, XMLWriter & doc, NixStringContext & context, - PathSet & drvsSeen, + StringSet & drvsSeen, const PosIdx pos) const { doc.writeEmptyElement("unevaluated"); @@ -202,7 +202,7 @@ void printValueAsXML( { XMLWriter doc(true, out); XMLOpenElement root(doc, "expr"); - PathSet drvsSeen; + StringSet drvsSeen; printValueAsXML(state, strict, location, v, doc, context, drvsSeen, pos); } diff --git a/src/libfetchers/git.cc b/src/libfetchers/git.cc index b9cdc9dccdf..f6ae63c815e 100644 --- a/src/libfetchers/git.cc +++ b/src/libfetchers/git.cc @@ -635,7 +635,9 @@ struct GitInputScheme : InputScheme // Why are we checking for bare repository? // well if it's a bare repository we want to force a git fetch rather than copying the folder - auto isBareRepository = [](PathView path) { return pathExists(path) && !pathExists(path + "/.git"); }; + auto isBareRepository = [](const std::filesystem::path & path) { + return pathExists(path) && !pathExists(path / ".git"); + }; // FIXME: here we turn a possibly relative path into an absolute path. // This allows relative git flake inputs to be resolved against the @@ -647,7 +649,7 @@ struct GitInputScheme : InputScheme // auto maybeUrlFsPathForFileUrl = url.scheme == "file" ? std::make_optional(urlPathToPath(url.path)) : std::nullopt; - if (maybeUrlFsPathForFileUrl && !forceHttp && !isBareRepository(maybeUrlFsPathForFileUrl->string())) { + if (maybeUrlFsPathForFileUrl && !forceHttp && !isBareRepository(*maybeUrlFsPathForFileUrl)) { auto & path = *maybeUrlFsPathForFileUrl; if (!path.is_absolute()) { diff --git a/src/libfetchers/mercurial.cc b/src/libfetchers/mercurial.cc index 187d25f340d..38fe31fcade 100644 --- a/src/libfetchers/mercurial.cc +++ b/src/libfetchers/mercurial.cc @@ -245,7 +245,7 @@ struct MercurialInputScheme : InputScheme auto actualPath = absPath(localPath); - PathFilter filter = [&](const Path & p) -> bool { + PathFilter filter = [&](const std::string & p) -> bool { assert(hasPrefix(p, actualPath.string())); std::string file(p, actualPath.string().size() + 1); diff --git a/src/libflake-c/nix_api_flake.cc b/src/libflake-c/nix_api_flake.cc index 990aa66fcb4..cbf5430f54a 100644 --- a/src/libflake-c/nix_api_flake.cc +++ b/src/libflake-c/nix_api_flake.cc @@ -62,7 +62,7 @@ nix_err nix_flake_reference_parse_flags_set_base_directory( { nix_clear_err(context); try { - flags->baseDirectory.emplace(nix::Path{std::string(baseDirectory, baseDirectoryLen)}); + flags->baseDirectory.emplace(std::string(baseDirectory, baseDirectoryLen)); return NIX_OK; } NIXC_CATCH_ERRS diff --git a/src/libflake/include/nix/flake/flakeref.hh b/src/libflake/include/nix/flake/flakeref.hh index 05c21bd1c6d..b557433a9fb 100644 --- a/src/libflake/include/nix/flake/flakeref.hh +++ b/src/libflake/include/nix/flake/flakeref.hh @@ -50,8 +50,10 @@ struct FlakeRef /** * sub-path within the fetched input that represents this input + * + * @todo Should probably use `CanonPath` instead of `std::string`? */ - Path subdir; + std::string subdir; bool operator==(const FlakeRef & other) const = default; @@ -60,7 +62,7 @@ struct FlakeRef return std::tie(input, subdir) < std::tie(other.input, other.subdir); } - FlakeRef(fetchers::Input && input, const Path & subdir) + FlakeRef(fetchers::Input && input, const std::string & subdir) : input(std::move(input)) , subdir(subdir) { diff --git a/src/libstore-test-support/include/nix/store/tests/protocol.hh b/src/libstore-test-support/include/nix/store/tests/protocol.hh index 4d62a0078ce..563c8cfb6c4 100644 --- a/src/libstore-test-support/include/nix/store/tests/protocol.hh +++ b/src/libstore-test-support/include/nix/store/tests/protocol.hh @@ -21,14 +21,14 @@ class ProtoTest : public CharacterizationTest } public: - Path storeDir = "/nix/store"; + std::string storeDir = "/nix/store"; StoreDirConfig store{storeDir}; /** * Golden test for `T` JSON reading */ template - void readJsonTest(PathView testStem, const T & expected) + void readJsonTest(std::string_view testStem, const T & expected) { nix::readJsonTest(*this, testStem, expected); } @@ -37,7 +37,7 @@ public: * Golden test for `T` JSON write */ template - void writeJsonTest(PathView testStem, const T & decoded) + void writeJsonTest(std::string_view testStem, const T & decoded) { nix::writeJsonTest(*this, testStem, decoded); } @@ -51,7 +51,7 @@ public: * Golden test for `T` reading */ template - void readProtoTest(PathView testStem, typename Proto::Version version, T expected) + void readProtoTest(std::string_view testStem, typename Proto::Version version, T expected) { CharacterizationTest::readTest(std::string{testStem + ".bin"}, [&](const auto & encoded) { T got = ({ @@ -72,7 +72,7 @@ public: * Golden test for `T` write */ template - void writeProtoTest(PathView testStem, typename Proto::Version version, const T & decoded) + void writeProtoTest(std::string_view testStem, typename Proto::Version version, const T & decoded) { CharacterizationTest::writeTest(std::string{testStem + ".bin"}, [&]() { StringSink to; diff --git a/src/libstore-tests/common-protocol.cc b/src/libstore-tests/common-protocol.cc index f318c8ec631..d63cbeeeed2 100644 --- a/src/libstore-tests/common-protocol.cc +++ b/src/libstore-tests/common-protocol.cc @@ -21,7 +21,7 @@ class CommonProtoTest : public ProtoTest * Golden test for `T` reading */ template - void readProtoTest(PathView testStem, const T & expected) + void readProtoTest(std::string_view testStem, const T & expected) { CharacterizationTest::readTest(std::string{testStem + ".bin"}, [&](const auto & encoded) { T got = ({ @@ -37,7 +37,7 @@ class CommonProtoTest : public ProtoTest * Golden test for `T` write */ template - void writeProtoTest(PathView testStem, const T & decoded) + void writeProtoTest(std::string_view testStem, const T & decoded) { CharacterizationTest::writeTest(std::string{testStem + ".bin"}, [&]() -> std::string { StringSink to; diff --git a/src/libstore-tests/derivation/external-formats.cc b/src/libstore-tests/derivation/external-formats.cc index 056eeaa8a96..a9be99f996e 100644 --- a/src/libstore-tests/derivation/external-formats.cc +++ b/src/libstore-tests/derivation/external-formats.cc @@ -23,17 +23,17 @@ TEST_F(DynDerivationTest, BadATerm_oldVersionDynDeps) FormatError); } -#define MAKE_OUTPUT_JSON_TEST_P(FIXTURE) \ - TEST_P(FIXTURE, from_json) \ - { \ - const auto & [name, expected] = GetParam(); \ - readJsonTest(Path{"output-"} + name, expected, mockXpSettings); \ - } \ - \ - TEST_P(FIXTURE, to_json) \ - { \ - const auto & [name, value] = GetParam(); \ - writeJsonTest("output-" + name, value); \ +#define MAKE_OUTPUT_JSON_TEST_P(FIXTURE) \ + TEST_P(FIXTURE, from_json) \ + { \ + const auto & [name, expected] = GetParam(); \ + readJsonTest(std::string{"output-"} + name, expected, mockXpSettings); \ + } \ + \ + TEST_P(FIXTURE, to_json) \ + { \ + const auto & [name, value] = GetParam(); \ + writeJsonTest(std::string{"output-"} + name, value); \ } struct DerivationOutputJsonTest : DerivationTest, diff --git a/src/libstore-tests/dummy-store.cc b/src/libstore-tests/dummy-store.cc index 4a12dcf78c0..e3422fe585f 100644 --- a/src/libstore-tests/dummy-store.cc +++ b/src/libstore-tests/dummy-store.cc @@ -73,7 +73,7 @@ TEST_P(DummyStoreJsonTest, from_json) using namespace nlohmann; /* Cannot use `readJsonTest` because need to dereference the stores for equality. */ - readTest(Path{name} + ".json", [&](const auto & encodedRaw) { + readTest(std::string{name} + ".json", [&](const auto & encodedRaw) { auto encoded = json::parse(encodedRaw); ref decoded = adl_serializer>::from_json(encoded); ASSERT_EQ(*decoded, *expected); diff --git a/src/libstore-tests/nar-info.cc b/src/libstore-tests/nar-info.cc index e71575d2d44..9b0f6018cde 100644 --- a/src/libstore-tests/nar-info.cc +++ b/src/libstore-tests/nar-info.cc @@ -15,7 +15,7 @@ class NarInfoTestV1 : public CharacterizationTest, public LibStoreTest { std::filesystem::path unitTestData = getUnitTestData() / "nar-info" / "json-1"; - std::filesystem::path goldenMaster(PathView testStem) const override + std::filesystem::path goldenMaster(std::string_view testStem) const override { return unitTestData / (testStem + ".json"); } @@ -25,7 +25,7 @@ class NarInfoTestV2 : public CharacterizationTest, public LibStoreTest { std::filesystem::path unitTestData = getUnitTestData() / "nar-info" / "json-2"; - std::filesystem::path goldenMaster(PathView testStem) const override + std::filesystem::path goldenMaster(std::string_view testStem) const override { return unitTestData / (testStem + ".json"); } diff --git a/src/libstore-tests/path-info.cc b/src/libstore-tests/path-info.cc index 05bcf2c117d..97ad4b270ad 100644 --- a/src/libstore-tests/path-info.cc +++ b/src/libstore-tests/path-info.cc @@ -14,7 +14,7 @@ class PathInfoTestV1 : public CharacterizationTest, public LibStoreTest { std::filesystem::path unitTestData = getUnitTestData() / "path-info" / "json-1"; - std::filesystem::path goldenMaster(PathView testStem) const override + std::filesystem::path goldenMaster(std::string_view testStem) const override { return unitTestData / (testStem + ".json"); } @@ -24,7 +24,7 @@ class PathInfoTestV2 : public CharacterizationTest, public LibStoreTest { std::filesystem::path unitTestData = getUnitTestData() / "path-info" / "json-2"; - std::filesystem::path goldenMaster(PathView testStem) const override + std::filesystem::path goldenMaster(std::string_view testStem) const override { return unitTestData / (testStem + ".json"); } diff --git a/src/libstore-tests/store-reference.cc b/src/libstore-tests/store-reference.cc index d4d273a8ef9..e83fc97234f 100644 --- a/src/libstore-tests/store-reference.cc +++ b/src/libstore-tests/store-reference.cc @@ -15,7 +15,7 @@ class StoreReferenceTest : public CharacterizationTest, public LibStoreTest { std::filesystem::path unitTestData = getUnitTestData() / "store-reference"; - std::filesystem::path goldenMaster(PathView testStem) const override + std::filesystem::path goldenMaster(std::string_view testStem) const override { return unitTestData / (testStem + ".txt"); } diff --git a/src/libstore/build/derivation-building-goal.cc b/src/libstore/build/derivation-building-goal.cc index 00ae1a248ce..bff5cb8d93e 100644 --- a/src/libstore/build/derivation-building-goal.cc +++ b/src/libstore/build/derivation-building-goal.cc @@ -163,7 +163,9 @@ Goal::Co DerivationBuildingGoal::gaveUpOnSubstitution(bool storeDerivation) /* Second, the input sources. */ worker.store.computeFSClosure(drv->inputSrcs, inputPaths); - debug("added input paths %s", worker.store.showPaths(inputPaths)); + debug("added input paths %s", concatMapStringsSep(", ", inputPaths, [&](auto & p) { + return "'" + worker.store.printStorePath(p) + "'"; + })); /* Okay, try to build. Note that here we don't wait for a build slot to become available, since we don't need one if there is a @@ -397,7 +399,11 @@ Goal::Co DerivationBuildingGoal::tryToBuild(StorePathSet inputPaths) if (!outputLocks.lockPaths(lockFiles, "", false)) { Activity act( - *logger, lvlWarn, actBuildWaiting, fmt("waiting for lock on %s", Magenta(showPaths(lockFiles)))); + *logger, + lvlWarn, + actBuildWaiting, + fmt("waiting for lock on %s", + Magenta(concatMapStringsSep(", ", lockFiles, [](auto & p) { return "'" + p.string() + "'"; })))); /* Wait then try locking again, repeat until success (returned boolean is true). */ diff --git a/src/libstore/build/derivation-check.cc b/src/libstore/build/derivation-check.cc index e56b9fe49a1..c422897e624 100644 --- a/src/libstore/build/derivation-check.cc +++ b/src/libstore/build/derivation-check.cc @@ -14,9 +14,9 @@ void checkOutputs( const decltype(DerivationOptions::outputChecks) & outputChecks, const std::map & outputs) { - std::map outputsByPath; + std::map outputsByPath; for (auto & output : outputs) - outputsByPath.emplace(store.printStorePath(output.second.path), output.second); + outputsByPath.emplace(output.second.path, output.second); for (auto & pair : outputs) { // We can't use auto destructuring here because @@ -69,7 +69,7 @@ void checkOutputs( if (!pathsDone.insert(path).second) continue; - auto i = outputsByPath.find(store.printStorePath(path)); + auto i = outputsByPath.find(path); if (i != outputsByPath.end()) { closureSize += i->second.narSize; for (auto & ref : i->second.references) diff --git a/src/libstore/builtins/buildenv.cc b/src/libstore/builtins/buildenv.cc index f8482081233..3dd66be2cca 100644 --- a/src/libstore/builtins/buildenv.cc +++ b/src/libstore/builtins/buildenv.cc @@ -123,10 +123,10 @@ void buildProfile(const std::filesystem::path & out, Packages && pkgs) { State state; - PathSet done, postponed; + std::set done, postponed; auto addPkg = [&](const std::filesystem::path & pkgDir, int priority) { - if (!done.insert(pkgDir.string()).second) + if (!done.insert(pkgDir).second) return; createLinks(state, pkgDir, out, priority); @@ -159,7 +159,7 @@ void buildProfile(const std::filesystem::path & out, Packages && pkgs) */ auto priorityCounter = 1000; while (!postponed.empty()) { - PathSet pkgDirs; + std::set pkgDirs; postponed.swap(pkgDirs); for (const auto & pkgDir : pkgDirs) addPkg(pkgDir, priorityCounter++); diff --git a/src/libstore/gc.cc b/src/libstore/gc.cc index e82d9dcf168..16b81abf282 100644 --- a/src/libstore/gc.cc +++ b/src/libstore/gc.cc @@ -540,7 +540,8 @@ void LocalStore::collectGarbage(const GCOptions & options, GCResults & results) GCLimitReached if we've deleted enough garbage. */ auto deleteFromStore = [&](std::string_view baseName, bool isKnownPath) { assert(!std::filesystem::path(baseName).is_absolute()); - Path path = storeDir + "/" + std::string(baseName); + /* Using `std::string` since this is the logical store dir. Hopefully that is the right choice. */ + std::string path = storeDir + "/" + std::string(baseName); auto realPath = config->realStoreDir.get() / std::string(baseName); /* There may be temp directories in the store that are still in use diff --git a/src/libstore/globals.cc b/src/libstore/globals.cc index 13fc42b128e..2e262aec8a0 100644 --- a/src/libstore/globals.cc +++ b/src/libstore/globals.cc @@ -120,7 +120,7 @@ Settings::Settings() }) { sandboxPaths.get().insert_or_assign(std::string{p}, ChrootPath{.source = std::string{p}}); } - allowedImpureHostPrefixes = tokenizeString("/System/Library /usr/lib /dev /bin/sh"); + allowedImpureHostPrefixes = std::set{"/System/Library", "/usr/lib", "/dev", "/bin/sh"}; #endif } diff --git a/src/libstore/include/nix/store/binary-cache-store.hh b/src/libstore/include/nix/store/binary-cache-store.hh index 07184ec81c8..cebf091522c 100644 --- a/src/libstore/include/nix/store/binary-cache-store.hh +++ b/src/libstore/include/nix/store/binary-cache-store.hh @@ -39,13 +39,13 @@ struct BinaryCacheStoreConfig : virtual StoreConfig fetch debug info on demand )"}; - Setting secretKeyFile{ + Setting secretKeyFile{ this, "", "secret-key", "Path to the secret key used to sign the binary cache."}; Setting secretKeyFiles{ this, "", "secret-keys", "List of comma-separated paths to the secret keys used to sign the binary cache."}; - Setting> localNarCache{ + Setting> localNarCache{ this, std::nullopt, "local-nar-cache", diff --git a/src/libstore/include/nix/store/builtins.hh b/src/libstore/include/nix/store/builtins.hh index 7da41621298..66ac0433842 100644 --- a/src/libstore/include/nix/store/builtins.hh +++ b/src/libstore/include/nix/store/builtins.hh @@ -13,11 +13,11 @@ namespace nix { struct BuiltinBuilderContext { const BasicDerivation & drv; - std::map outputs; + std::map outputs; std::string netrcData; std::string caFileData; Strings hashedMirrors; - Path tmpDirInSandbox; + std::filesystem::path tmpDirInSandbox; #if NIX_WITH_AWS_AUTH /** diff --git a/src/libstore/include/nix/store/common-ssh-store-config.hh b/src/libstore/include/nix/store/common-ssh-store-config.hh index 1fdb1675bdb..42b3415b777 100644 --- a/src/libstore/include/nix/store/common-ssh-store-config.hh +++ b/src/libstore/include/nix/store/common-ssh-store-config.hh @@ -14,7 +14,7 @@ struct CommonSSHStoreConfig : virtual StoreConfig CommonSSHStoreConfig(const ParsedURL::Authority & authority, const Params & params); - Setting sshKey{ + Setting sshKey{ this, "", "ssh-key", "Path to the SSH private key used to authenticate to the remote machine."}; Setting sshPublicHostKey{ diff --git a/src/libstore/include/nix/store/derivations.hh b/src/libstore/include/nix/store/derivations.hh index 05e42200449..78f0f5dc8d9 100644 --- a/src/libstore/include/nix/store/derivations.hh +++ b/src/libstore/include/nix/store/derivations.hh @@ -274,7 +274,10 @@ struct BasicDerivation */ StorePathSet inputSrcs; std::string platform; - Path builder; + /** + * Probably should be an absolute path in the path format that `platform` uses + */ + std::string builder; Strings args; /** * Must not contain the key `__json`, at least in order to serialize to ATerm. diff --git a/src/libstore/include/nix/store/filetransfer.hh b/src/libstore/include/nix/store/filetransfer.hh index e34c3692a27..340ad856ccc 100644 --- a/src/libstore/include/nix/store/filetransfer.hh +++ b/src/libstore/include/nix/store/filetransfer.hh @@ -95,7 +95,7 @@ public: Nix to use for downloads. )"}; - Setting netrcFile{ + Setting netrcFile{ this, nixConfDir() / "netrc", "netrc-file", @@ -122,7 +122,7 @@ public: > `.netrc`. )"}; - Setting> caFile{ + Setting> caFile{ this, getDefaultSSLCertFile(), "ssl-cert-file", diff --git a/src/libstore/include/nix/store/gc-store.hh b/src/libstore/include/nix/store/gc-store.hh index d5617d6d5c4..de016e241de 100644 --- a/src/libstore/include/nix/store/gc-store.hh +++ b/src/libstore/include/nix/store/gc-store.hh @@ -66,7 +66,7 @@ struct GCResults * Depending on the action, the GC roots, or the paths that would * be or have been deleted. */ - PathSet paths; + StringSet paths; /** * For `gcDeleteDead` and `gcDeleteSpecific`, the number of bytes that were freed. diff --git a/src/libstore/include/nix/store/http-binary-cache-store.hh b/src/libstore/include/nix/store/http-binary-cache-store.hh index 7138c56667f..765eb6dd513 100644 --- a/src/libstore/include/nix/store/http-binary-cache-store.hh +++ b/src/libstore/include/nix/store/http-binary-cache-store.hh @@ -36,10 +36,10 @@ struct HttpBinaryCacheStoreConfig : std::enable_shared_from_this> tlsCert{ + Setting> tlsCert{ this, std::nullopt, "tls-certificate", "Path to an optional TLS client certificate in PEM format."}; - Setting> tlsKey{ + Setting> tlsKey{ this, std::nullopt, "tls-private-key", "Path to an optional TLS client certificate private key in PEM format."}; static const std::string name() diff --git a/src/libstore/include/nix/store/local-fs-store.hh b/src/libstore/include/nix/store/local-fs-store.hh index 7e0d095ada1..d4f8c965ef9 100644 --- a/src/libstore/include/nix/store/local-fs-store.hh +++ b/src/libstore/include/nix/store/local-fs-store.hh @@ -10,8 +10,8 @@ namespace nix { struct LocalFSStoreConfig : virtual StoreConfig { private: - static Setting> - makeRootDirSetting(LocalFSStoreConfig & self, std::optional defaultValue) + static Setting> + makeRootDirSetting(LocalFSStoreConfig & self, std::optional defaultValue) { return { &self, @@ -33,7 +33,7 @@ public: */ LocalFSStoreConfig(const std::filesystem::path & path, const Params & params); - Setting> rootDir = makeRootDirSetting(*this, std::nullopt); + Setting> rootDir = makeRootDirSetting(*this, std::nullopt); private: @@ -51,21 +51,21 @@ private: public: - Setting stateDir{ + Setting stateDir{ this, rootDir.get() ? *rootDir.get() / "nix" / "var" / "nix" : getDefaultStateDir(), "state", "Directory where Nix stores state.", }; - Setting logDir{ + Setting logDir{ this, rootDir.get() ? *rootDir.get() / "nix" / "var" / "log" / "nix" : getDefaultLogDir(), "log", "directory where Nix stores log files.", }; - Setting realStoreDir{ + Setting realStoreDir{ this, rootDir.get() ? *rootDir.get() / "nix" / "store" : std::filesystem::path{storeDir}, "real", diff --git a/src/libstore/include/nix/store/local-overlay-store.hh b/src/libstore/include/nix/store/local-overlay-store.hh index 007ef0eed0c..5d8ec1b4571 100644 --- a/src/libstore/include/nix/store/local-overlay-store.hh +++ b/src/libstore/include/nix/store/local-overlay-store.hh @@ -31,7 +31,7 @@ struct LocalOverlayStoreConfig : virtual LocalStoreConfig Must be used as OverlayFS lower layer for this store's store dir. )"}; - const Setting upperLayer{ + const Setting upperLayer{ (StoreConfig *) this, "", "upper-layer", @@ -53,7 +53,7 @@ struct LocalOverlayStoreConfig : virtual LocalStoreConfig default, but can be disabled if needed. )"}; - const Setting remountHook{ + const Setting remountHook{ (StoreConfig *) this, "", "remount-hook", diff --git a/src/libstore/include/nix/store/local-settings.hh b/src/libstore/include/nix/store/local-settings.hh index d16f004321e..af7eccdf44f 100644 --- a/src/libstore/include/nix/store/local-settings.hh +++ b/src/libstore/include/nix/store/local-settings.hh @@ -439,7 +439,7 @@ struct LocalSettings : public virtual Config, public GCSettings, public AutoAllo #endif #if defined(__linux__) || defined(__FreeBSD__) - Setting sandboxBuildDir{ + Setting sandboxBuildDir{ this, "/build", "sandbox-build-dir", @@ -452,7 +452,7 @@ struct LocalSettings : public virtual Config, public GCSettings, public AutoAllo )"}; #endif - Setting> buildDir{ + Setting> buildDir{ this, std::nullopt, "build-dir", @@ -462,7 +462,7 @@ struct LocalSettings : public virtual Config, public GCSettings, public AutoAllo See also the per-store [`build-dir`](@docroot@/store/types/local-store.md#store-local-store-build-dir) setting. )"}; - Setting allowedImpureHostPrefixes{ + Setting> allowedImpureHostPrefixes{ this, {}, "allowed-impure-host-deps", @@ -490,7 +490,7 @@ struct LocalSettings : public virtual Config, public GCSettings, public AutoAllo private: - Setting> diffHook{ + Setting> diffHook{ this, std::nullopt, "diff-hook", diff --git a/src/libstore/include/nix/store/local-store.hh b/src/libstore/include/nix/store/local-store.hh index 3d3ca6e589d..1d25c7c0df2 100644 --- a/src/libstore/include/nix/store/local-store.hh +++ b/src/libstore/include/nix/store/local-store.hh @@ -40,7 +40,7 @@ private: /** Input for computing the build directory. See `getBuildDir()`. */ - Setting> buildDir{ + Setting> buildDir{ this, std::nullopt, "build-dir", @@ -244,7 +244,7 @@ public: /** * Hack for build-remote.cc. */ - PathSetNG locksHeld; + PathSet locksHeld; /** * Initialise the local store, upgrading the schema if @@ -478,9 +478,6 @@ private: void updatePathInfo(State & state, const ValidPathInfo & info); - PathSet queryValidPathsOld(); - ValidPathInfo queryPathInfoOld(const Path & path); - void findRoots(const std::filesystem::path & path, std::filesystem::file_type type, Roots & roots); void findRootsNoTemp(Roots & roots, bool censor); diff --git a/src/libstore/include/nix/store/nar-info-disk-cache.hh b/src/libstore/include/nix/store/nar-info-disk-cache.hh index c8a3567c27d..a30c5a553b9 100644 --- a/src/libstore/include/nix/store/nar-info-disk-cache.hh +++ b/src/libstore/include/nix/store/nar-info-disk-cache.hh @@ -25,7 +25,8 @@ struct NarInfoDiskCache virtual ~NarInfoDiskCache() {} - virtual int createCache(const std::string & uri, const Path & storeDir, bool wantMassQuery, int priority) = 0; + virtual int + createCache(const std::string & uri, const std::string & storeDir, bool wantMassQuery, int priority) = 0; struct CacheInfo { diff --git a/src/libstore/include/nix/store/path-references.hh b/src/libstore/include/nix/store/path-references.hh index 6aa506da4a3..ead02e70a74 100644 --- a/src/libstore/include/nix/store/path-references.hh +++ b/src/libstore/include/nix/store/path-references.hh @@ -10,7 +10,7 @@ namespace nix { -StorePathSet scanForReferences(Sink & toTee, const Path & path, const StorePathSet & refs); +StorePathSet scanForReferences(Sink & toTee, const std::filesystem::path & path, const StorePathSet & refs); class PathRefScanSink : public RefScanSink { diff --git a/src/libstore/include/nix/store/remote-fs-accessor.hh b/src/libstore/include/nix/store/remote-fs-accessor.hh index a8c5c8a0a23..19d97a589d0 100644 --- a/src/libstore/include/nix/store/remote-fs-accessor.hh +++ b/src/libstore/include/nix/store/remote-fs-accessor.hh @@ -34,8 +34,7 @@ public: */ std::shared_ptr accessObject(const StorePath & path); - RemoteFSAccessor( - ref store, bool requireValidPath = true, std::optional cacheDir = {}); + RemoteFSAccessor(ref store, bool requireValidPath = true, std::optional cacheDir = {}); std::optional maybeLstat(const CanonPath & path) override; diff --git a/src/libstore/include/nix/store/store-api.hh b/src/libstore/include/nix/store/store-api.hh index d7454dbff04..b5a6f6c497e 100644 --- a/src/libstore/include/nix/store/store-api.hh +++ b/src/libstore/include/nix/store/store-api.hh @@ -1020,18 +1020,6 @@ void removeTempRoots(); StorePath resolveDerivedPath(Store &, const SingleDerivedPath &, Store * evalStore = nullptr); OutputPathMap resolveDerivedPath(Store &, const DerivedPath::Built &, Store * evalStore = nullptr); -/** - * Display a set of paths in human-readable form (i.e., between quotes - * and separated by commas). - */ -std::string showPaths(const PathSet & paths); - -/** - * Display a set of paths in human-readable form (i.e., between quotes - * and separated by commas). - */ -std::string showPaths(const std::set paths); - std::optional decodeValidPathInfo(const Store & store, std::istream & str, std::optional hashGiven = std::nullopt); diff --git a/src/libstore/include/nix/store/store-dir-config.hh b/src/libstore/include/nix/store/store-dir-config.hh index 78ce4507299..d6d97b4ff6a 100644 --- a/src/libstore/include/nix/store/store-dir-config.hh +++ b/src/libstore/include/nix/store/store-dir-config.hh @@ -1,6 +1,7 @@ #pragma once #include "nix/store/path.hh" +#include "nix/util/canon-path.hh" #include "nix/util/hash.hh" #include "nix/store/content-address.hh" #include "nix/util/configuration.hh" @@ -44,21 +45,19 @@ struct StoreDirConfig * * \todo remove */ - StorePathSet parseStorePathSet(const PathSet & paths) const; + StorePathSet parseStorePathSet(const StringSet & paths) const; - PathSet printStorePathSet(const StorePathSet & path) const; + StringSet printStorePathSet(const StorePathSet & path) const; /** * Display a set of paths in human-readable form (i.e., between quotes * and separated by commas). */ - std::string showPaths(const StorePathSet & paths) const; - /** * @return true if *path* is in the Nix store (but not the Nix * store itself). */ - bool isInStore(PathView path) const; + bool isInStore(std::string_view path) const; /** * @return true if *path* is a store path, i.e. a direct child of the @@ -70,7 +69,7 @@ struct StoreDirConfig * Split a path like `/nix/store/-/` into * `/nix/store/-` and `/`. */ - std::pair toStorePath(PathView path) const; + std::pair toStorePath(std::string_view path) const; /** * Constructs a unique store path name. diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc index ea019ae05f7..8eb3d78daf1 100644 --- a/src/libstore/local-store.cc +++ b/src/libstore/local-store.cc @@ -80,7 +80,7 @@ std::filesystem::path LocalBuildStoreConfig::getBuildDir() const auto & bd = getLocalSettings().buildDir.get(); return bd.has_value() ? *bd : buildDir.get().has_value() ? *buildDir.get() - : std::filesystem::path{stateDir.get()} / "builds"; + : AbsolutePath{stateDir.get() / "builds"}; } ref LocalStore::Config::openStore() const @@ -884,7 +884,7 @@ std::optional LocalStore::queryPathFromHashPart(const std::string & h if (hashPart.size() != StorePath::HashLen) throw Error("invalid hash part"); - Path prefix = storeDir + "/" + hashPart; + std::string prefix = storeDir + "/" + hashPart; return retrySQLite>([&]() -> std::optional { auto state(_state->lock()); @@ -1310,7 +1310,9 @@ void LocalStore::invalidatePathChecked(const StorePath & path) referrers.erase(path); /* ignore self-references */ if (!referrers.empty()) throw PathInUse( - "cannot delete path '%s' because it is in use by %s", printStorePath(path), showPaths(referrers)); + "cannot delete path '%s' because it is in use by %s", + printStorePath(path), + concatMapStringsSep(", ", referrers, [&](auto & p) { return "'" + printStorePath(p) + "'"; })); invalidatePath(*state, path); } diff --git a/src/libstore/nar-info-disk-cache.cc b/src/libstore/nar-info-disk-cache.cc index 5b9315f30a6..3f330753d94 100644 --- a/src/libstore/nar-info-disk-cache.cc +++ b/src/libstore/nar-info-disk-cache.cc @@ -66,7 +66,7 @@ struct NarInfoDiskCacheImpl : NarInfoDiskCache struct Cache { int id; - Path storeDir; + std::string storeDir; bool wantMassQuery; int priority; }; @@ -200,7 +200,7 @@ struct NarInfoDiskCacheImpl : NarInfoDiskCache } public: - int createCache(const std::string & uri, const Path & storeDir, bool wantMassQuery, int priority) override + int createCache(const std::string & uri, const std::string & storeDir, bool wantMassQuery, int priority) override { return retrySQLite([&]() { auto state(_state.lock()); diff --git a/src/libstore/path-references.cc b/src/libstore/path-references.cc index 9571da65cd9..384e9ec5d4c 100644 --- a/src/libstore/path-references.cc +++ b/src/libstore/path-references.cc @@ -47,7 +47,7 @@ StorePathSet PathRefScanSink::getResultPaths() return found; } -StorePathSet scanForReferences(Sink & toTee, const Path & path, const StorePathSet & refs) +StorePathSet scanForReferences(Sink & toTee, const std::filesystem::path & path, const StorePathSet & refs) { PathRefScanSink refsSink = PathRefScanSink::fromPaths(refs); TeeSink sink{refsSink, toTee}; diff --git a/src/libstore/remote-fs-accessor.cc b/src/libstore/remote-fs-accessor.cc index b52baadd0d4..4d83240a2db 100644 --- a/src/libstore/remote-fs-accessor.cc +++ b/src/libstore/remote-fs-accessor.cc @@ -2,8 +2,7 @@ namespace nix { -RemoteFSAccessor::RemoteFSAccessor( - ref store, bool requireValidPath, std::optional cacheDir) +RemoteFSAccessor::RemoteFSAccessor(ref store, bool requireValidPath, std::optional cacheDir) : store(store) , narCache(cacheDir) , requireValidPath(requireValidPath) @@ -15,7 +14,7 @@ std::pair, CanonPath> RemoteFSAccessor::fetch(const CanonPat auto [storePath, restPath] = store->toStorePath(store->storeDir + path.abs()); if (requireValidPath && !store->isValidPath(storePath)) throw InvalidPath("path '%1%' is not a valid store path", store->printStorePath(storePath)); - return {ref{accessObject(storePath)}, CanonPath{restPath}}; + return {ref{accessObject(storePath)}, restPath}; } std::shared_ptr RemoteFSAccessor::accessObject(const StorePath & storePath) diff --git a/src/libstore/remote-store.cc b/src/libstore/remote-store.cc index f317e906e41..133b7a81b1e 100644 --- a/src/libstore/remote-store.cc +++ b/src/libstore/remote-store.cc @@ -695,7 +695,7 @@ Roots RemoteStore::findRoots(bool censor) size_t count = readNum(conn->from); Roots result; while (count--) { - Path link = readString(conn->from); + std::string link = readString(conn->from); result[WorkerProto::Serialise::read(*this, *conn)].emplace(link); } return result; @@ -715,7 +715,7 @@ void RemoteStore::collectGarbage(const GCOptions & options, GCResults & results) conn.processStderr(); - results.paths = readStrings(conn->from); + results.paths = readStrings(conn->from); results.bytesFreed = readLongLong(conn->from); readLongLong(conn->from); // obsolete diff --git a/src/libstore/store-api.cc b/src/libstore/store-api.cc index 641163b598e..845e7bcb37a 100644 --- a/src/libstore/store-api.cc +++ b/src/libstore/store-api.cc @@ -69,20 +69,20 @@ StoreConfig::StoreConfig(const Params & params) { } -bool StoreDirConfig::isInStore(PathView path) const +bool StoreDirConfig::isInStore(std::string_view path) const { return isInDir(path, storeDir); } -std::pair StoreDirConfig::toStorePath(PathView path) const +std::pair StoreDirConfig::toStorePath(std::string_view path) const { if (!isInStore(path)) throw Error("path '%1%' is not in the Nix store", path); auto slash = path.find('/', storeDir.size() + 1); - if (slash == Path::npos) - return {parseStorePath(path), ""}; + if (slash == std::string::npos) + return {parseStorePath(path), CanonPath::root}; else - return {parseStorePath(path.substr(0, slash)), (Path) path.substr(slash)}; + return {parseStorePath(path.substr(0, slash)), CanonPath{path.substr(slash)}}; } std::filesystem::path Store::followLinksToStore(std::string_view _path) const @@ -1183,27 +1183,6 @@ decodeValidPathInfo(const Store & store, std::istream & str, std::optional(std::move(info)); } -std::string StoreDirConfig::showPaths(const StorePathSet & paths) const -{ - std::string s; - for (auto & i : paths) { - if (s.size() != 0) - s += ", "; - s += "'" + printStorePath(i) + "'"; - } - return s; -} - -std::string showPaths(const std::set paths) -{ - return concatStringsSep(", ", quoteFSPaths(paths)); -} - -std::string showPaths(const PathSet & paths) -{ - return concatStringsSep(", ", quoteStrings(paths)); -} - Derivation Store::derivationFromPath(const StorePath & drvPath) { ensurePath(drvPath); diff --git a/src/libstore/store-dir-config.cc b/src/libstore/store-dir-config.cc index 0e835e178c8..61f82029d79 100644 --- a/src/libstore/store-dir-config.cc +++ b/src/libstore/store-dir-config.cc @@ -39,7 +39,7 @@ bool StoreDirConfig::isStorePath(std::string_view path) const return (bool) maybeParseStorePath(path); } -StorePathSet StoreDirConfig::parseStorePathSet(const PathSet & paths) const +StorePathSet StoreDirConfig::parseStorePathSet(const StringSet & paths) const { StorePathSet res; for (auto & i : paths) @@ -52,9 +52,9 @@ std::string StoreDirConfig::printStorePath(const StorePath & path) const return (storeDir + "/").append(path.to_string()); } -PathSet StoreDirConfig::printStorePathSet(const StorePathSet & paths) const +StringSet StoreDirConfig::printStorePathSet(const StorePathSet & paths) const { - PathSet res; + StringSet res; for (auto & i : paths) res.insert(printStorePath(i)); return res; diff --git a/src/libstore/unix/build/darwin-derivation-builder.cc b/src/libstore/unix/build/darwin-derivation-builder.cc index 336e402d0b5..e9999d455b3 100644 --- a/src/libstore/unix/build/darwin-derivation-builder.cc +++ b/src/libstore/unix/build/darwin-derivation-builder.cc @@ -67,7 +67,7 @@ struct DarwinDerivationBuilder : DerivationBuilderImpl if (useSandbox) { /* Lots and lots and lots of file functions freak out if they can't stat their full ancestry */ - PathSet ancestry; + StringSet ancestry; /* We build the ancestry before adding all inputPaths to the store because we know they'll all have the same parents (the store), and there might be lots of inputs. This isn't diff --git a/src/libstore/unix/build/derivation-builder.cc b/src/libstore/unix/build/derivation-builder.cc index aa140103b43..46ebf866176 100644 --- a/src/libstore/unix/build/derivation-builder.cc +++ b/src/libstore/unix/build/derivation-builder.cc @@ -895,7 +895,7 @@ PathsInChroot DerivationBuilderImpl::getPathsInSandbox() } pathsInChroot[tmpDirInSandbox()] = {.source = tmpDir}; - PathSet allowedPaths = localSettings.allowedImpureHostPrefixes; + auto allowedPaths = localSettings.allowedImpureHostPrefixes.get(); /* This works like the above, except on a per-derivation level */ auto impurePaths = drvOptions.impureHostDeps; diff --git a/src/libutil-test-support/include/nix/util/tests/characterization.hh b/src/libutil-test-support/include/nix/util/tests/characterization.hh index 52321828f5d..6dd5f38866d 100644 --- a/src/libutil-test-support/include/nix/util/tests/characterization.hh +++ b/src/libutil-test-support/include/nix/util/tests/characterization.hh @@ -28,7 +28,7 @@ struct CharacterizationTest : virtual ::testing::Test * While the "golden master" for this characterization test is * located. It should not be shared with any other test. */ - virtual std::filesystem::path goldenMaster(PathView testStem) const = 0; + virtual std::filesystem::path goldenMaster(std::string_view testStem) const = 0; /** * Golden test for reading @@ -36,7 +36,7 @@ struct CharacterizationTest : virtual ::testing::Test * @param test hook that takes the contents of the file and does the * actual work */ - void readTest(PathView testStem, auto && test) + void readTest(std::string_view testStem, auto && test) { auto file = goldenMaster(testStem); @@ -53,7 +53,7 @@ struct CharacterizationTest : virtual ::testing::Test * @param test hook that produces contents of the file and does the * actual work */ - void writeTest(PathView testStem, auto && test, auto && readFile2, auto && writeFile2) + void writeTest(std::string_view testStem, auto && test, auto && readFile2, auto && writeFile2) { auto file = goldenMaster(testStem); @@ -72,7 +72,7 @@ struct CharacterizationTest : virtual ::testing::Test /** * Specialize to `std::string` */ - void writeTest(PathView testStem, auto && test) + void writeTest(std::string_view testStem, auto && test) { writeTest( testStem, diff --git a/src/libutil-test-support/include/nix/util/tests/json-characterization.hh b/src/libutil-test-support/include/nix/util/tests/json-characterization.hh index 744880f38e2..d0f4f9c495a 100644 --- a/src/libutil-test-support/include/nix/util/tests/json-characterization.hh +++ b/src/libutil-test-support/include/nix/util/tests/json-characterization.hh @@ -16,10 +16,10 @@ namespace nix { * Golden test for JSON reading */ template -void readJsonTest(CharacterizationTest & test, PathView testStem, const T & expected, auto... args) +void readJsonTest(CharacterizationTest & test, std::string_view testStem, const T & expected, auto... args) { using namespace nlohmann; - test.readTest(Path{testStem} + ".json", [&](const auto & encodedRaw) { + test.readTest(std::string{testStem} + ".json", [&](const auto & encodedRaw) { auto encoded = json::parse(encodedRaw); T decoded = adl_serializer::from_json(encoded, args...); ASSERT_EQ(decoded, expected); @@ -30,11 +30,11 @@ void readJsonTest(CharacterizationTest & test, PathView testStem, const T & expe * Golden test for JSON writing */ template -void writeJsonTest(CharacterizationTest & test, PathView testStem, const T & value) +void writeJsonTest(CharacterizationTest & test, std::string_view testStem, const T & value) { using namespace nlohmann; test.writeTest( - Path{testStem} + ".json", + std::string{testStem} + ".json", [&]() -> json { return static_cast(value); }, [](const auto & file) { return json::parse(readFile(file)); }, [](const auto & file, const auto & got) { return writeFile(file, got.dump(2) + "\n"); }); @@ -49,11 +49,11 @@ void writeJsonTest(CharacterizationTest & test, PathView testStem, const T & val * pointer), so we break the symmetry as the best remaining option. */ template -void writeJsonTest(CharacterizationTest & test, PathView testStem, const ref & value) +void writeJsonTest(CharacterizationTest & test, std::string_view testStem, const ref & value) { using namespace nlohmann; test.writeTest( - Path{testStem} + ".json", + std::string{testStem} + ".json", [&]() -> json { return static_cast(*value); }, [](const auto & file) { return json::parse(readFile(file)); }, [](const auto & file, const auto & got) { return writeFile(file, got.dump(2) + "\n"); }); @@ -63,11 +63,11 @@ void writeJsonTest(CharacterizationTest & test, PathView testStem, const ref * Golden test in the middle of something */ template -void checkpointJson(CharacterizationTest & test, PathView testStem, const T & got) +void checkpointJson(CharacterizationTest & test, std::string_view testStem, const T & got) { using namespace nlohmann; - auto file = test.goldenMaster(Path{testStem} + ".json"); + auto file = test.goldenMaster(std::string{testStem} + ".json"); json gotJson = static_cast(got); @@ -88,11 +88,11 @@ void checkpointJson(CharacterizationTest & test, PathView testStem, const T & go * direction, but "`const T &` -> JSON" in the other direction. */ template -void checkpointJson(CharacterizationTest & test, PathView testStem, const ref & got) +void checkpointJson(CharacterizationTest & test, std::string_view testStem, const ref & got) { using namespace nlohmann; - auto file = test.goldenMaster(Path{testStem} + ".json"); + auto file = test.goldenMaster(std::string{testStem} + ".json"); json gotJson = static_cast(*got); @@ -121,7 +121,7 @@ struct JsonCharacterizationTest : virtual CharacterizationTest * @param test hook that takes the contents of the file and does the * actual work */ - void readJsonTest(PathView testStem, const T & expected, auto... args) + void readJsonTest(std::string_view testStem, const T & expected, auto... args) { nix::readJsonTest(*this, testStem, expected, args...); } @@ -132,12 +132,12 @@ struct JsonCharacterizationTest : virtual CharacterizationTest * @param test hook that produces contents of the file and does the * actual work */ - void writeJsonTest(PathView testStem, const T & value) + void writeJsonTest(std::string_view testStem, const T & value) { nix::writeJsonTest(*this, testStem, value); } - void checkpointJson(PathView testStem, const T & value) + void checkpointJson(std::string_view testStem, const T & value) { nix::checkpointJson(*this, testStem, value); } diff --git a/src/libutil-tests/memory-source-accessor.cc b/src/libutil-tests/memory-source-accessor.cc index 0b262ea4359..d9a48da0ceb 100644 --- a/src/libutil-tests/memory-source-accessor.cc +++ b/src/libutil-tests/memory-source-accessor.cc @@ -248,7 +248,7 @@ TEST_P(MemorySourceAccessorJsonTest, from_json) auto & [name, expected] = GetParam(); /* Cannot use `readJsonTest` because need to compare `root` field of the source accessors for equality. */ - readTest(Path{name} + ".json", [&](const auto & encodedRaw) { + readTest(std::string{name} + ".json", [&](const auto & encodedRaw) { auto encoded = json::parse(encodedRaw); auto decoded = static_cast(encoded); ASSERT_EQ(decoded.root, expected.root); diff --git a/src/libutil/configuration.cc b/src/libutil/configuration.cc index 0262a30e206..297d4221f18 100644 --- a/src/libutil/configuration.cc +++ b/src/libutil/configuration.cc @@ -394,6 +394,28 @@ std::string BaseSetting::to_string() const return concatStringsSep(" ", value); } +template<> +std::set BaseSetting>::parse(const std::string & str) const +{ + auto tokens = tokenizeString(str); + return {tokens.begin(), tokens.end()}; +} + +template<> +void BaseSetting>::appendOrSet(std::set newValue, bool append) +{ + if (!append) + value.clear(); + value.insert(std::make_move_iterator(newValue.begin()), std::make_move_iterator(newValue.end())); +} + +template<> +std::string BaseSetting>::to_string() const +{ + return concatStringsSep( + " ", value | std::views::transform([](const auto & p) { return p.string(); }) | std::ranges::to()); +} + template<> std::set BaseSetting>::parse(const std::string & str) const { @@ -461,7 +483,7 @@ std::string BaseSetting::to_string() const [](const auto & kvpair) { return kvpair.first + "=" + kvpair.second; }); } -static std::filesystem::path parsePath(const AbstractSetting & s, const std::string & str) +static AbsolutePath parseAbsolutePath(const AbstractSetting & s, const std::string & str) { if (str == "") throw UsageError("setting '%s' is a path and paths cannot be empty", s.name); @@ -472,7 +494,9 @@ static std::filesystem::path parsePath(const AbstractSetting & s, const std::str template<> std::filesystem::path BaseSetting::parse(const std::string & str) const { - return parsePath(*this, str); + if (str == "") + throw UsageError("setting '%s' is a path and paths cannot be empty", name); + return str; } template<> @@ -482,17 +506,28 @@ std::string BaseSetting::to_string() const } template<> -std::optional -BaseSetting>::parse(const std::string & str) const +AbsolutePath BaseSetting::parse(const std::string & str) const +{ + return parseAbsolutePath(*this, str); +} + +template<> +std::string BaseSetting::to_string() const +{ + return value.string(); +} + +template<> +std::optional BaseSetting>::parse(const std::string & str) const { if (str == "") return std::nullopt; else - return parsePath(*this, str); + return parseAbsolutePath(*this, str); } template<> -std::string BaseSetting>::to_string() const +std::string BaseSetting>::to_string() const { return value ? value->string() : ""; } @@ -511,7 +546,8 @@ template class BaseSetting; template class BaseSetting; template class BaseSetting>; template class BaseSetting; -template class BaseSetting>; +template class BaseSetting; +template class BaseSetting>; template class BaseSetting>; bool ExperimentalFeatureSettings::isEnabled(const ExperimentalFeature & feature) const diff --git a/src/libutil/current-process.cc b/src/libutil/current-process.cc index b2c6548b25c..8f7150c97de 100644 --- a/src/libutil/current-process.cc +++ b/src/libutil/current-process.cc @@ -154,7 +154,7 @@ std::optional getSelfExe() // serialized to JSON and evaluated as a Nix string. path.pop_back(); - return Path(path.begin(), path.end()); + return std::string(path.begin(), path.end()); #else return std::nullopt; #endif diff --git a/src/libutil/file-system.cc b/src/libutil/file-system.cc index f62ab03216b..e1efca0ddf7 100644 --- a/src/libutil/file-system.cc +++ b/src/libutil/file-system.cc @@ -701,8 +701,7 @@ void moveFile(const std::filesystem::path & oldName, const std::filesystem::path auto newPath = newName; // For the move to be as atomic as possible, copy to a temporary // directory - std::filesystem::path temp = - createTempDir(os_string_to_string(PathViewNG{newPath.parent_path()}), "rename-tmp"); + std::filesystem::path temp = createTempDir(os_string_to_string(PathView{newPath.parent_path()}), "rename-tmp"); Finally removeTemp = [&]() { std::filesystem::remove(temp); }; auto tempCopyTarget = temp / "copy-target"; if (e.code().value() == EXDEV) { @@ -710,7 +709,7 @@ void moveFile(const std::filesystem::path & oldName, const std::filesystem::path warn("can’t rename %s as %s, copying instead", PathFmt(oldName), PathFmt(newName)); copyFile(oldPath, tempCopyTarget, true); std::filesystem::rename( - os_string_to_string(PathViewNG{tempCopyTarget}), os_string_to_string(PathViewNG{newPath})); + os_string_to_string(PathView{tempCopyTarget}), os_string_to_string(PathView{newPath})); } } } diff --git a/src/libutil/include/nix/util/config-impl.hh b/src/libutil/include/nix/util/config-impl.hh index 8f6f9a358a4..88d82394f31 100644 --- a/src/libutil/include/nix/util/config-impl.hh +++ b/src/libutil/include/nix/util/config-impl.hh @@ -136,7 +136,9 @@ DECLARE_CONFIG_SERIALISER(StringSet) DECLARE_CONFIG_SERIALISER(StringMap) DECLARE_CONFIG_SERIALISER(std::set) DECLARE_CONFIG_SERIALISER(std::filesystem::path) -DECLARE_CONFIG_SERIALISER(std::optional) +DECLARE_CONFIG_SERIALISER(AbsolutePath) +DECLARE_CONFIG_SERIALISER(std::set) +DECLARE_CONFIG_SERIALISER(std::optional) template T BaseSetting::parse(const std::string & str) const diff --git a/src/libutil/include/nix/util/configuration.hh b/src/libutil/include/nix/util/configuration.hh index f09b194baa0..446b68f3d33 100644 --- a/src/libutil/include/nix/util/configuration.hh +++ b/src/libutil/include/nix/util/configuration.hh @@ -2,11 +2,13 @@ ///@file #include +#include #include #include #include +#include "nix/util/json-non-null.hh" #include "nix/util/types.hh" #include "nix/util/experimental-features.hh" @@ -216,6 +218,30 @@ protected: bool isOverridden() const; }; +/** + * For `Setting`. `parse()` calls `canonPath`, + * rejecting empty and relative paths. + */ +struct AbsolutePath : std::filesystem::path +{ + using path::path; + using path::operator=; + + AbsolutePath(const std::filesystem::path & p) + : path(p) + { + } + + AbsolutePath(std::filesystem::path && p) + : path(std::move(p)) + { + } +}; + +template<> +struct json_avoids_null : std::true_type +{}; + /** * A setting of type T. */ @@ -379,6 +405,9 @@ public: } }; +template<> +void BaseSetting>::appendOrSet(std::set newValue, bool append); + struct ExperimentalFeatureSettings : Config { diff --git a/src/libutil/include/nix/util/file-path.hh b/src/libutil/include/nix/util/file-path.hh index 52dae32ff35..f570dcec341 100644 --- a/src/libutil/include/nix/util/file-path.hh +++ b/src/libutil/include/nix/util/file-path.hh @@ -11,30 +11,26 @@ namespace nix { /** * Paths are just `std::filesystem::path`s. - * - * @todo drop `NG` suffix and replace the ones in `types.hh`. */ -typedef std::list PathsNG; -typedef std::set PathSetNG; +typedef std::list Paths; +typedef std::set PathSet; /** * Stop gap until `std::filesystem::path_view` from P1030R6 exists in a * future C++ standard. - * - * @todo drop `NG` suffix and replace the one in `types.hh`. */ -struct PathViewNG : OsStringView +struct PathView : OsStringView { using string_view = OsStringView; using string_view::string_view; - PathViewNG(const std::filesystem::path & path) + PathView(const std::filesystem::path & path) : OsStringView{path.native()} { } - PathViewNG(const OsString & path) + PathView(const OsString & path) : OsStringView{path} { } @@ -52,7 +48,7 @@ struct PathViewNG : OsStringView std::optional maybePath(PathView path); -std::filesystem::path pathNG(PathView path); +std::filesystem::path toOwnedPath(PathView path); template<> struct json_avoids_null : std::true_type diff --git a/src/libutil/include/nix/util/file-system.hh b/src/libutil/include/nix/util/file-system.hh index 6fd4f325391..7838a3f4407 100644 --- a/src/libutil/include/nix/util/file-system.hh +++ b/src/libutil/include/nix/util/file-system.hh @@ -357,7 +357,7 @@ public: return _path; } - PathViewNG view() const + PathView view() const { return _path; } @@ -367,7 +367,7 @@ public: return _path; } - operator PathViewNG() const + operator PathView() const { return _path; } diff --git a/src/libutil/include/nix/util/logging.hh b/src/libutil/include/nix/util/logging.hh index 4673895aad6..e58b71c8b9e 100644 --- a/src/libutil/include/nix/util/logging.hh +++ b/src/libutil/include/nix/util/logging.hh @@ -54,7 +54,7 @@ struct LoggerSettings : Config expression evaluation errors. )"}; - Setting> jsonLogPath{ + Setting> jsonLogPath{ this, {}, "json-log-path", diff --git a/src/libutil/include/nix/util/types.hh b/src/libutil/include/nix/util/types.hh index f8c6c097958..9bc1428c310 100644 --- a/src/libutil/include/nix/util/types.hh +++ b/src/libutil/include/nix/util/types.hh @@ -44,20 +44,6 @@ using StringPairs = StringMap; */ using StringSet = std::set>; -/** - * Paths are just strings. - */ -typedef std::string Path; -typedef std::string_view PathView; -typedef std::list Paths; - -/** - * Alias to an ordered set of `Path`s. Uses transparent comparator. - * - * @see StringSet - */ -using PathSet = std::set>; - typedef std::vector> Headers; /** diff --git a/src/libutil/serialise.cc b/src/libutil/serialise.cc index eee6f3cdaeb..b2648c323f0 100644 --- a/src/libutil/serialise.cc +++ b/src/libutil/serialise.cc @@ -531,8 +531,8 @@ T readStrings(Source & source) return ss; } -template Paths readStrings(Source & source); -template PathSet readStrings(Source & source); +template Strings readStrings(Source & source); +template StringSet readStrings(Source & source); Error readError(Source & source) { diff --git a/src/libutil/unix/file-path.cc b/src/libutil/unix/file-path.cc index d1fcd3a3a08..55ccddb4568 100644 --- a/src/libutil/unix/file-path.cc +++ b/src/libutil/unix/file-path.cc @@ -8,7 +8,7 @@ namespace nix { -std::filesystem::path pathNG(PathView path) +std::filesystem::path toOwnedPath(PathView path) { return {std::string{path}}; } diff --git a/src/libutil/unix/file-system.cc b/src/libutil/unix/file-system.cc index d1fd8aa1b56..55fd7584fbf 100644 --- a/src/libutil/unix/file-system.cc +++ b/src/libutil/unix/file-system.cc @@ -124,7 +124,7 @@ void setWriteTime( } #ifdef __FreeBSD__ -# define MOUNTEDPATHS_PARAM , std::set & mountedPaths +# define MOUNTEDPATHS_PARAM , std::set & mountedPaths # define MOUNTEDPATHS_ARG , mountedPaths #else # define MOUNTEDPATHS_PARAM @@ -257,7 +257,7 @@ void deletePath(const std::filesystem::path & path, uint64_t & bytesFreed) { // Activity act(*logger, lvlDebug, "recursively deleting path '%1%'", path); #ifdef __FreeBSD__ - std::set mountedPaths; + std::set mountedPaths; struct statfs * mntbuf; int count; if ((count = getmntinfo(&mntbuf, MNT_WAIT)) < 0) { diff --git a/src/libutil/windows/file-path.cc b/src/libutil/windows/file-path.cc index 7913b3d5d28..afe43e060b5 100644 --- a/src/libutil/windows/file-path.cc +++ b/src/libutil/windows/file-path.cc @@ -13,26 +13,26 @@ std::optional maybePath(PathView path) { if (path.length() >= 3 && (('A' <= path[0] && path[0] <= 'Z') || ('a' <= path[0] && path[0] <= 'z')) && path[1] == ':' && WindowsPathTrait::isPathSep(path[2])) { - std::filesystem::path::string_type sw = string_to_os_string(std::string{"\\\\?\\"} + path); + std::filesystem::path::string_type sw = std::wstring{L"\\\\?\\"} + std::wstring{path}; std::replace(sw.begin(), sw.end(), '/', '\\'); return sw; } if (path.length() >= 7 && path[0] == '\\' && path[1] == '\\' && (path[2] == '.' || path[2] == '?') && path[3] == '\\' && ('A' <= path[4] && path[4] <= 'Z') && path[5] == ':' && WindowsPathTrait::isPathSep(path[6])) { - std::filesystem::path::string_type sw = string_to_os_string(path); + std::filesystem::path::string_type sw{path}; std::replace(sw.begin(), sw.end(), '/', '\\'); return sw; } return std::optional(); } -std::filesystem::path pathNG(PathView path) +std::filesystem::path toOwnedPath(PathView path) { std::optional sw = maybePath(path); if (!sw) { // FIXME why are we not using the regular error handling? - std::cerr << "invalid path for WinAPI call [" << path << "]" << std::endl; + std::wcerr << L"invalid path for WinAPI call [" << path << L"]" << std::endl; _exit(111); } return *sw; diff --git a/src/nix/build-remote/build-remote.cc b/src/nix/build-remote/build-remote.cc index c986284badb..d46f3011a4e 100644 --- a/src/nix/build-remote/build-remote.cc +++ b/src/nix/build-remote/build-remote.cc @@ -254,7 +254,7 @@ static int main_build_remote(int argc, char ** argv) std::cerr << "# accept\n" << storeUri << "\n"; - auto inputs = readStrings(source); + auto inputs = readStrings(source); auto wantedOutputs = readStrings(source); AutoCloseFD uploadLock; diff --git a/src/nix/cat.cc b/src/nix/cat.cc index d1250ea8eed..7e96e6903f6 100644 --- a/src/nix/cat.cc +++ b/src/nix/cat.cc @@ -48,7 +48,7 @@ struct CmdCatStore : StoreCommand, MixCat void run(ref store) override { auto [storePath, rest] = store->toStorePath(path); - cat(store->requireStoreObjectAccessor(storePath), CanonPath{rest}); + cat(store->requireStoreObjectAccessor(storePath), rest); } }; diff --git a/src/nix/develop.cc b/src/nix/develop.cc index c0e2ed827c8..d093c7f27ff 100644 --- a/src/nix/develop.cc +++ b/src/nix/develop.cc @@ -438,7 +438,7 @@ struct Common : InstallableCommand, MixProfile * that's accessible from the interactive shell session. */ void fixupStructuredAttrs( - PathViewNG::string_view ext, + PathView::string_view ext, const std::string & envVar, const std::string & content, StringMap & rewrites, diff --git a/src/nix/env.cc b/src/nix/env.cc index a80bcda6707..79d187d85e5 100644 --- a/src/nix/env.cc +++ b/src/nix/env.cc @@ -97,7 +97,7 @@ struct CmdShell : InstallablesCommand, MixEnvironment auto propPath = state->storeFS->resolveSymlinks( CanonPath(store->printStorePath(path)) / "nix-support" / "propagated-user-env-packages"); if (auto st = state->storeFS->maybeLstat(propPath); st && st->type == SourceAccessor::tRegular) { - for (auto & p : tokenizeString(state->storeFS->readFile(propPath))) + for (auto & p : tokenizeString(state->storeFS->readFile(propPath))) todo.push(store->parseStorePath(p)); } } diff --git a/src/nix/ls.cc b/src/nix/ls.cc index 9761fc9f732..a9d082fb378 100644 --- a/src/nix/ls.cc +++ b/src/nix/ls.cc @@ -120,7 +120,7 @@ struct CmdLsStore : StoreCommand, MixLs void run(ref store) override { auto [storePath, rest] = store->toStorePath(path); - list(store->requireStoreObjectAccessor(storePath), CanonPath{rest}); + list(store->requireStoreObjectAccessor(storePath), rest); } }; diff --git a/src/nix/nix-copy-closure/nix-copy-closure.cc b/src/nix/nix-copy-closure/nix-copy-closure.cc index 43cf11e4faf..33aec6c3e65 100644 --- a/src/nix/nix-copy-closure/nix-copy-closure.cc +++ b/src/nix/nix-copy-closure/nix-copy-closure.cc @@ -16,7 +16,7 @@ static int main_nix_copy_closure(int argc, char ** argv) auto dryRun = false; auto useSubstitutes = NoSubstitute; std::string sshHost; - PathSet storePaths; + StringSet storePaths; parseCmdLine(argc, argv, [&](Strings::iterator & arg, const Strings::iterator & end) { if (*arg == "--help") diff --git a/src/nix/nix-store/nix-store.cc b/src/nix/nix-store/nix-store.cc index 9eb80fb0554..fb2018cff98 100644 --- a/src/nix/nix-store/nix-store.cc +++ b/src/nix/nix-store/nix-store.cc @@ -69,9 +69,10 @@ static StorePath useDeriver(const StorePath & path) return *info->deriver; } -/* Realise the given path. For a derivation that means build it; for - other paths it means ensure their validity. */ -static PathSet realisePath(StorePathWithOutputs path, bool build = true) +/** + * Because we are downcasting first thing to a `LocalFSStore`, we know it is OK to return local paths. + */ +static std::set realisePath(StorePathWithOutputs path, bool build = true) { auto store2 = std::dynamic_pointer_cast(store); @@ -87,14 +88,14 @@ static PathSet realisePath(StorePathWithOutputs path, bool build = true) for (auto & i : drv.outputs) path.outputs.insert(i.first); - PathSet outputs; + std::set outputs; for (auto & j : path.outputs) { /* Match outputs of a store path with outputs of the derivation that produces it. */ DerivationOutputs::iterator i = drv.outputs.find(j); if (i == drv.outputs.end()) throw Error("derivation '%s' does not have an output named '%s'", store2->printStorePath(path.path), j); auto outPath = outputPaths.at(i->first); - auto retPath = store->printStorePath(outPath); + std::filesystem::path retPath = store->printStorePath(outPath); if (store2) { if (gcRoot == "") printGCWarning(); @@ -104,7 +105,7 @@ static PathSet realisePath(StorePathWithOutputs path, bool build = true) rootName += "-" + std::to_string(rootNr); if (i->first != "out") rootName += "-" + i->first; - retPath = store2->addPermRoot(outPath, rootName).string(); + retPath = store2->addPermRoot(outPath, rootName); } } outputs.insert(retPath); @@ -125,10 +126,10 @@ static PathSet realisePath(StorePathWithOutputs path, bool build = true) rootNr++; if (rootNr > 1) rootName += "-" + std::to_string(rootNr); - return {store2->addPermRoot(path.path, rootName).string()}; + return {store2->addPermRoot(path.path, rootName)}; } } - return {store->printStorePath(path.path)}; + return {std::filesystem::path{store->printStorePath(path.path)}}; } } @@ -181,7 +182,7 @@ static void opRealise(Strings opFlags, Strings opArgs) auto paths2 = realisePath(i, false); if (!noOutput) for (auto & j : paths2) - cout << fmt("%1%\n", j); + cout << fmt("%s\n", j.string()); } }