From 42f5c8b4323fcf1467a6d93794550e901a89c3f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Thu, 7 Nov 2024 08:02:27 +0100 Subject: [PATCH] fix compilation with nix 2.24 --- flake.lock | 6 +++--- flake.nix | 2 +- libnixt/include/nixt/InitEval.h | 6 ++++++ libnixt/lib/Flake.cpp | 4 ++-- libnixt/lib/Value.cpp | 17 +++++++++-------- libnixt/test/StateTest.h | 3 ++- libnixt/test/Value.cpp | 2 +- nixd/lib/Eval/AttrSetProvider.cpp | 27 +++++++++++++++------------ 8 files changed, 39 insertions(+), 28 deletions(-) diff --git a/flake.lock b/flake.lock index 5b7dcf117..c2be67aca 100644 --- a/flake.lock +++ b/flake.lock @@ -35,11 +35,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1714562304, - "narHash": "sha256-Mr3U37Rh6tH0FbaDFu0aZDwk9mPAe7ASaqDOGgLqqLU=", + "lastModified": 1730831018, + "narHash": "sha256-2S0HwIFRxYp+afuoFORcZA9TjryAf512GmE0MTfEOPU=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "bcd44e224fd68ce7d269b4f44d24c2220fd821e7", + "rev": "8c4dc69b9732f6bbe826b5fbb32184987520ff26", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index 66a478326..719b49369 100644 --- a/flake.nix +++ b/flake.nix @@ -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; }; diff --git a/libnixt/include/nixt/InitEval.h b/libnixt/include/nixt/InitEval.h index 4e4651c88..e6e5135a9 100644 --- a/libnixt/include/nixt/InitEval.h +++ b/libnixt/include/nixt/InitEval.h @@ -3,12 +3,18 @@ #include #include #include +#include +#include +#include +#include +#include namespace nixt { inline void initEval() { nix::initNix(); nix::initLibStore(); + nix::flake::initLib(nix::flakeSettings); nix::initPlugins(); nix::initGC(); } diff --git a/libnixt/lib/Flake.cpp b/libnixt/lib/Flake.cpp index 6b940f4d1..e98d783ba 100644 --- a/libnixt/lib/Flake.cpp +++ b/libnixt/lib/Flake.cpp @@ -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); diff --git a/libnixt/lib/Value.cpp b/libnixt/lib/Value.cpp index aaedb205f..088905f34 100644 --- a/libnixt/lib/Value.cpp +++ b/libnixt/lib/Value.cpp @@ -14,7 +14,7 @@ std::optional 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; @@ -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"); @@ -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; } diff --git a/libnixt/test/StateTest.h b/libnixt/test/StateTest.h index 9f702c161..2a249e35a 100644 --- a/libnixt/test/StateTest.h +++ b/libnixt/test/StateTest.h @@ -2,12 +2,13 @@ #include #include +#include namespace nixt { struct StateTest : testing::Test { std::unique_ptr State; - StateTest() : State(new nix::EvalState{{}, nix::openStore("dummy://")}) {} + StateTest() : State(new nix::EvalState{{}, nix::openStore("dummy://"), nix::fetchSettings, nix::evalSettings}) {} }; } // namespace nixt diff --git a/libnixt/test/Value.cpp b/libnixt/test/Value.cpp index c7a1f4710..f14de8176 100644 --- a/libnixt/test/Value.cpp +++ b/libnixt/test/Value.cpp @@ -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) { diff --git a/nixd/lib/Eval/AttrSetProvider.cpp b/nixd/lib/Eval/AttrSetProvider.cpp index 963ffdf8b..fe205b839 100644 --- a/nixd/lib/Eval/AttrSetProvider.cpp +++ b/nixd/lib/Eval/AttrSetProvider.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include using namespace nixd; @@ -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; } @@ -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" @@ -157,10 +158,12 @@ void fillOptionDescription(nix::EvalState &State, nix::Value &V, } // namespace +// myArgs.lookupPath, evalStore, fetchSettings, +// evalSettings); AttrSetProvider::AttrSetProvider(std::unique_ptr In, std::unique_ptr 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); @@ -177,7 +180,7 @@ void AttrSetProvider::onEvalExpr( lspserver::Callback> Reply) { try { nix::Expr *AST = state().parseExprFromString( - Name, state().rootPath(nix::CanonPath::fromCwd())); + Name, state().rootPath(".")); state().eval(AST, Nixpkgs); Reply(std::nullopt); return; @@ -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); @@ -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);