forked from lix-project/lix
nix edit: Support non-derivation attributes
E.g.
$ nix edit .#nixosConfigurations.bla
now works.
(cherry picked from commit d2032edb2f
)
This commit is contained in:
parent
c1ca4f0acc
commit
231a8aa2c2
|
@ -103,7 +103,7 @@ Pos findDerivationFilename(EvalState & state, Value & v, std::string what)
|
||||||
auto dummyArgs = state.allocBindings(0);
|
auto dummyArgs = state.allocBindings(0);
|
||||||
v2 = findAlongAttrPath(state, "meta.position", *dummyArgs, v).first;
|
v2 = findAlongAttrPath(state, "meta.position", *dummyArgs, v).first;
|
||||||
} catch (Error &) {
|
} catch (Error &) {
|
||||||
throw Error("package '%s' has no source location information", what);
|
throw NoPositionInfo("package '%s' has no source location information", what);
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: is it possible to extract the Pos object instead of doing this
|
// FIXME: is it possible to extract the Pos object instead of doing this
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
MakeError(AttrPathNotFound, Error);
|
MakeError(AttrPathNotFound, Error);
|
||||||
|
MakeError(NoPositionInfo, Error);
|
||||||
|
|
||||||
std::pair<Value *, Pos> findAlongAttrPath(EvalState & state, const string & attrPath,
|
std::pair<Value *, Pos> findAlongAttrPath(EvalState & state, const string & attrPath,
|
||||||
Bindings & autoArgs, Value & vIn);
|
Bindings & autoArgs, Value & vIn);
|
||||||
|
|
|
@ -3,17 +3,12 @@
|
||||||
#include "args.hh"
|
#include "args.hh"
|
||||||
#include "common-eval-args.hh"
|
#include "common-eval-args.hh"
|
||||||
#include "path.hh"
|
#include "path.hh"
|
||||||
|
#include "eval.hh"
|
||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
extern std::string programPath;
|
extern std::string programPath;
|
||||||
|
|
||||||
struct Value;
|
|
||||||
class Bindings;
|
|
||||||
class EvalState;
|
|
||||||
struct Pos;
|
|
||||||
class Store;
|
|
||||||
|
|
||||||
/* A command that requires a Nix store. */
|
/* A command that requires a Nix store. */
|
||||||
struct StoreCommand : virtual Command
|
struct StoreCommand : virtual Command
|
||||||
{
|
{
|
||||||
|
@ -48,7 +43,7 @@ struct Installable
|
||||||
|
|
||||||
Buildable toBuildable();
|
Buildable toBuildable();
|
||||||
|
|
||||||
virtual Value * toValue(EvalState & state)
|
virtual std::pair<Value *, Pos> toValue(EvalState & state)
|
||||||
{
|
{
|
||||||
throw Error("argument '%s' cannot be evaluated", what());
|
throw Error("argument '%s' cannot be evaluated", what());
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,9 +29,15 @@ struct CmdEdit : InstallableCommand
|
||||||
{
|
{
|
||||||
auto state = getEvalState();
|
auto state = getEvalState();
|
||||||
|
|
||||||
auto v = installable->toValue(*state);
|
auto [v, pos] = installable->toValue(*state);
|
||||||
|
|
||||||
Pos pos = findDerivationFilename(*state, *v, installable->what());
|
try {
|
||||||
|
pos = findDerivationFilename(*state, *v, installable->what());
|
||||||
|
} catch (NoPositionInfo &) {
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pos == noPos)
|
||||||
|
throw Error("cannot find position information for '%s", installable->what());
|
||||||
|
|
||||||
stopProgressBar();
|
stopProgressBar();
|
||||||
|
|
||||||
|
|
|
@ -52,7 +52,7 @@ struct CmdEval : MixJSON, InstallableCommand
|
||||||
|
|
||||||
auto state = getEvalState();
|
auto state = getEvalState();
|
||||||
|
|
||||||
auto v = installable->toValue(*state);
|
auto v = installable->toValue(*state).first;
|
||||||
PathSet context;
|
PathSet context;
|
||||||
|
|
||||||
stopProgressBar();
|
stopProgressBar();
|
||||||
|
|
|
@ -121,7 +121,7 @@ struct InstallableValue : Installable
|
||||||
{
|
{
|
||||||
auto state = cmd.getEvalState();
|
auto state = cmd.getEvalState();
|
||||||
|
|
||||||
auto v = toValue(*state);
|
auto v = toValue(*state).first;
|
||||||
|
|
||||||
Bindings & autoArgs = *cmd.getAutoArgs(*state);
|
Bindings & autoArgs = *cmd.getAutoArgs(*state);
|
||||||
|
|
||||||
|
@ -169,11 +169,11 @@ struct InstallableExpr : InstallableValue
|
||||||
|
|
||||||
std::string what() override { return text; }
|
std::string what() override { return text; }
|
||||||
|
|
||||||
Value * toValue(EvalState & state) override
|
std::pair<Value *, Pos> toValue(EvalState & state) override
|
||||||
{
|
{
|
||||||
auto v = state.allocValue();
|
auto v = state.allocValue();
|
||||||
state.eval(state.parseExprFromString(text, absPath(".")), *v);
|
state.eval(state.parseExprFromString(text, absPath(".")), *v);
|
||||||
return v;
|
return {v, noPos};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -187,7 +187,7 @@ struct InstallableAttrPath : InstallableValue
|
||||||
|
|
||||||
std::string what() override { return attrPath; }
|
std::string what() override { return attrPath; }
|
||||||
|
|
||||||
Value * toValue(EvalState & state) override
|
std::pair<Value *, Pos> toValue(EvalState & state) override
|
||||||
{
|
{
|
||||||
auto source = cmd.getSourceExpr(state);
|
auto source = cmd.getSourceExpr(state);
|
||||||
|
|
||||||
|
@ -196,7 +196,7 @@ struct InstallableAttrPath : InstallableValue
|
||||||
auto v = findAlongAttrPath(state, attrPath, autoArgs, *source).first;
|
auto v = findAlongAttrPath(state, attrPath, autoArgs, *source).first;
|
||||||
state.forceValue(*v);
|
state.forceValue(*v);
|
||||||
|
|
||||||
return v;
|
return {v, noPos};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue