-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
335 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
subdir('nixd') | ||
subdir('nix-node-eval') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# nix-node-eval | ||
|
||
Collect per-node eval information, by using official evaluator. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
nix_node_eval = executable('nix-node-eval', | ||
'src/EvalProvider.cpp', | ||
'src/Main.cpp', | ||
install: true, | ||
install_dir: get_option('libexecdir'), | ||
dependencies: [ libnixdrpc, nixt ] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#include "EvalProvider.h" | ||
|
||
#include "nixd/rpc/Protocol.h" | ||
|
||
#include <bc/Read.h> | ||
#include <bc/Write.h> | ||
|
||
namespace nixd { | ||
|
||
using bc::readBytecode; | ||
using rpc::readBytecode; | ||
|
||
void EvalProvider::handleInbound(const std::vector<char> &Buf) { | ||
std::ostringstream OS; | ||
rpc::RPCKind Kind; | ||
std::string_view Data(Buf.data(), Buf.size()); | ||
readBytecode(Data, Kind); | ||
switch (Kind) { | ||
case rpc::RPCKind::RegisterBC: { | ||
rpc::RegisterBCParams Params; | ||
readBytecode(Data, Params); | ||
onRegisterBC(Params); | ||
break; | ||
} | ||
case rpc::RPCKind::UnregisterBC: | ||
case rpc::RPCKind::Log: | ||
case rpc::RPCKind::ExprValue: { | ||
rpc::ExprValueParams Params; | ||
readBytecode(Data, Params); | ||
rpc::ExprValueResponse Response = onExprValue(Params); | ||
writeBytecode(OS, Response); | ||
break; | ||
} | ||
} | ||
} | ||
|
||
} // namespace nixd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#pragma once | ||
|
||
#include "nixd/rpc/Protocol.h" | ||
#include "nixd/rpc/Transport.h" | ||
|
||
#include <nixt/Deserialize.h> | ||
#include <nixt/PtrPool.h> | ||
|
||
#include <nix/eval.hh> | ||
#include <nix/nixexpr.hh> | ||
#include <nix/store-api.hh> | ||
|
||
// libc | ||
#include <fcntl.h> | ||
#include <sys/mman.h> | ||
|
||
namespace nixd { | ||
|
||
class EvalProvider : public rpc::Transport { | ||
|
||
nixt::PtrPool<nix::Expr> Pool; | ||
nixt::ValueMap VMap; | ||
nixt::EnvMap EMap; | ||
std::unique_ptr<nix::EvalState> State; | ||
|
||
void handleInbound(const std::vector<char> &Buf) override; | ||
|
||
public: | ||
EvalProvider(int InboundFD, int OutboundFD) | ||
: rpc::Transport(InboundFD, OutboundFD), State(nullptr) {} | ||
|
||
void onRegisterBC(const rpc::RegisterBCParams &Params) {} | ||
|
||
rpc::ExprValueResponse onExprValue(const rpc::ExprValueParams &Params) { | ||
return {}; | ||
} | ||
}; | ||
|
||
} // namespace nixd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
|
||
#include "EvalProvider.h" | ||
|
||
#include <nixt/InitEval.h> | ||
|
||
#include <unistd.h> | ||
|
||
int main() { | ||
nixt::initEval(); | ||
nixd::EvalProvider Provider(STDIN_FILENO, STDOUT_FILENO); | ||
return Provider.run(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#include "nixd-config.h" | ||
|
||
#include "EvalClient.h" | ||
|
||
#include "nixd/rpc/Protocol.h" | ||
#include "nixd/util/ForkPiped.h" | ||
|
||
#include <bc/Read.h> | ||
#include <bc/Write.h> | ||
|
||
namespace nixd { | ||
|
||
using namespace rpc; | ||
using namespace nixd::util; | ||
|
||
std::unique_ptr<EvalClient> EvalClient::create(int &Fail) { | ||
int In; | ||
int Out; | ||
int Err; | ||
|
||
pid_t Child = forkPiped(In, Out, Err); | ||
if (Child == 0) { | ||
execl(NIXD_LIBEXEC "/nix-node-eval", "nix-node-eval", nullptr); | ||
exit(-1); | ||
} else if (Child < 0) { | ||
// Error. | ||
Fail = Child; | ||
return nullptr; | ||
} | ||
|
||
Fail = 0; | ||
// Parent process. | ||
auto Proc = std::make_unique<PipedProc>(Child, In, Out, Err); | ||
return std::make_unique<EvalClient>(Out, In, std::move(Proc)); | ||
} | ||
|
||
void EvalClient::registerBC(const RegisterBCParams &Params) { | ||
sendPacket(Message{RPCKind::RegisterBC, Params}); | ||
} | ||
|
||
ExprValueResponse EvalClient::exprValue(const ExprValueParams &Params) { | ||
sendPacket(Message{RPCKind::ExprValue, Params}); | ||
return recvPacket<ExprValueResponse>(); | ||
} | ||
|
||
} // namespace nixd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#pragma once | ||
|
||
#include "nixd/rpc/Protocol.h" | ||
#include "nixd/rpc/Transport.h" | ||
#include "nixd/util/PipedProc.h" | ||
|
||
#include <memory> | ||
|
||
namespace nixd { | ||
|
||
class EvalClient : public rpc::Transport { | ||
// Owned process of the evaluator | ||
std::unique_ptr<util::PipedProc> Proc; | ||
void handleInbound(const std::vector<char> &Buf) override{}; | ||
|
||
public: | ||
EvalClient(int InboundFD, int OutboundFD, | ||
std::unique_ptr<util::PipedProc> Proc) | ||
: rpc::Transport(InboundFD, OutboundFD), Proc(std::move(Proc)) {} | ||
|
||
virtual ~EvalClient() = default; | ||
|
||
/// Lanch nix-node-eval, with properly handled file descriptors. | ||
/// System-wide errno will be written into "Fail" variable and thus cannot be | ||
/// discarded. | ||
static std::unique_ptr<EvalClient> create(int &Fail); | ||
|
||
void registerBC(const rpc::RegisterBCParams &Params); | ||
|
||
rpc::ExprValueResponse exprValue(const rpc::ExprValueParams &Params); | ||
|
||
util::PipedProc *proc() { return Proc.get(); } | ||
}; | ||
|
||
} // namespace nixd |
Oops, something went wrong.