-
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
nixd/Server: split worker in a dedicated class (#230)
This should fix some async-signal unsafe calls (causing the forked process hangs).
- Loading branch information
Showing
27 changed files
with
808 additions
and
629 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#include <nix/eval-inline.hh> | ||
#include <nix/shared.hh> | ||
|
||
namespace nix { | ||
|
||
// Copy-paste from nix source code, do not know why it is inlined. | ||
|
||
inline void EvalState::evalAttrs(Env &env, Expr *e, Value &v, const PosIdx pos, | ||
std::string_view errorCtx) { | ||
try { | ||
e->eval(*this, env, v); | ||
if (v.type() != nAttrs) | ||
error("value is %1% while a set was expected", showType(v)) | ||
.withFrame(env, *e) | ||
.debugThrow<TypeError>(); | ||
} catch (Error &e) { | ||
e.addTrace(positions[pos], errorCtx); | ||
throw; | ||
} | ||
} | ||
|
||
} // namespace nix |
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,16 @@ | ||
#pragma once | ||
|
||
#include <nix/eval.hh> | ||
#include <nix/globals.hh> | ||
#include <nix/shared.hh> | ||
|
||
namespace nixd { | ||
|
||
inline void initEval() { | ||
nix::initNix(); | ||
nix::initLibStore(); | ||
nix::initPlugins(); | ||
nix::initGC(); | ||
} | ||
|
||
} // 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,52 @@ | ||
#pragma once | ||
|
||
#include <list> | ||
#include <string> | ||
#include <thread> | ||
#include <vector> | ||
|
||
namespace nixd::configuration { | ||
|
||
inline std::list<std::string> toNixArgs(const std::vector<std::string> &Args) { | ||
return {Args.begin(), Args.end()}; | ||
} | ||
struct InstallableConfigurationItem { | ||
std::vector<std::string> args; | ||
std::string installable; | ||
|
||
[[nodiscard]] bool empty() const { | ||
return args.empty() && installable.empty(); | ||
} | ||
|
||
[[nodiscard]] auto nArgs() const { return toNixArgs(args); } | ||
}; | ||
|
||
struct TopLevel { | ||
|
||
struct Eval { | ||
/// Nix installables that will be used for root translation unit. | ||
InstallableConfigurationItem target; | ||
|
||
/// The depth you'd like to eval *after* reached "installable" target. | ||
int depth = 0; | ||
/// Number of workers forking | ||
/// defaults to std::thread::hardware_concurrency | ||
int workers = static_cast<int>(std::thread::hardware_concurrency()); | ||
}; | ||
|
||
Eval eval; | ||
|
||
struct Formatting { | ||
std::string command = "nixpkgs-fmt"; | ||
}; | ||
Formatting formatting; | ||
|
||
struct Options { | ||
bool enable = false; | ||
InstallableConfigurationItem target; | ||
}; | ||
|
||
Options options; | ||
}; | ||
|
||
} // namespace nixd::configuration |
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,31 @@ | ||
#pragma once | ||
|
||
#include "Config.h" | ||
|
||
#include <llvm/Support/JSON.h> | ||
|
||
namespace nixd::configuration { | ||
|
||
llvm::json::Value toJSON(const TopLevel::Eval &R); | ||
|
||
llvm::json::Value toJSON(const TopLevel::Formatting &R); | ||
|
||
llvm::json::Value toJSON(const TopLevel::Options &R); | ||
|
||
llvm::json::Value toJSON(const InstallableConfigurationItem &R); | ||
|
||
bool fromJSON(const llvm::json::Value &Params, TopLevel::Eval &R, | ||
llvm::json::Path P); | ||
|
||
bool fromJSON(const llvm::json::Value &Params, TopLevel::Formatting &R, | ||
llvm::json::Path P); | ||
|
||
bool fromJSON(const llvm::json::Value &Params, TopLevel::Options &R, | ||
llvm::json::Path P); | ||
|
||
bool fromJSON(const llvm::json::Value &Params, TopLevel &R, llvm::json::Path P); | ||
|
||
bool fromJSON(const llvm::json::Value &Params, InstallableConfigurationItem &R, | ||
llvm::json::Path P); | ||
|
||
} // namespace nixd::configuration |
Oops, something went wrong.