66#include < tuple>
77#include < iomanip>
88#ifdef __APPLE__
9- #include < sys/time.h>
9+ # include < sys/time.h>
1010#endif
1111
1212#include " nix/store/machines.hh"
2626using namespace nix ;
2727using std::cin;
2828
29- static void handleAlarm (int sig) {
30- }
29+ static void handleAlarm (int sig) {}
3130
3231std::string escapeUri (std::string uri)
3332{
@@ -42,13 +41,15 @@ static AutoCloseFD openSlotLock(const Machine & m, uint64_t slot)
4241 return openLockFile (fmt (" %s/%s-%d" , currentLoad, escapeUri (m.storeUri .render ()), slot), true );
4342}
4443
45- static bool allSupportedLocally (Store & store, const std::set<std::string>& requiredFeatures) {
44+ static bool allSupportedLocally (Store & store, const std::set<std::string> & requiredFeatures)
45+ {
4646 for (auto & feature : requiredFeatures)
47- if (!store.systemFeatures .get ().count (feature)) return false ;
47+ if (!store.systemFeatures .get ().count (feature))
48+ return false ;
4849 return true ;
4950}
5051
51- static int main_build_remote (int argc, char * * argv)
52+ static int main_build_remote (int argc, char ** argv)
5253{
5354 {
5455 logger = makeJSONLogger (getStandardError ());
@@ -85,7 +86,7 @@ static int main_build_remote(int argc, char * * argv)
8586 that gets cleared on reboot, but it wouldn't work on macOS. */
8687 auto currentLoadName = " /current-load" ;
8788 if (auto localStore = store.dynamic_pointer_cast <LocalFSStore>())
88- currentLoad = std::string { localStore->stateDir } + currentLoadName;
89+ currentLoad = std::string{ localStore->stateDir } + currentLoadName;
8990 else
9091 currentLoad = settings.nixStateDir + currentLoadName;
9192
@@ -107,8 +108,11 @@ static int main_build_remote(int argc, char * * argv)
107108
108109 try {
109110 auto s = readString (source);
110- if (s != " try" ) return 0 ;
111- } catch (EndOfFile &) { return 0 ; }
111+ if (s != " try" )
112+ return 0 ;
113+ } catch (EndOfFile &) {
114+ return 0 ;
115+ }
112116
113117 auto amWilling = readInt (source);
114118 auto neededSystem = readString (source);
@@ -117,10 +121,10 @@ static int main_build_remote(int argc, char * * argv)
117121
118122 /* It would be possible to build locally after some builds clear out,
119123 so don't show the warning now: */
120- bool couldBuildLocally = maxBuildJobs > 0
121- && ( neededSystem == settings. thisSystem
122- || settings.extraPlatforms .get ().count (neededSystem) > 0 )
123- && allSupportedLocally (*store, requiredFeatures);
124+ bool couldBuildLocally =
125+ maxBuildJobs > 0
126+ && (neededSystem == settings. thisSystem || settings.extraPlatforms .get ().count (neededSystem) > 0 )
127+ && allSupportedLocally (*store, requiredFeatures);
124128 /* It's possible to build this locally right now: */
125129 bool canBuildLocally = amWilling && couldBuildLocally;
126130
@@ -139,11 +143,8 @@ static int main_build_remote(int argc, char * * argv)
139143 for (auto & m : machines) {
140144 debug (" considering building on remote machine '%s'" , m.storeUri .render ());
141145
142- if (m.enabled &&
143- m.systemSupported (neededSystem) &&
144- m.allSupported (requiredFeatures) &&
145- m.mandatoryMet (requiredFeatures))
146- {
146+ if (m.enabled && m.systemSupported (neededSystem) && m.allSupported (requiredFeatures)
147+ && m.mandatoryMet (requiredFeatures)) {
147148 rightType = true ;
148149 AutoCloseFD free;
149150 uint64_t load = 0 ;
@@ -185,8 +186,7 @@ static int main_build_remote(int argc, char * * argv)
185186 if (!bestSlotLock) {
186187 if (rightType && !canBuildLocally)
187188 std::cerr << " # postpone\n " ;
188- else
189- {
189+ else {
190190 // build the hint template.
191191 std::string errorText =
192192 " Failed to find a machine for remote build!\n "
@@ -205,16 +205,11 @@ static int main_build_remote(int argc, char * * argv)
205205 drvstr = " <unknown>" ;
206206
207207 auto error = HintFmt::fromFormatString (errorText);
208- error
209- % drvstr
210- % neededSystem
211- % concatStringsSep<StringSet>(" , " , requiredFeatures)
208+ error % drvstr % neededSystem % concatStringsSep<StringSet>(" , " , requiredFeatures)
212209 % machines.size ();
213210
214211 for (auto & m : machines)
215- error
216- % concatStringsSep<StringSet>(" , " , m.systemTypes )
217- % m.maxJobs
212+ error % concatStringsSep<StringSet>(" , " , m.systemTypes ) % m.maxJobs
218213 % concatStringsSep<StringSet>(" , " , m.supportedFeatures )
219214 % concatStringsSep<StringSet>(" , " , m.mandatoryFeatures );
220215
@@ -242,9 +237,7 @@ static int main_build_remote(int argc, char * * argv)
242237 sshStore->connect ();
243238 } catch (std::exception & e) {
244239 auto msg = chomp (drainFD (5 , false ));
245- printError (" cannot build on '%s': %s%s" ,
246- storeUri, e.what (),
247- msg.empty () ? " " : " : " + msg);
240+ printError (" cannot build on '%s': %s%s" , storeUri, e.what (), msg.empty () ? " " : " : " + msg);
248241 bestMachine->enabled = false ;
249242 continue ;
250243 }
@@ -253,7 +246,7 @@ static int main_build_remote(int argc, char * * argv)
253246 }
254247 }
255248
256- connected:
249+ connected:
257250 close (5 );
258251
259252 assert (sshStore);
@@ -265,13 +258,14 @@ static int main_build_remote(int argc, char * * argv)
265258
266259 AutoCloseFD uploadLock;
267260 {
268- auto setUpdateLock = [&](auto && fileName){
261+ auto setUpdateLock = [&](auto && fileName) {
269262 uploadLock = openLockFile (currentLoad + " /" + escapeUri (fileName) + " .upload-lock" , true );
270263 };
271264 try {
272265 setUpdateLock (storeUri);
273266 } catch (SysError & e) {
274- if (e.errNo != ENAMETOOLONG) throw ;
267+ if (e.errNo != ENAMETOOLONG)
268+ throw ;
275269 // Try again hashing the store URL so we have a shorter path
276270 auto h = hashString (HashAlgorithm::MD5, storeUri);
277271 setUpdateLock (h.to_string (HashFormat::Base64, false ));
@@ -315,7 +309,7 @@ static int main_build_remote(int argc, char * * argv)
315309 //
316310 // This condition mirrors that: that code enforces the "rules" outlined there;
317311 // we do the best we can given those "rules".
318- if (trustedOrLegacy || drv.type ().isCA ()) {
312+ if (trustedOrLegacy || drv.type ().isCA ()) {
319313 // Hijack the inputs paths of the derivation to include all
320314 // the paths that come from the `inputDrvs` set. We don’t do
321315 // that for the derivations whose `inputDrvs` is empty
@@ -330,28 +324,26 @@ static int main_build_remote(int argc, char * * argv)
330324 optResult = sshStore->buildDerivation (*drvPath, (const BasicDerivation &) drv);
331325 auto & result = *optResult;
332326 if (!result.success ())
333- throw Error (" build of '%s' on '%s' failed: %s" , store->printStorePath (*drvPath), storeUri, result.errorMsg );
327+ throw Error (
328+ " build of '%s' on '%s' failed: %s" , store->printStorePath (*drvPath), storeUri, result.errorMsg );
334329 } else {
335- copyClosure (*store, *sshStore, StorePathSet {*drvPath}, NoRepair, NoCheckSigs, substitute);
336- auto res = sshStore->buildPathsWithResults ({
337- DerivedPath::Built {
338- .drvPath = makeConstantStorePathRef (*drvPath),
339- .outputs = OutputsSpec::All {},
340- }
341- });
330+ copyClosure (*store, *sshStore, StorePathSet{*drvPath}, NoRepair, NoCheckSigs, substitute);
331+ auto res = sshStore->buildPathsWithResults ({DerivedPath::Built{
332+ .drvPath = makeConstantStorePathRef (*drvPath),
333+ .outputs = OutputsSpec::All{},
334+ }});
342335 // One path to build should produce exactly one build result
343336 assert (res.size () == 1 );
344337 optResult = std::move (res[0 ]);
345338 }
346339
347-
348340 auto outputHashes = staticOutputHashes (*store, drv);
349341 std::set<Realisation> missingRealisations;
350342 StorePathSet missingPaths;
351343 if (experimentalFeatureSettings.isEnabled (Xp::CaDerivations) && !drv.type ().hasKnownOutputPaths ()) {
352344 for (auto & outputName : wantedOutputs) {
353345 auto thisOutputHash = outputHashes.at (outputName);
354- auto thisOutputId = DrvOutput{ thisOutputHash, outputName };
346+ auto thisOutputId = DrvOutput{thisOutputHash, outputName};
355347 if (!store->queryRealisation (thisOutputId)) {
356348 debug (" missing output %s" , outputName);
357349 assert (optResult);
0 commit comments