Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/libcmd/include/nix/cmd/command.hh
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ void createOutLinks(const std::filesystem::path & outLink, const BuiltPaths & bu
struct MixOutLinkBase : virtual Args
{
/** Prefix for any output symlinks. Empty means do not write an output symlink. */
Path outLink;
std::filesystem::path outLink;

MixOutLinkBase(const std::string & defaultOutLink)
: outLink(defaultOutLink)
Expand Down Expand Up @@ -435,7 +435,7 @@ struct MixOutLinkByDefault : MixOutLinkBase, virtual Args
addFlag({
.longName = "no-link",
.description = "Do not create symlinks to the build results.",
.handler = {&outLink, Path("")},
.handler = {&outLink, std::filesystem::path{}},
});
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/libcmd/installables.cc
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ MixFlakeOptions::MixFlakeOptions()
.category = category,
.labels = {"flake-lock-path"},
.handler = {[&](std::string lockFilePath) {
lockFlags.referenceLockFilePath = {getFSSourceAccessor(), CanonPath(absPath(lockFilePath))};
lockFlags.referenceLockFilePath = {getFSSourceAccessor(), CanonPath(absPath(lockFilePath).string())};
}},
.completer = completePath,
});
Expand Down
2 changes: 1 addition & 1 deletion src/libcmd/repl-interacter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ ReadlineLikeInteracter::Guard ReadlineLikeInteracter::init(detail::ReplCompleter
// Allow nix-repl specific settings in .inputrc
rl_readline_name = "nix-repl";
try {
createDirs(dirOf(historyFile));
createDirs(std::filesystem::path(historyFile).parent_path());
} catch (SystemError & e) {
logWarning(e.info());
}
Expand Down
2 changes: 1 addition & 1 deletion src/libexpr/eval-cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ struct AttrDb
{
auto state(_state->lock());

auto cacheDir = std::filesystem::path(getCacheDir()) / "eval-cache-v6";
auto cacheDir = getCacheDir() / "eval-cache-v6";
createDirs(cacheDir);

auto dbPath = cacheDir / (fingerprint.to_string(HashFormat::Base16, false) + ".sqlite");
Expand Down
7 changes: 7 additions & 0 deletions src/libexpr/eval-error.cc
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
#include "nix/expr/eval-error.hh"
#include "nix/expr/eval.hh"
#include "nix/expr/value.hh"
#include "nix/store/store-api.hh"

namespace nix {

InvalidPathError::InvalidPathError(EvalState & state, const StorePath & path)
: EvalError(state, "path '%s' is not valid", state.store->printStorePath(path))
, path{path}
{
}

template<class T>
EvalErrorBuilder<T> & EvalErrorBuilder<T>::withExitStatus(unsigned int exitStatus)
{
Expand Down
2 changes: 1 addition & 1 deletion src/libexpr/eval-settings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Strings EvalSettings::getDefaultNixPath()
}
};

add(std::filesystem::path{getNixDefExpr()} / "channels");
add(getNixDefExpr() / "channels");
auto profilesDirOpts = settings.getProfileDirsOptions();
add(rootChannelsDir(profilesDirOpts) / "nixpkgs", "nixpkgs");
add(rootChannelsDir(profilesDirOpts));
Expand Down
2 changes: 1 addition & 1 deletion src/libexpr/eval.cc
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ void EvalState::checkURI(const std::string & uri)

/* If the URI is a path, then check it against allowedPaths as
well. */
if (isAbsolute(uri)) {
if (std::filesystem::path(uri).is_absolute()) {
if (auto rootFS2 = rootFS.dynamic_pointer_cast<AllowListSourceAccessor>())
rootFS2->checkAccess(CanonPath(uri));
return;
Expand Down
7 changes: 2 additions & 5 deletions src/libexpr/include/nix/expr/eval-error.hh
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,9 @@ MakeError(IFDError, EvalBaseError);
struct InvalidPathError : public EvalError
{
public:
Path path;
StorePath path;

InvalidPathError(EvalState & state, const Path & path)
: EvalError(state, "path '%s' is not valid", path)
{
}
InvalidPathError(EvalState & state, const StorePath & path);
};

/**
Expand Down
3 changes: 2 additions & 1 deletion src/libexpr/parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,8 @@ path_start
});
}

Path path(absPath(literal, state->basePath.path.abs()));
auto basePath = std::filesystem::path(state->basePath.path.abs());
Path path(absPath(literal, &basePath).string());
/* add back in the trailing '/' to the first segment */
if (literal.size() > 1 && literal.back() == '/')
path += '/';
Expand Down
2 changes: 1 addition & 1 deletion src/libexpr/paths.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ SourcePath EvalState::rootPath(CanonPath path)

SourcePath EvalState::rootPath(PathView path)
{
return {rootFS, CanonPath(absPath(path))};
return {rootFS, CanonPath(absPath(std::filesystem::path{path}).string())};
}

SourcePath EvalState::storePath(const StorePath & path)
Expand Down
8 changes: 4 additions & 4 deletions src/libexpr/primops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ StringMap EvalState::realiseContext(const NixStringContext & context, StorePathS
for (auto & c : context) {
auto ensureValid = [&](const StorePath & p) {
if (!store->isValidPath(p))
error<InvalidPathError>(store->printStorePath(p)).debugThrow();
error<InvalidPathError>(p).debugThrow();
};
std::visit(
overloaded{
Expand Down Expand Up @@ -503,7 +503,7 @@ void prim_exec(EvalState & state, const PosIdx pos, Value ** args, Value & v)
try {
auto _ = state.realiseContext(context); // FIXME: Handle CA derivations
} catch (InvalidPathError & e) {
state.error<EvalError>("cannot execute '%1%', since path '%2%' is not valid", program, e.path)
state.error<EvalError>("cannot execute '%1%', since path '%2%' is not valid", program, e.path.to_string())
.atPos(pos)
.debugThrow();
}
Expand Down Expand Up @@ -1931,7 +1931,7 @@ static void prim_storePath(EvalState & state, const PosIdx pos, Value ** args, V
directly in the store. The latter condition is necessary so
e.g. nix-push does the right thing. */
if (!state.store->isStorePath(path.abs()))
path = CanonPath(canonPath(path.abs(), true));
path = CanonPath(canonPath(path.abs(), true).string());
if (!state.store->isInStore(path.abs()))
state.error<EvalError>("path '%1%' is not in the Nix store", path).atPos(pos).debugThrow();
auto path2 = state.store->toStorePath(path.abs()).first;
Expand Down Expand Up @@ -2152,7 +2152,7 @@ static void prim_findFile(EvalState & state, const PosIdx pos, Value ** args, Va
auto rewrites = state.realiseContext(context);
path = rewriteStrings(std::move(path), rewrites);
} catch (InvalidPathError & e) {
state.error<EvalError>("cannot find '%1%', since path '%2%' is not valid", path, e.path)
state.error<EvalError>("cannot find '%1%', since path '%2%' is not valid", path, state.store->printStorePath(e.path))
.atPos(pos)
.debugThrow();
}
Expand Down
4 changes: 2 additions & 2 deletions src/libfetchers/cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ struct CacheImpl : Cache
{
auto state(_state.lock());

auto dbPath = (getCacheDir() / "fetcher-cache-v4.sqlite").string();
createDirs(dirOf(dbPath));
auto dbPath = getCacheDir() / "fetcher-cache-v4.sqlite";
createDirs(dbPath.parent_path());

state->db = SQLite(dbPath, {.useWAL = nix::settings.useSQLiteWAL});
state->db.isCache();
Expand Down
4 changes: 2 additions & 2 deletions src/libfetchers/git-lfs-fetch.cc
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,10 @@ void Fetch::fetch(
return;
}

std::filesystem::path cacheDir = getCacheDir() / "git-lfs";
auto cacheDir = getCacheDir() / "git-lfs";
std::string key = hashString(HashAlgorithm::SHA256, pointerFilePath.rel()).to_string(HashFormat::Base16, false)
+ "/" + pointer->oid;
std::filesystem::path cachePath = cacheDir / key;
auto cachePath = cacheDir / key;
if (pathExists(cachePath)) {
debug("using cache entry %s -> %s", key, PathFmt(cachePath));
sink(readFile(cachePath));
Expand Down
2 changes: 1 addition & 1 deletion src/libfetchers/git-utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ struct GitRepoImpl : GitRepo, std::enable_shared_from_this<GitRepoImpl>
.program = "git",
.args =
{"-c",
"gpg.ssh.allowedSignersFile=" + allowedSignersFile,
"gpg.ssh.allowedSignersFile=" + allowedSignersFile.string(),
"-C",
path.string(),
"verify-commit",
Expand Down
7 changes: 4 additions & 3 deletions src/libfetchers/git.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ static bool isCacheFileWithinTtl(const Settings & settings, time_t now, const Po

std::filesystem::path getCachePath(std::string_view key, bool shallow)
{
return getCacheDir() / "gitv3"
/ (hashString(HashAlgorithm::SHA256, key).to_string(HashFormat::Nix32, false) + (shallow ? "-shallow" : ""));
auto name =
hashString(HashAlgorithm::SHA256, key).to_string(HashFormat::Nix32, false) + (shallow ? "-shallow" : "");
return getCacheDir() / "gitv3" / std::move(name);
}

// Returns the name of the HEAD branch.
Expand Down Expand Up @@ -629,7 +630,7 @@ struct GitInputScheme : InputScheme
if (url.scheme == "file" && !forceHttp && !isBareRepository(renderUrlPathEnsureLegal(url.path))) {
auto path = renderUrlPathEnsureLegal(url.path);

if (!isAbsolute(path)) {
if (!std::filesystem::path(path).is_absolute()) {
warn(
"Fetching Git repository '%s', which uses a path relative to the current directory. "
"This is not supported and will stop working in a future release. "
Expand Down
2 changes: 1 addition & 1 deletion src/libfetchers/mercurial.cc
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ struct MercurialInputScheme : InputScheme
}
}
} else {
createDirs(dirOf(cacheDir.string()));
createDirs(cacheDir.parent_path());
runHg({"clone", "--noupdate", "--", actualUrl, cacheDir.string()});
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/libfetchers/path.cc
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ struct PathInputScheme : InputScheme
std::optional<std::string> isRelative(const Input & input) const override
{
auto path = getStrAttr(input.attrs, "path");
if (isAbsolute(path))
if (std::filesystem::path(path).is_absolute())
return std::nullopt;
else
return path;
Expand All @@ -132,7 +132,7 @@ struct PathInputScheme : InputScheme
{
auto path = getStrAttr(input.attrs, "path");

if (isAbsolute(path))
if (std::filesystem::path(path).is_absolute())
return canonPath(path);

throw Error("cannot fetch input '%s' because it uses a relative path", input.to_string());
Expand Down
4 changes: 2 additions & 2 deletions src/libfetchers/registry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,13 @@ static std::shared_ptr<Registry> getGlobalRegistry(const Settings & settings, St
return Registry::read(
settings,
[&] -> SourcePath {
if (!isAbsolute(path)) {
if (!std::filesystem::path(path).is_absolute()) {
auto storePath = downloadFile(store, settings, path, "flake-registry.json").storePath;
if (auto store2 = dynamic_cast<LocalFSStore *>(&store))
store2->addPermRoot(storePath, (getCacheDir() / "flake-registry.json").string());
return {store.requireStoreObjectAccessor(storePath)};
} else {
return SourcePath{getFSSourceAccessor(), CanonPath{path}}.resolveSymlinks();
return SourcePath{makeFSSourceAccessor(path)}.resolveSymlinks();
}
}(),
Registry::Global);
Expand Down
2 changes: 1 addition & 1 deletion src/libfetchers/tarball.cc
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ static DownloadTarballResult downloadTarball_(
auto [fdTemp, path] = createTempFile("nix-zipfile");
cleanupTemp.cancel();
cleanupTemp = {path};
debug("downloading '%s' into '%s'...", url, path);
debug("downloading '%s' into %s...", url, PathFmt(path));
{
FdSink sink(fdTemp.get());
source->drainInto(sink);
Expand Down
2 changes: 1 addition & 1 deletion src/libflake-c/nix_api_flake_internal.hh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ struct nix_flake_settings

struct nix_flake_reference_parse_flags
{
std::optional<nix::Path> baseDirectory;
std::optional<std::filesystem::path> baseDirectory;
};

struct nix_flake_reference
Expand Down
2 changes: 1 addition & 1 deletion src/libflake/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace nix::flake {
// setting name -> setting value -> allow or ignore.
typedef std::map<std::string, std::map<std::string, bool>> TrustedList;

std::filesystem::path trustedListPath()
static std::filesystem::path trustedListPath()
{
return getDataDir() / "trusted-settings.json";
}
Expand Down
22 changes: 14 additions & 8 deletions src/libflake/flakeref.cc
Original file line number Diff line number Diff line change
Expand Up @@ -121,19 +121,23 @@ std::pair<FlakeRef, std::string> parsePathFlakeRefWithFragment(
to 'baseDir'). If so, search upward to the root of the
repo (i.e. the directory containing .git). */

path = absPath(path, baseDir->string(), true);
{
auto baseDirPath = *baseDir;
path = absPath(path, &baseDirPath, true).string();
}

if (isFlake) {

if (!S_ISDIR(lstat(path).st_mode)) {
if (baseNameOf(path) == "flake.nix") {
// Be gentle with people who accidentally write `/foo/bar/flake.nix` instead of `/foo/bar`
auto parentPath = std::filesystem::path(path).parent_path().string();
warn(
"Path '%s' should point at the directory containing the 'flake.nix' file, not the file itself. "
"Pretending that you meant '%s'",
path,
dirOf(path));
path = dirOf(path);
parentPath);
path = parentPath;
} else {
throw BadURL("path '%s' is not a flake (because it's not a directory)", path);
}
Expand All @@ -157,7 +161,7 @@ std::pair<FlakeRef, std::string> parsePathFlakeRefWithFragment(
if (lstat(path).st_dev != device)
throw Error("unable to find a flake before encountering filesystem boundary at '%s'", path);
}
path = dirOf(path);
path = std::filesystem::path(path).parent_path().string();
}
if (!found)
throw BadURL("could not find a flake.nix file");
Expand Down Expand Up @@ -192,12 +196,12 @@ std::pair<FlakeRef, std::string> parsePathFlakeRefWithFragment(
}

subdir = std::string(baseNameOf(flakeRoot)) + (subdir.empty() ? "" : "/" + subdir);
flakeRoot = dirOf(flakeRoot);
flakeRoot = std::filesystem::path(flakeRoot).parent_path().string();
}
}

} else {
if (!preserveRelativePaths && !isAbsolute(path))
if (!preserveRelativePaths && !std::filesystem::path(path).is_absolute())
throw BadURL("flake reference '%s' is not an absolute path", url);
}

Expand Down Expand Up @@ -251,8 +255,10 @@ std::optional<std::pair<FlakeRef, std::string>> parseURLFlakeRef(
if (baseDir && (parsed.scheme == "path" || parsed.scheme == "git+file")) {
/* Here we know that the path must not contain encoded '/' or NUL bytes. */
auto path = renderUrlPathEnsureLegal(parsed.path);
if (!isAbsolute(path))
parsed.path = splitString<std::vector<std::string>>(absPath(path, baseDir->string()), "/");
if (!std::filesystem::path(path).is_absolute()) {
auto baseDirPath = *baseDir;
parsed.path = splitString<std::vector<std::string>>(absPath(path, &baseDirPath).string(), "/");
}
}
return fromParsedURL(fetchSettings, std::move(parsed), isFlake);
} catch (BadURL &) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ protected:
// resolve any symlinks in i.e. on macOS /tmp -> /private/tmp
// because this is not allowed for a nix store.
auto tmpl =
nix::absPath(std::filesystem::path(nix::defaultTempDir()) / "tests_nix-store.XXXXXX", std::nullopt, true);
nix::absPath(std::filesystem::path(nix::defaultTempDir()) / "tests_nix-store.XXXXXX", nullptr, true);
nixDir = mkdtemp((char *) tmpl.c_str());
#endif

Expand Down
4 changes: 0 additions & 4 deletions src/libstore-tests/machines.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ using testing::Eq;
using testing::Field;
using testing::SizeIs;

namespace nix::fs {
using namespace std::filesystem;
}

using namespace nix;

TEST(machines, getMachinesWithEmptyBuilders)
Expand Down
2 changes: 1 addition & 1 deletion src/libstore/binary-cache-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ BinaryCacheStore::BinaryCacheStore(Config & config)
: config{config}
{
if (config.secretKeyFile != "")
signers.push_back(std::make_unique<LocalSigner>(SecretKey{readFile(config.secretKeyFile)}));
signers.push_back(std::make_unique<LocalSigner>(SecretKey{readFile(config.secretKeyFile.get())}));

if (config.secretKeyFiles != "") {
std::stringstream ss(config.secretKeyFiles);
Expand Down
12 changes: 6 additions & 6 deletions src/libstore/build/derivation-building-goal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1052,15 +1052,15 @@ LogFile::LogFile(Store & store, const StorePath & drvPath, const LogFileSettings

auto baseName = std::string(baseNameOf(store.printStorePath(drvPath)));

Path logDir;
std::filesystem::path logDir;
if (auto localStore = dynamic_cast<LocalStore *>(&store))
logDir = localStore->config->logDir;
logDir = localStore->config->logDir.get();
else
logDir = logSettings.nixLogDir.string();
Path dir = fmt("%s/%s/%s/", logDir, LocalFSStore::drvsLogDir, baseName.substr(0, 2));
logDir = logSettings.nixLogDir;
auto dir = logDir / LocalFSStore::drvsLogDir / baseName.substr(0, 2);
createDirs(dir);

Path logFileName = fmt("%s/%s%s", dir, baseName.substr(2), logSettings.compressLog ? ".bz2" : "");
auto logFileName = dir / (baseName.substr(2) + (logSettings.compressLog ? ".bz2" : ""));

fd = openNewFileForWrite(
logFileName,
Expand All @@ -1070,7 +1070,7 @@ LogFile::LogFile(Store & store, const StorePath & drvPath, const LogFileSettings
.followSymlinksOnTruncate = true, /* FIXME: Probably shouldn't follow symlinks. */
});
if (!fd)
throw SysError("creating log file '%1%'", logFileName);
throw SysError("creating log file %1%", PathFmt(logFileName));

fileSink = std::make_shared<FdSink>(fd.get());

Expand Down
Loading
Loading