Skip to content
Merged
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
9 changes: 5 additions & 4 deletions src/libcmd/common-eval-args.cc
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ Bindings * MixEvalArgs::getAutoArgs(EvalState & state)
state.parseExprFromString(
arg.expr,
compatibilitySettings.nixShellShebangArgumentsRelativeToScript
? state.rootPath(absPath(getCommandBaseDir()))
? state.rootPath(absPath(getCommandBaseDir()).string())
: state.rootPath(".")));
},
[&](const AutoArgString & arg) { v->mkString(arg.s, state.mem); },
Expand All @@ -177,7 +177,7 @@ Bindings * MixEvalArgs::getAutoArgs(EvalState & state)
return res.finish();
}

SourcePath lookupFileArg(EvalState & state, std::string_view s, const Path * baseDir)
SourcePath lookupFileArg(EvalState & state, std::string_view s, const std::filesystem::path * baseDir)
{
if (EvalSettings::isPseudoUrl(s)) {
auto accessor = fetchers::downloadTarball(*state.store, state.fetchSettings, EvalSettings::resolvePseudoUrl(s));
Expand All @@ -197,12 +197,13 @@ SourcePath lookupFileArg(EvalState & state, std::string_view s, const Path * bas
}

else if (s.size() > 2 && s.at(0) == '<' && s.at(s.size() - 1) == '>') {
Path p(s.substr(1, s.size() - 2));
// Should perhaps be a `CanonPath`?
std::string p(s.substr(1, s.size() - 2));
return state.findFile(p);
}

else
return state.rootPath(baseDir ? absPath(s, *baseDir) : absPath(s));
return state.rootPath(absPath(std::filesystem::path{s}, baseDir).string());
}

} // namespace nix
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 @@ -134,7 +134,7 @@ struct MixFlakeOptions : virtual Args, EvalCommand

struct SourceExprCommand : virtual Args, MixFlakeOptions
{
std::optional<Path> file;
std::optional<std::filesystem::path> file;
std::optional<std::string> expr;

SourceExprCommand();
Expand Down Expand Up @@ -310,7 +310,7 @@ static RegisterCommand registerCommand2(std::vector<std::string> && name)

struct MixProfile : virtual StoreCommand
{
std::optional<Path> profile;
std::optional<std::filesystem::path> profile;

MixProfile();

Expand Down
2 changes: 1 addition & 1 deletion src/libcmd/include/nix/cmd/common-eval-args.hh
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,6 @@ private:
/**
* @param baseDir Optional [base directory](https://nix.dev/manual/nix/development/glossary#gloss-base-directory)
*/
SourcePath lookupFileArg(EvalState & state, std::string_view s, const Path * baseDir = nullptr);
SourcePath lookupFileArg(EvalState & state, std::string_view s, const std::filesystem::path * baseDir = nullptr);

} // namespace nix
2 changes: 1 addition & 1 deletion src/libcmd/include/nix/cmd/installable-value.hh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class AttrCursor;
struct App
{
std::vector<DerivedPath> context;
Path program;
std::filesystem::path program;
// FIXME: add args, sandbox settings, metadata, ...
};

Expand Down
11 changes: 10 additions & 1 deletion src/libcmd/include/nix/cmd/repl.hh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,16 @@ struct AbstractNixRepl

typedef std::vector<std::pair<Value *, std::string>> AnnotatedValues;

using RunNix = void(Path program, const Strings & args, const std::optional<std::string> & input);
/**
* Run a nix executable
*
* @todo this is a layer violation
*
* @param programName Name of the command, e.g. `nix` or `nix-env`.
* @param args aguments to the command.
*/
using RunNix =
void(const std::string & programName, const Strings & args, const std::optional<std::string> & input);

/**
* @param runNix Function to run the nix CLI to support various
Expand Down
18 changes: 10 additions & 8 deletions src/libcmd/installables.cc
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ MixFlakeOptions::MixFlakeOptions()
lockFlags.writeLockFile = false;
lockFlags.inputOverrides.insert_or_assign(
flake::parseInputAttrPath(inputAttrPath),
parseFlakeRef(fetchSettings, flakeRef, absPath(getCommandBaseDir()), true));
parseFlakeRef(fetchSettings, flakeRef, absPath(getCommandBaseDir()).string(), true));
}},
.completer = {[&](AddCompletions & completions, size_t n, std::string_view prefix) {
if (n == 0) {
Expand Down Expand Up @@ -173,7 +173,7 @@ MixFlakeOptions::MixFlakeOptions()
auto flake = flake::lockFlake(
flakeSettings,
*evalState,
parseFlakeRef(fetchSettings, flakeRef, absPath(getCommandBaseDir())),
parseFlakeRef(fetchSettings, flakeRef, absPath(getCommandBaseDir()).string()),
{.writeLockFile = false});
for (auto & [inputName, input] : flake.lockFile.root->inputs) {
auto input2 = flake.lockFile.findInput({inputName}); // resolve 'follows' nodes
Expand Down Expand Up @@ -263,7 +263,7 @@ void SourceExprCommand::completeInstallable(AddCompletions & completions, std::s

evalSettings.pureEval = false;
auto state = getEvalState();
auto e = state->parseExprFromFile(resolveExprPath(lookupFileArg(*state, *file)));
auto e = state->parseExprFromFile(resolveExprPath(lookupFileArg(*state, file->string())));

Value root;
state->eval(e, root);
Expand Down Expand Up @@ -465,10 +465,10 @@ Installables SourceExprCommand::parseInstallables(ref<Store> store, std::vector<
state->eval(e, *vFile);
} else if (file) {
auto dir = absPath(getCommandBaseDir());
state->evalFile(lookupFileArg(*state, *file, &dir), *vFile);
state->evalFile(lookupFileArg(*state, file->string(), &dir), *vFile);
} else {
Path dir = absPath(getCommandBaseDir());
auto e = state->parseExprFromString(*expr, state->rootPath(dir));
auto dir = absPath(getCommandBaseDir());
auto e = state->parseExprFromString(*expr, state->rootPath(dir.string()));
state->eval(e, *vFile);
}

Expand Down Expand Up @@ -801,7 +801,8 @@ std::vector<FlakeRef> RawInstallablesCommand::getFlakeRefsForCompletion()
std::vector<FlakeRef> res;
res.reserve(rawInstallables.size());
for (const auto & i : rawInstallables)
res.push_back(parseFlakeRefWithFragment(fetchSettings, expandTilde(i), absPath(getCommandBaseDir())).first);
res.push_back(
parseFlakeRefWithFragment(fetchSettings, expandTilde(i), absPath(getCommandBaseDir()).string()).first);
return res;
}

Expand All @@ -820,7 +821,8 @@ void RawInstallablesCommand::run(ref<Store> store)

std::vector<FlakeRef> InstallableCommand::getFlakeRefsForCompletion()
{
return {parseFlakeRefWithFragment(fetchSettings, expandTilde(_installable), absPath(getCommandBaseDir())).first};
return {parseFlakeRefWithFragment(fetchSettings, expandTilde(_installable), absPath(getCommandBaseDir()).string())
.first};
}

void InstallablesCommand::run(ref<Store> store, std::vector<std::string> && rawInstallables)
Expand Down
19 changes: 10 additions & 9 deletions src/libcmd/repl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ struct NixRepl : AbstractNixRepl, detail::ReplCompleterMixin, gc
{
size_t debugTraceIndex;

// Arguments passed to :load, saved so they can be reloaded with :reload
Strings loadedFiles;
std::list<std::filesystem::path> loadedFiles;
// Arguments passed to :load-flake, saved so they can be reloaded with :reload
Strings loadedFlakes;
std::function<AnnotatedValues()> getValues;
Expand All @@ -73,7 +72,7 @@ struct NixRepl : AbstractNixRepl, detail::ReplCompleterMixin, gc

RunNix * runNixPtr;

void runNix(Path program, const Strings & args, const std::optional<std::string> & input = {});
void runNix(const std::string & program, const Strings & args, const std::optional<std::string> & input = {});

std::unique_ptr<ReplInteracter> interacter;

Expand All @@ -92,7 +91,7 @@ struct NixRepl : AbstractNixRepl, detail::ReplCompleterMixin, gc
StorePath getDerivationPath(Value & v);
ProcessLineResult processLine(std::string line);

void loadFile(const Path & path);
void loadFile(const std::filesystem::path & path);
void loadFlake(const std::string & flakeRef);
void loadFiles();
void loadFlakes();
Expand Down Expand Up @@ -539,7 +538,9 @@ ProcessLineResult NixRepl::processLine(std::string line)
Value v;
evalString(arg, v);
StorePath drvPath = getDerivationPath(v);
Path drvPathRaw = state->store->printStorePath(drvPath);
// N.B. This need not be a local / native file path. For
// example, we might be using an SSH store to a different OS.
std::string drvPathRaw = state->store->printStorePath(drvPath);

if (command == ":b" || command == ":bl") {
state->store->buildPaths({
Expand Down Expand Up @@ -712,12 +713,12 @@ ProcessLineResult NixRepl::processLine(std::string line)
return ProcessLineResult::PromptAgain;
}

void NixRepl::loadFile(const Path & path)
void NixRepl::loadFile(const std::filesystem::path & path)
{
loadedFiles.remove(path);
loadedFiles.push_back(path);
Value v, v2;
state->evalFile(lookupFileArg(*state, path), v);
state->evalFile(lookupFileArg(*state, path.string()), v);
state->autoCallFunction(*autoArgs, v, v2);
addAttrsToScope(v2);
}
Expand Down Expand Up @@ -790,7 +791,7 @@ void NixRepl::reloadFilesAndFlakes()

void NixRepl::loadFiles()
{
Strings old = loadedFiles;
decltype(loadedFiles) old = loadedFiles;
loadedFiles.clear();

for (auto & i : old) {
Expand Down Expand Up @@ -888,7 +889,7 @@ void NixRepl::evalString(std::string s, Value & v)
state->forceValue(v, v.determinePos(noPos));
}

void NixRepl::runNix(Path program, const Strings & args, const std::optional<std::string> & input)
void NixRepl::runNix(const std::string & program, const Strings & args, const std::optional<std::string> & input)
{
if (runNixPtr)
(*runNixPtr)(program, args, input);
Expand Down
4 changes: 2 additions & 2 deletions src/libutil/args.cc
Original file line number Diff line number Diff line change
Expand Up @@ -371,13 +371,13 @@ void RootArgs::parseCmdline(const Strings & _cmdline, bool allowShebang)
d.completer(*completions, d.n, d.prefix);
}

Path Args::getCommandBaseDir() const
std::filesystem::path Args::getCommandBaseDir() const
{
assert(parent);
return parent->getCommandBaseDir();
}

Path RootArgs::getCommandBaseDir() const
std::filesystem::path RootArgs::getCommandBaseDir() const
{
return commandBaseDir;
}
Expand Down
2 changes: 1 addition & 1 deletion src/libutil/include/nix/util/args.hh
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public:
*
* This only returns the correct value after parseCmdline() has run.
*/
virtual Path getCommandBaseDir() const;
virtual std::filesystem::path getCommandBaseDir() const;

protected:

Expand Down
4 changes: 2 additions & 2 deletions src/libutil/include/nix/util/args/root.hh
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ protected:
*
* @see getCommandBaseDir()
*/
Path commandBaseDir = ".";
std::filesystem::path commandBaseDir = ".";

public:
/** Parse the command line, throwing a UsageError if something goes
Expand All @@ -48,7 +48,7 @@ public:

std::shared_ptr<Completions> completions;

Path getCommandBaseDir() const override;
std::filesystem::path getCommandBaseDir() const override;

protected:

Expand Down
6 changes: 3 additions & 3 deletions src/nix/app.cc
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,9 @@ App UnresolvedApp::resolve(ref<Store> evalStore, ref<Store> store)
auto res = unresolved;

auto builtContext = build(evalStore, store);
res.program = resolveString(*store, unresolved.program, builtContext);
if (!store->isInStore(res.program))
throw Error("app program '%s' is not in the Nix store", res.program);
res.program = resolveString(*store, unresolved.program.string(), builtContext);
if (!store->isInStore(res.program.string()))
throw Error("app program '%s' is not in the Nix store", res.program.string());

return res;
}
Expand Down
4 changes: 2 additions & 2 deletions src/nix/formatter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ struct CmdFormatterRun : MixFormatter, MixJSON
assert(maybeFlakeDir.has_value());
auto flakeDir = maybeFlakeDir.value();

Strings programArgs{app.program};
Strings programArgs{app.program.string()};

// Propagate arguments from the CLI
for (auto & i : args) {
Expand All @@ -103,7 +103,7 @@ struct CmdFormatterRun : MixFormatter, MixJSON
execProgramInStore(
store,
UseLookupPath::DontUse,
app.program,
app.program.string(),
programArgs,
std::nullopt, // Use default system
env);
Expand Down
2 changes: 1 addition & 1 deletion src/nix/repl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace nix {

void runNix(Path program, const Strings & args, const std::optional<std::string> & input = {})
void runNix(const std::string & program, const Strings & args, const std::optional<std::string> & input = {})
{
auto subprocessEnv = getEnv();
subprocessEnv["NIX_CONFIG"] = globalConfig.toKeyValue();
Expand Down
4 changes: 2 additions & 2 deletions src/nix/run.cc
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ struct CmdRun : InstallableValueCommand, MixEnvironment
lockFlags.applyNixConfig = true;
auto app = installable->toApp(*state).resolve(getEvalStore(), store);

Strings allArgs{app.program};
Strings allArgs{app.program.string()};
for (auto & i : args)
allArgs.push_back(i);

Expand All @@ -170,7 +170,7 @@ struct CmdRun : InstallableValueCommand, MixEnvironment

setEnviron();

execProgramInStore(store, UseLookupPath::DontUse, app.program, allArgs);
execProgramInStore(store, UseLookupPath::DontUse, app.program.string(), allArgs);
}
};

Expand Down
Loading