Skip to content

Commit d8bda44

Browse files
authored
Merge pull request #120 from DeterminateSystems/external-builder-allow-args
Allow specifying args to external builder program
2 parents 5842d54 + a20a7fa commit d8bda44

File tree

3 files changed

+73
-2
lines changed

3 files changed

+73
-2
lines changed

src/libstore/globals.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ unsigned int MaxBuildJobsSetting::parse(const std::string & str) const
309309
}
310310
}
311311

312-
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Settings::ExternalBuilder, systems, program);
312+
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Settings::ExternalBuilder, systems, program, args);
313313

314314
template<> Settings::ExternalBuilders BaseSetting<Settings::ExternalBuilders>::parse(const std::string & str) const
315315
{

src/libstore/include/nix/store/globals.hh

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,6 +1241,7 @@ public:
12411241
{
12421242
std::vector<std::string> systems;
12431243
Path program;
1244+
std::optional<std::vector<std::string>> args;
12441245
};
12451246

12461247
using ExternalBuilders = std::vector<ExternalBuilder>;
@@ -1251,6 +1252,68 @@ public:
12511252
"external-builders",
12521253
R"(
12531254
Helper programs that execute derivations.
1255+
1256+
The program is passed a JSON document that describes the build environment as the final argument.
1257+
The JSON document looks like this:
1258+
1259+
{
1260+
"args": [
1261+
"-e",
1262+
"/nix/store/vj1c3wf9c11a0qs6p3ymfvrnsdgsdcbq-source-stdenv.sh",
1263+
"/nix/store/shkw4qm9qcw5sc5n1k5jznc83ny02r39-default-builder.sh"
1264+
],
1265+
"builder": "/nix/store/s1qkj0ph0ma64a6743mvkwnabrbw1hsc-bash-5.2p37/bin/bash",
1266+
"env": {
1267+
"HOME": "/homeless-shelter",
1268+
"NIX_BUILD_CORES": "14",
1269+
"NIX_BUILD_TOP": "/build",
1270+
"NIX_LOG_FD": "2",
1271+
"NIX_STORE": "/nix/store",
1272+
"PATH": "/path-not-set",
1273+
"PWD": "/build",
1274+
"TEMP": "/build",
1275+
"TEMPDIR": "/build",
1276+
"TERM": "xterm-256color",
1277+
"TMP": "/build",
1278+
"TMPDIR": "/build",
1279+
"__structuredAttrs": "",
1280+
"buildInputs": "",
1281+
"builder": "/nix/store/s1qkj0ph0ma64a6743mvkwnabrbw1hsc-bash-5.2p37/bin/bash",
1282+
"cmakeFlags": "",
1283+
"configureFlags": "",
1284+
"depsBuildBuild": "",
1285+
"depsBuildBuildPropagated": "",
1286+
"depsBuildTarget": "",
1287+
"depsBuildTargetPropagated": "",
1288+
"depsHostHost": "",
1289+
"depsHostHostPropagated": "",
1290+
"depsTargetTarget": "",
1291+
"depsTargetTargetPropagated": "",
1292+
"doCheck": "1",
1293+
"doInstallCheck": "1",
1294+
"mesonFlags": "",
1295+
"name": "hello-2.12.2",
1296+
"nativeBuildInputs": "/nix/store/l31j72f1h33hsa4nq4iyhsmsqjyndq9f-version-check-hook",
1297+
"out": "/nix/store/2yx2prgxmzbkrnbb4liy6n4zkzb1cqai-hello-2.12.2",
1298+
"outputs": "out",
1299+
"patches": "",
1300+
"pname": "hello",
1301+
"postInstallCheck": "stat \"${!outputBin}/bin/hello\"\n",
1302+
"propagatedBuildInputs": "",
1303+
"propagatedNativeBuildInputs": "",
1304+
"src": "/nix/store/dw402azxjrgrzrk6j0p66wkqrab5mwgw-hello-2.12.2.tar.gz",
1305+
"stdenv": "/nix/store/i8bw5nqg1225m281zr6lgsz42bw04z7g-stdenv-linux",
1306+
"strictDeps": "",
1307+
"system": "aarch64-linux",
1308+
"version": "2.12.2"
1309+
},
1310+
"realStoreDir": "/nix/store",
1311+
"storeDir": "/nix/store",
1312+
"system": "aarch64-linux",
1313+
"tmpDir": "/private/tmp/nix-build-hello-2.12.2.drv-0/build",
1314+
"tmpDirInSandbox": "/build",
1315+
"topTmpDir": "/private/tmp/nix-build-hello-2.12.2.drv-0"
1316+
}
12541317
)"
12551318
};
12561319
};

src/libstore/unix/build/external-derivation-builder.cc

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ struct ExternalDerivationBuilder : DerivationBuilderImpl
8383
json.emplace("realStoreDir", getLocalStore(store).config->realStoreDir.get());
8484
json.emplace("system", drv.platform);
8585

86+
// FIXME: maybe write this JSON into the builder's stdin instead....?
8687
auto jsonFile = topTmpDir + "/build.json";
8788
writeFile(jsonFile, json.dump());
8889

@@ -91,8 +92,15 @@ struct ExternalDerivationBuilder : DerivationBuilderImpl
9192
try {
9293
commonChildInit();
9394

94-
Strings args = {externalBuilder.program, jsonFile};
95+
Strings args = {externalBuilder.program};
9596

97+
if (externalBuilder.args) {
98+
args.insert(args.end(), externalBuilder.args->begin(), externalBuilder.args->end());
99+
}
100+
101+
args.insert(args.end(), jsonFile);
102+
103+
debug("executing external builder: %s", concatStringsSep(" ", args));
96104
execv(externalBuilder.program.c_str(), stringsToCharPtrs(args).data());
97105

98106
throw SysError("executing '%s'", externalBuilder.program);

0 commit comments

Comments
 (0)