diff --git a/src/libstore/include/nix/store/globals.hh b/src/libstore/include/nix/store/globals.hh index fcfc2e94a..041300bed 100644 --- a/src/libstore/include/nix/store/globals.hh +++ b/src/libstore/include/nix/store/globals.hh @@ -1248,7 +1248,7 @@ public: R"( Helper programs that execute derivations. - The program is passed a JSON document that describes the build environment as the final argument. + The program is passed a JSON document that describes the build environment on standard input. The JSON document looks like this: { diff --git a/src/libstore/unix/build/external-derivation-builder.cc b/src/libstore/unix/build/external-derivation-builder.cc index 1906ddd70..9fe0eb19f 100644 --- a/src/libstore/unix/build/external-derivation-builder.cc +++ b/src/libstore/unix/build/external-derivation-builder.cc @@ -4,6 +4,11 @@ struct ExternalDerivationBuilder : DerivationBuilderImpl { Settings::ExternalBuilder externalBuilder; + /** + * Pipe for talking to the spawned builder. + */ + Pipe toBuilder; + ExternalDerivationBuilder( Store & store, std::unique_ptr miscMethods, @@ -83,23 +88,22 @@ struct ExternalDerivationBuilder : DerivationBuilderImpl json.emplace("realStoreDir", getLocalStore(store).config->realStoreDir.get()); json.emplace("system", drv.platform); - // FIXME: maybe write this JSON into the builder's stdin instead....? - auto jsonFile = topTmpDir + "/build.json"; - writeFile(jsonFile, json.dump()); + toBuilder.create(); pid = startProcess([&]() { openSlave(); try { commonChildInit(); + if (dup2(toBuilder.readSide.get(), STDIN_FILENO) == -1) + throw SysError("duping to-builder read side to builder's stdin"); + Strings args = {externalBuilder.program}; if (!externalBuilder.args.empty()) { args.insert(args.end(), externalBuilder.args.begin(), externalBuilder.args.end()); } - args.insert(args.end(), jsonFile); - debug("executing external builder: %s", concatStringsSep(" ", args)); execv(externalBuilder.program.c_str(), stringsToCharPtrs(args).data()); @@ -109,6 +113,9 @@ struct ExternalDerivationBuilder : DerivationBuilderImpl _exit(1); } }); + + writeFull(toBuilder.writeSide.get(), json.dump()); + toBuilder.close(); } };