Skip to content

Commit

Permalink
fix compilation with nix 2.24
Browse files Browse the repository at this point in the history
  • Loading branch information
Mic92 committed Nov 7, 2024
1 parent 20290ee commit ed15bc7
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 31 deletions.
6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
callPackage
stdenv
;
nix = nixVersions.nix_2_19;
nix = nixVersions.nix_2_24;
llvmPackages = llvmPackages_16;
nixf = callPackage ./libnixf { };
nixt = callPackage ./libnixt { inherit nix; };
Expand Down
6 changes: 6 additions & 0 deletions libnixt/include/nixt/InitEval.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,18 @@
#include <nix/eval.hh>
#include <nix/shared.hh>
#include <nix/store-api.hh>
#include <nix/eval-gc.hh>
#include <nix/eval-settings.hh>
#include <nix/flake/flake.hh>
#include <nix/plugin.hh>
#include <nix/common-eval-args.hh>

namespace nixt {

inline void initEval() {
nix::initNix();
nix::initLibStore();
nix::flake::initLib(nix::flakeSettings);
nix::initPlugins();
nix::initGC();
}
Expand Down
4 changes: 2 additions & 2 deletions libnixt/lib/Flake.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,12 @@ void nixt::callDirtyFlake(EvalState &State, std::string_view Src,
nix::Value &VRes) {

nix::Value *VSrc = State.allocValue();
VSrc->mkPath(State.rootPath(nix::CanonPath(Src, nix::CanonPath::fromCwd())));
VSrc->mkPath(State.rootPath(nix::CanonPath(Src)));

auto *VFlakeCompat = State.allocValue();

nix::Expr *EFlakeCompat = State.parseExprFromString(
FlakeCompat, State.rootPath(nix::CanonPath::fromCwd()));
FlakeCompat, State.rootPath("."));
State.eval(EFlakeCompat, *VFlakeCompat);

State.callFunction(*VFlakeCompat, *VSrc, VRes, noPos);
Expand Down
17 changes: 9 additions & 8 deletions libnixt/lib/Value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ std::optional<nix::Value> nixt::getField(nix::EvalState &State, nix::Value &V,
return std::nullopt;

nix::Symbol SFiled = State.symbols.create(Field);
if (auto *It = V.attrs->find(SFiled); It != V.attrs->end())
if (auto *It = V.attrs()->find(SFiled); It != V.attrs()->end())
return *It->value;

return std::nullopt;
Expand Down Expand Up @@ -86,11 +86,11 @@ nix::Value &nixt::selectAttr(nix::EvalState &State, nix::Value &V,
State.forceValue(V, nix::noPos);

if (V.type() != nix::ValueType::nAttrs)
throw nix::TypeError("value is not an attrset");
throw nix::TypeError(State, "value is not an attrset");

assert(V.attrs && "nix must allocate non-null attrs!");
auto *Nested = V.attrs->find(Attr);
if (Nested == V.attrs->end())
assert(V.attrs() && "nix must allocate non-null attrs!");
auto *Nested = V.attrs()->find(Attr);
if (Nested == V.attrs()->end())
throw nix::AttrPathNotFound("attrname " + State.symbols[Attr] +
" not found in attrset");

Expand Down Expand Up @@ -145,11 +145,12 @@ nix::Value getSubOptions(nix::EvalState &State, nix::Value &Type) {
nix::Value &GetSubOptions =
selectAttr(State, Type, State.symbols.create("getSubOptions"));

nix::Value EmptyList;
EmptyList.mkList(0);
auto list = State.buildList(0);
auto EmptyList = State.allocValue();
EmptyList->mkList(list);
// Invoke "GetSubOptions"
nix::Value VResult;
State.callFunction(GetSubOptions, EmptyList, VResult, nix::noPos);
State.callFunction(GetSubOptions, *EmptyList, VResult, nix::noPos);
return VResult;
}

Expand Down
3 changes: 2 additions & 1 deletion libnixt/test/StateTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

#include <nix/eval.hh>
#include <nix/store-api.hh>
#include <nix/common-eval-args.hh>

namespace nixt {

struct StateTest : testing::Test {
std::unique_ptr<nix::EvalState> State;
StateTest() : State(new nix::EvalState{{}, nix::openStore("dummy://")}) {}
StateTest() : State(new nix::EvalState{{}, nix::openStore("dummy://"), nix::fetchSettings, nix::evalSettings}) {}
};

} // namespace nixt
4 changes: 2 additions & 2 deletions libnixt/test/Value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ using namespace nixt;
namespace {

struct ValueTest : StateTest {
nix::SourcePath cwd() { return State->rootPath(nix::CanonPath::fromCwd()); }
nix::SourcePath cwd() { return State->rootPath("."); }
};

TEST_F(ValueTest, IsOption_neg) {
Expand Down Expand Up @@ -58,7 +58,7 @@ TEST_F(ValueTest, selectAttrPath) {
nix::Value &Kern = selectStringViews(*State, Nested, {"c", "d"});

ASSERT_EQ(Kern.type(), nix::ValueType::nInt);
ASSERT_EQ(Kern.integer, 1);
ASSERT_EQ(Kern.integer(), 1);
}

} // namespace
31 changes: 17 additions & 14 deletions nixd/lib/Eval/AttrSetProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <nix/attr-path.hh>
#include <nix/nixexpr.hh>
#include <nix/store-api.hh>
#include <nix/common-eval-args.hh>
#include <nixt/Value.h>

using namespace nixd;
Expand All @@ -22,7 +23,7 @@ void fillString(nix::EvalState &State, nix::Value &V,
nix::Value &Select = nixt::selectStringViews(State, V, AttrPath);
State.forceValue(Select, nix::noPos);
if (Select.type() == nix::ValueType::nString)
Field = Select.string.c_str;
Field = Select.string_view();
} catch (std::exception &E) {
Field = std::nullopt;
}
Expand Down Expand Up @@ -85,8 +86,8 @@ void fillUnsafeGetAttrPosLocation(nix::EvalState &State, nix::Value &V,
Column.type() == nix::ValueType::nInt) {

// Nix position starts from "1" however lsp starts from zero.
lspserver::Position Pos = {static_cast<int>(Line.integer) - 1,
static_cast<int>(Column.integer) - 1};
lspserver::Position Pos = {static_cast<int>(Line.integer()) - 1,
static_cast<int>(Column.integer()) - 1};
Loc.range = {Pos, Pos};
}
}
Expand Down Expand Up @@ -131,16 +132,16 @@ void fillOptionDescription(nix::EvalState &State, nix::Value &V,
fillOptionDeclarations(State, V, R);
// FIXME: add definitions location.
if (V.type() == nix::ValueType::nAttrs) [[likely]] {
assert(V.attrs);
if (auto *It = V.attrs->find(State.symbols.create("type"));
It != V.attrs->end()) [[likely]] {
assert(V.attrs());
if (auto *It = V.attrs()->find(State.symbols.create("type"));
It != V.attrs()->end()) [[likely]] {
OptionType Type;
fillOptionType(State, *It->value, Type);
R.Type = std::move(Type);
}

if (auto *It = V.attrs->find(State.symbols.create("example"));
It != V.attrs->end()) {
if (auto *It = V.attrs()->find(State.symbols.create("example"));
It != V.attrs()->end()) {
State.forceValue(*It->value, It->pos);

// In nixpkgs some examples are nested in "literalExpression"
Expand All @@ -157,10 +158,12 @@ void fillOptionDescription(nix::EvalState &State, nix::Value &V,

} // namespace

// myArgs.lookupPath, evalStore, fetchSettings,
// evalSettings);
AttrSetProvider::AttrSetProvider(std::unique_ptr<InboundPort> In,
std::unique_ptr<OutboundPort> Out)
: LSPServer(std::move(In), std::move(Out)),
State(new nix::EvalState({}, nix::openStore())) {
State(new nix::EvalState({}, nix::openStore(), nix::fetchSettings, nix::evalSettings)) {
Registry.addMethod(rpcMethod::EvalExpr, this, &AttrSetProvider::onEvalExpr);
Registry.addMethod(rpcMethod::AttrPathInfo, this,
&AttrSetProvider::onAttrPathInfo);
Expand All @@ -177,7 +180,7 @@ void AttrSetProvider::onEvalExpr(
lspserver::Callback<std::optional<std::string>> Reply) {
try {
nix::Expr *AST = state().parseExprFromString(
Name, state().rootPath(nix::CanonPath::fromCwd()));
Name, state().rootPath("."));
state().eval(AST, Nixpkgs);
Reply(std::nullopt);
return;
Expand Down Expand Up @@ -234,9 +237,9 @@ void AttrSetProvider::onAttrPathComplete(
// evaluating package details.
// "Trie"s may not beneficial becausae it cannot speedup eval.
for (const auto *AttrPtr :
Scope.attrs->lexicographicOrder(state().symbols)) {
Scope.attrs()->lexicographicOrder(state().symbols)) {
const nix::Attr &Attr = *AttrPtr;
const std::string Name = state().symbols[Attr.name];
const std::string_view Name = state().symbols[Attr.name];
if (Name.starts_with(Params.Prefix)) {
++Num;
Names.emplace_back(Name);
Expand Down Expand Up @@ -309,9 +312,9 @@ void AttrSetProvider::onOptionComplete(
// evaluating package details.
// "Trie"s may not beneficial becausae it cannot speedup eval.
for (const auto *AttrPtr :
Scope.attrs->lexicographicOrder(state().symbols)) {
Scope.attrs()->lexicographicOrder(state().symbols)) {
const nix::Attr &Attr = *AttrPtr;
std::string Name = state().symbols[Attr.name];
std::string_view Name = state().symbols[Attr.name];
if (Name.starts_with(Params.Prefix)) {
// Add a new "OptionField", see it's type.
assert(Attr.value);
Expand Down

0 comments on commit ed15bc7

Please sign in to comment.