refactor(3p/nix): Only initialise garbage-collector where needed

Only libexpr depends on the garbage collector, specifically only
instantiations of EvalState actually require the GC to be initialised.

Rather than always starting it for the whole program, even if it is
not needed, this change moves the GC initialisation into libexpr,
guarded by absl::call_once.

This should make it possible to run the nix daemon without the garbage
collector interfering, granted that things are correcty separated and
the daemon does not actually invoke the evaluator.

Based on my investigation so far, the daemon logic itself does not
require libexpr to be present at all - so I think it is safe - but the
current monobinary might have some tricks up its sleeve that will
cause problems for us. We can deal with those if they arise.

Relates to https://b.tvl.fyi/issues/30

Change-Id: I61c745f96420c02e089bd3c362ac3ccb117d3073
Reviewed-on: https://cl.tvl.fyi/c/depot/+/1584
Tested-by: BuildkiteCI
Reviewed-by: edef <edef@edef.eu>
Reviewed-by: kanepyork <rikingcoding@gmail.com>
This commit is contained in:
Vincent Ambo 2020-08-02 23:54:16 +01:00 committed by tazjin
parent 6e04b23506
commit 46c78aa0f9
6 changed files with 72 additions and 70 deletions

View file

@ -115,7 +115,7 @@ class AttrSetTest : public ::testing::Test {
protected:
EvalState* eval_state_;
void SetUp() override {
nix::initGC();
nix::expr::InitGC();
auto store = std::make_shared<DummyStore>();
eval_state_ = new EvalState({"."}, ref<Store>(store));
symbol_table = &eval_state_->symbols;