@@ -417,11 +417,25 @@ def nix_eval_config(
417
417
)
418
418
419
419
420
+ @dataclass
421
+ class CachixConfig :
422
+ name : str
423
+ signing_key_secret_name : str | None = None
424
+ auth_token_secret_name : str | None = None
425
+
426
+ def cachix_env (self ) -> dict [str , str ]:
427
+ env = {}
428
+ if self .signing_key_secret_name is not None :
429
+ env ["CACHIX_SIGNING_KEY" ] = util .Secret (self .signing_key_secret_name )
430
+ if self .auth_token_secret_name is not None :
431
+ env ["CACHIX_AUTH_TOKEN" ] = util .Secret (self .auth_token_secret_name )
432
+ return env
433
+
434
+
420
435
def nix_build_config (
421
436
project : GithubProject ,
422
437
worker_names : list [str ],
423
- has_cachix_auth_token : bool = False ,
424
- has_cachix_signing_key : bool = False ,
438
+ cachix : CachixConfig | None = None ,
425
439
outputs_path : Path | None = None ,
426
440
) -> util .BuilderConfig :
427
441
"""
@@ -454,19 +468,15 @@ def nix_build_config(
454
468
haltOnFailure = True ,
455
469
)
456
470
)
457
- if has_cachix_auth_token or has_cachix_signing_key :
458
- if has_cachix_signing_key :
459
- env = dict (CACHIX_SIGNING_KEY = util .Secret ("cachix-signing-key" ))
460
- else :
461
- env = dict (CACHIX_AUTH_TOKEN = util .Secret ("cachix-auth-token" ))
471
+ if cachix :
462
472
factory .addStep (
463
473
steps .ShellCommand (
464
474
name = "Upload cachix" ,
465
- env = env ,
475
+ env = cachix . cachix_env () ,
466
476
command = [
467
477
"cachix" ,
468
478
"push" ,
469
- util . Secret ( " cachix- name" ) ,
479
+ cachix . name ,
470
480
util .Interpolate ("result-%(prop:attr)s" ),
471
481
],
472
482
)
@@ -572,13 +582,13 @@ def token(self) -> str:
572
582
def config_for_project (
573
583
config : dict [str , Any ],
574
584
project : GithubProject ,
575
- credentials : str ,
576
585
worker_names : list [str ],
577
586
github : GithubConfig ,
578
587
nix_supported_systems : list [str ],
579
588
nix_eval_worker_count : int ,
580
589
nix_eval_max_memory_size : int ,
581
590
eval_lock : util .WorkerLock ,
591
+ cachix : CachixConfig | None = None ,
582
592
outputs_path : Path | None = None ,
583
593
) -> Project :
584
594
config ["projects" ].append (Project (project .name ))
@@ -635,12 +645,6 @@ def config_for_project(
635
645
),
636
646
]
637
647
)
638
- has_cachix_auth_token = os .path .isfile (
639
- os .path .join (credentials , "cachix-auth-token" )
640
- )
641
- has_cachix_signing_key = os .path .isfile (
642
- os .path .join (credentials , "cachix-signing-key" )
643
- )
644
648
config ["builders" ].extend (
645
649
[
646
650
# Since all workers run on the same machine, we only assign one of them to do the evaluation.
@@ -657,8 +661,7 @@ def config_for_project(
657
661
nix_build_config (
658
662
project ,
659
663
worker_names ,
660
- has_cachix_auth_token ,
661
- has_cachix_signing_key ,
664
+ cachix = cachix ,
662
665
outputs_path = outputs_path ,
663
666
),
664
667
nix_skipped_build_config (project , [SKIPPED_BUILDER_NAME ]),
@@ -756,6 +759,7 @@ def __init__(
756
759
nix_eval_worker_count : int | None ,
757
760
nix_eval_max_memory_size : int ,
758
761
nix_workers_secret_name : str = "buildbot-nix-workers" ,
762
+ cachix : CachixConfig | None = None ,
759
763
outputs_path : str | None = None ,
760
764
) -> None :
761
765
super ().__init__ ()
@@ -765,7 +769,7 @@ def __init__(
765
769
self .nix_supported_systems = nix_supported_systems
766
770
self .github = github
767
771
self .url = url
768
- self .systemd_credentials_dir = os . environ [ "CREDENTIALS_DIRECTORY" ]
772
+ self .cachix = cachix
769
773
if outputs_path is None :
770
774
self .outputs_path = None
771
775
else :
@@ -803,13 +807,13 @@ def configure(self, config: dict[str, Any]) -> None:
803
807
config_for_project (
804
808
config ,
805
809
project ,
806
- self .systemd_credentials_dir ,
807
810
worker_names ,
808
811
self .github ,
809
812
self .nix_supported_systems ,
810
813
self .nix_eval_worker_count or multiprocessing .cpu_count (),
811
814
self .nix_eval_max_memory_size ,
812
815
eval_lock ,
816
+ self .cachix ,
813
817
self .outputs_path ,
814
818
)
815
819
0 commit comments