mirror of
https://github.com/NixOS/nix
synced 2025-07-09 07:53:55 +02:00
Introduce DerivationOptions
This is a first step towards PR #10760, and the issues it addresses. See the Doxygen for details. Thanks to these changes, we are able to drastically restrict how the rest of the code-base uses `ParseDerivation`. Co-Authored-By: HaeNoe <git@haenoe.party>
This commit is contained in:
parent
f0dbfada38
commit
917b8b2f77
14 changed files with 664 additions and 279 deletions
|
@ -11,6 +11,7 @@
|
|||
|
||||
#include "current-process.hh"
|
||||
#include "parsed-derivations.hh"
|
||||
#include "derivation-options.hh"
|
||||
#include "store-api.hh"
|
||||
#include "local-fs-store.hh"
|
||||
#include "globals.hh"
|
||||
|
@ -542,12 +543,13 @@ static void main_nix_build(int argc, char * * argv)
|
|||
env["NIX_STORE"] = store->storeDir;
|
||||
env["NIX_BUILD_CORES"] = std::to_string(settings.buildCores);
|
||||
|
||||
auto passAsFile = tokenizeString<StringSet>(getOr(drv.env, "passAsFile", ""));
|
||||
ParsedDerivation parsedDrv(packageInfo.requireDrvPath(), drv);
|
||||
DerivationOptions drvOptions = DerivationOptions::fromParsedDerivation(parsedDrv);
|
||||
|
||||
int fileNr = 0;
|
||||
|
||||
for (auto & var : drv.env)
|
||||
if (passAsFile.count(var.first)) {
|
||||
if (drvOptions.passAsFile.count(var.first)) {
|
||||
auto fn = ".attr-" + std::to_string(fileNr++);
|
||||
Path p = (tmpDir.path() / fn).string();
|
||||
writeFile(p, var.second);
|
||||
|
@ -557,7 +559,7 @@ static void main_nix_build(int argc, char * * argv)
|
|||
|
||||
std::string structuredAttrsRC;
|
||||
|
||||
if (env.count("__json")) {
|
||||
if (parsedDrv.hasStructuredAttrs()) {
|
||||
StorePathSet inputs;
|
||||
|
||||
std::function<void(const StorePath &, const DerivedPathMap<StringSet>::ChildNode &)> accumInputClosure;
|
||||
|
@ -575,8 +577,6 @@ static void main_nix_build(int argc, char * * argv)
|
|||
for (const auto & [inputDrv, inputNode] : drv.inputDrvs.map)
|
||||
accumInputClosure(inputDrv, inputNode);
|
||||
|
||||
ParsedDerivation parsedDrv(packageInfo.requireDrvPath(), drv);
|
||||
|
||||
if (auto structAttrs = parsedDrv.prepareStructuredAttrs(*store, inputs)) {
|
||||
auto json = structAttrs.value();
|
||||
structuredAttrsRC = writeStructuredAttrsShell(json);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue