@@ -22,6 +22,7 @@ import mcl.utils.json : toJSON;
2222import mcl.utils.path : rootDir, resultDir, gcRootsDir, createResultDirs;
2323import mcl.utils.process : execute;
2424import mcl.utils.nix : nix;
25+ import mcl.utils.cachix : cachixNixStoreUrl;
2526
2627enum GitHubOS
2728{
@@ -141,18 +142,12 @@ version (unittest)
141142 ];
142143}
143144
144- immutable Params params;
145-
146- version (unittest ) {} else
147- shared static this ()
148- {
149- params = parseEnv! Params;
150- }
151-
152145export void ci_matrix ()
153146{
147+ Params params = parseEnv! Params;
148+
154149 createResultDirs();
155- nixEvalForAllSystems().array.printTableForCacheStatus();
150+ nixEvalForAllSystems(params ).array.printTableForCacheStatus(params );
156151}
157152
158153string flakeAttr (string prefix, SupportedSystem system, string postfix)
@@ -167,14 +162,14 @@ string flakeAttr(string prefix, string arch, string os, string postfix)
167162 return " %s.%s-%s%s" .fmt(prefix, arch, os, postfix);
168163}
169164
170- Package[] checkCacheStatus (Package[] packages)
165+ Package[] checkCacheStatus (Package[] packages, string cachixAuthToken )
171166{
172167 import std.array : appender;
173168 import std.parallelism : parallel;
174169
175170 foreach (ref pkg; packages.parallel)
176171 {
177- pkg = checkPackage(pkg);
172+ pkg = checkPackage(pkg, cachixAuthToken );
178173 struct Output { string isCached, name, storePath; }
179174 auto res = appender! string ;
180175 writeRecordAsTable(
@@ -188,11 +183,13 @@ Package[] checkCacheStatus(Package[] packages)
188183
189184export void print_table ()
190185{
186+ Params params = parseEnv! Params;
187+
191188 createResultDirs();
192189
193- getPrecalcMatrix()
194- .checkCacheStatus()
195- .printTableForCacheStatus();
190+ getPrecalcMatrix(params )
191+ .checkCacheStatus(params.cachixAuthToken )
192+ .printTableForCacheStatus(params );
196193}
197194
198195struct Params
@@ -304,12 +301,12 @@ unittest
304301 }
305302}
306303
307- Package[] nixEvalJobs (string flakeAttrPrefix, string cachixUrl, bool doCheck = true )
304+ Package[] nixEvalJobs (string flakeAttrPrefix, Params params, string cachixUrl, bool doCheck = true )
308305{
309306 Package[] result = [];
310307
311- int maxMemoryMB = getAvailableMemoryMB();
312- int maxWorkers = getNixEvalWorkerCount();
308+ int maxMemoryMB = getAvailableMemoryMB(params.maxMemory );
309+ int maxWorkers = getNixEvalWorkerCount(params.maxWorkers );
313310
314311 const args = [
315312 " nix-eval-jobs" , " --quiet" , " --option" , " warn-dirty" , " false" ,
@@ -347,7 +344,7 @@ Package[] nixEvalJobs(string flakeAttrPrefix, string cachixUrl, bool doCheck = t
347344 Package pkg = json.packageFromNixEvalJobsJson(
348345 flakeAttrPrefix, cachixUrl);
349346
350- if (doCheck)pkg = pkg.checkPackage();
347+ if (doCheck)pkg = pkg.checkPackage(params.cachixAuthToken );
351348
352349 result ~= pkg;
353350
@@ -365,14 +362,19 @@ Package[] nixEvalJobs(string flakeAttrPrefix, string cachixUrl, bool doCheck = t
365362 output: pkg.output
366363 ).writeRecordAsTable(stderr.lockingTextWriter);
367364 }
365+
366+ string bufferedOutput = " " ;
368367 foreach (line; pipes.stderr.byLine)
369368 {
370369 if (uselessWarnings.map! ((warning) => line.indexOf(warning) != - 1 ).any)
371370 continue ;
372371
373- logError(line.idup);
372+ bufferedOutput ~= line ~ " \n " ;
373+ // logError(line.idup);
374374 }
375375
376+ logError(bufferedOutput);
377+
376378 int status = wait(pipes.pid);
377379 enforce(status == 0 , " Command `%s` failed with status %s" .fmt(args, status));
378380
@@ -396,26 +398,26 @@ SupportedSystem[] getSupportedSystems(string flakeRef = ".")
396398 return json.array.map! (system => getSystem(system.str)).array;
397399}
398400
399- Package[] nixEvalForAllSystems ()
401+ Package[] nixEvalForAllSystems (Params params )
400402{
401- const cachixUrl = " https:// " ~ params.cachixCache ~ " .cachix.org " ;
403+ const cachixUrl = cachixNixStoreUrl( params.cachixCache) ;
402404 const systems = getSupportedSystems();
403405
404406 infof(" Evaluating flake for: %s" , systems);
405407
406408 return systems.map! (system =>
407409 flakeAttr(params.flakePre, system, params.flakePost)
408- .nixEvalJobs(cachixUrl)
410+ .nixEvalJobs(params, cachixUrl)
409411 )
410412 .reduce! ((a, b) => a ~ b)
411413 .array
412414 .sort! ((a, b) => a.name < b.name)
413415 .array;
414416}
415417
416- int getNixEvalWorkerCount ()
418+ int getNixEvalWorkerCount (int maxWorkers )
417419{
418- return params. maxWorkers == 0 ? (threadsPerCPU() < 8 ? threadsPerCPU() : 8 ) : params. maxWorkers;
420+ return maxWorkers == 0 ? (threadsPerCPU() < 8 ? threadsPerCPU() : 8 ) : maxWorkers;
419421}
420422
421423@(" getNixEvalWorkerCount" )
@@ -424,7 +426,7 @@ unittest
424426 assert (getNixEvalWorkerCount() == (threadsPerCPU() < 8 ? threadsPerCPU() : 8 ));
425427}
426428
427- int getAvailableMemoryMB ()
429+ int getAvailableMemoryMB (int maxMemory )
428430{
429431
430432 // free="$(< /proc/meminfo grep MemFree | tr -s ' ' | cut -d ' ' -f 2)"
@@ -448,15 +450,15 @@ int getAvailableMemoryMB()
448450 .find! (a => a.indexOf(" Shmem:" ) != - 1 )
449451 .front
450452 .split[1 ].to! int ;
451- int maxMemoryMB = params.maxMemory == 0 ? ((free + cached + buffers + shmem) / 1024 )
452- : params.maxMemory;
453+ int maxMemoryMB = maxMemory == 0 ? ((free + cached + buffers + shmem) / 1024 ) : maxMemory;
453454 return maxMemoryMB;
454455}
455456
456457@(" getAvailableMemoryMB" )
457458unittest
458459{
459- assert (getAvailableMemoryMB() > 0 );
460+ Params params = parseEnv! Params;
461+ assert (getAvailableMemoryMB(params.maxMemory) > 0 );
460462}
461463
462464void saveCachixDeploySpec (Package[] packages)
@@ -481,12 +483,12 @@ unittest
481483 assert (testPackageArray[1 ].output == deploySpec[0 ][" out" ].str);
482484}
483485
484- void saveGHCIMatrix (Package[] packages)
486+ void saveGHCIMatrix (Package[] packages, bool isInitial )
485487{
486488 auto matrix = JSONValue([
487489 " include" : JSONValue(packages.map! (pkg => pkg.toJSON()).array)
488490 ]);
489- string resPath = rootDir.buildPath(params. isInitial ? " matrix-pre.json" : " matrix-post.json" );
491+ string resPath = rootDir.buildPath(isInitial ? " matrix-pre.json" : " matrix-post.json" );
490492 resPath.write(JSONValue(matrix).toString(JSONOptions.doNotEscapeSlashes));
491493}
492494
@@ -495,8 +497,10 @@ unittest
495497{
496498 import std.file : rmdirRecurse;
497499
500+ Params params = parseEnv! Params;
501+
498502 createResultDirs();
499- saveGHCIMatrix(cast (Package[]) testPackageArray);
503+ saveGHCIMatrix(cast (Package[]) testPackageArray, params.isInitial );
500504 JSONValue matrix = rootDir
501505 .buildPath(params.isInitial ? " matrix-pre.json" : " matrix-post.json" )
502506 .readText
@@ -624,24 +628,24 @@ unittest
624628
625629}
626630
627- void printTableForCacheStatus (Package[] packages)
631+ void printTableForCacheStatus (Package[] packages, Params params )
628632{
629633 if (params.precalcMatrix == " " )
630634 {
631- saveGHCIMatrix(packages);
635+ saveGHCIMatrix(packages, params.isInitial );
632636 }
633637 saveCachixDeploySpec(packages);
634638 saveGHCIComment(convertNixEvalToTableSummary(packages, params.isInitial));
635639}
636640
637- Package checkPackage (Package pkg)
641+ Package checkPackage (Package pkg, ref string cachixAuthToken )
638642{
639643 import std.algorithm : canFind;
640644 import std.string : lineSplitter;
641645 import std.net.curl : HTTP , httpGet = get , HTTPStatusException;
642646
643647 auto http = HTTP ();
644- http.addRequestHeader(" Authorization" , " Bearer " ~ params. cachixAuthToken);
648+ http.addRequestHeader(" Authorization" , " Bearer " ~ cachixAuthToken);
645649
646650 try
647651 {
@@ -663,6 +667,8 @@ Package checkPackage(Package pkg)
663667@(" checkPackage" )
664668unittest
665669{
670+ Params params = parseEnv! Params;
671+
666672 const nixosCacheEndpoint = " https://cache.nixos.org/" ;
667673 const storePathHash = " mdb034kf7sq6g03ric56jxr4a7043l41" ;
668674 const storePath = " /nix/store/" ~ storePathHash ~ " -hello-2.12.1" ;
@@ -673,14 +679,14 @@ unittest
673679 );
674680
675681 assert (! testPackage.isCached);
676- assert (checkPackage(testPackage).isCached);
682+ assert (checkPackage(testPackage, params.cachixAuthToken ).isCached);
677683
678684 testPackage.cacheUrl = nixosCacheEndpoint ~ " nonexistent.narinfo" ;
679685
680- assert (! checkPackage(testPackage).isCached);
686+ assert (! checkPackage(testPackage, params.cachixAuthToken ).isCached);
681687}
682688
683- Package[] getPrecalcMatrix ()
689+ Package[] getPrecalcMatrix (Params params )
684690{
685691 auto precalcMatrixStr = params.precalcMatrix == " " ? " {\" include\" : []}" : params.precalcMatrix;
686692 enforce! MissingEnvVarsException(
0 commit comments