snix/third_party/nix/src/libexpr/get-drvs.hh
Kane York 72e61aa584 refactor(tvix): completely remove boehm gc
We have decided that leaking memory is a better fate than random,
non-debuggable memory corruption. Future CLs will begin changing
various fields to std::unique_ptr and std::shared_ptr.

It turns out that disabling the GC does not have disasterous impact.
The Nix evaluator only runs on the client CLI, never in any long-
running process. Even the REPL does not leak too badly under this
change, because it uses one EvalState for the duration of the REPL.

Building an explicitly tracing garbage collector is likely in the
future of this project, but that giant amount of work cannot be
done under a nix evaluator that is constantly crashing. We need to
restore development velocity here, and this is the best way we've
figured out to do it.

Change-Id: I2fcda8fcee853c15a9a5e22eca7c5a784bc2bf76
Reviewed-on: https://cl.tvl.fyi/c/depot/+/1720
Reviewed-by: glittershark <grfn@gws.fyi>
Reviewed-by: tazjin <mail@tazj.in>
Tested-by: BuildkiteCI
2020-08-14 00:35:18 +00:00

81 lines
2.4 KiB
C++

#pragma once
#include <map>
#include <string>
#include "libexpr/eval.hh"
namespace nix {
struct DrvInfo {
public:
typedef std::map<std::string, Path> Outputs;
private:
EvalState* state;
mutable std::string name;
mutable std::string system;
mutable std::string drvPath;
mutable std::string outPath;
mutable std::string outputName;
Outputs outputs;
bool failed = false; // set if we get an AssertionError
Bindings *attrs = nullptr, *meta = nullptr;
Bindings* getMeta();
bool checkMeta(Value& v);
public:
std::string attrPath; /* path towards the derivation */
DrvInfo(EvalState& state) : state(&state){};
DrvInfo(EvalState& state, std::string attrPath, Bindings* attrs);
DrvInfo(EvalState& state, const ref<Store>& store,
const std::string& drvPathWithOutputs);
std::string queryName() const;
std::string querySystem() const;
std::string queryDrvPath() const;
std::string queryOutPath() const;
std::string queryOutputName() const;
/** Return the list of outputs. The "outputs to install" are determined by
* `meta.outputsToInstall`. */
Outputs queryOutputs(bool onlyOutputsToInstall = false);
StringSet queryMetaNames();
Value* queryMeta(const std::string& name);
std::string queryMetaString(const std::string& name);
NixInt queryMetaInt(const std::string& name, NixInt def);
NixFloat queryMetaFloat(const std::string& name, NixFloat def);
bool queryMetaBool(const std::string& name, bool def);
void setMeta(const std::string& name, Value* v);
/*
MetaInfo queryMetaInfo(EvalState & state) const;
MetaValue queryMetaInfo(EvalState & state, const std::string & name) const;
*/
void setName(const std::string& s) { name = s; }
void setDrvPath(const std::string& s) { drvPath = s; }
void setOutPath(const std::string& s) { outPath = s; }
void setFailed() { failed = true; };
bool hasFailed() { return failed; };
};
typedef std::list<DrvInfo> DrvInfos;
/* If value `v' denotes a derivation, return a DrvInfo object
describing it. Otherwise return nothing. */
std::optional<DrvInfo> getDerivation(EvalState& state, Value& v,
bool ignoreAssertionFailures);
void getDerivations(EvalState& state, Value& v, const std::string& pathPrefix,
Bindings& autoArgs, DrvInfos& drvs,
bool ignoreAssertionFailures);
} // namespace nix