@@ -105,8 +105,8 @@ def __init__(
105105 build_graph : str ,
106106 nixpkgs_config : Path ,
107107 extra_nixpkgs_config : str ,
108+ eval_type : str ,
108109 api_token : str | None = None ,
109- use_github_eval : bool | None = True ,
110110 only_packages : set [str ] | None = None ,
111111 additional_packages : set [str ] | None = None ,
112112 package_regexes : list [Pattern [str ]] | None = None ,
@@ -135,8 +135,9 @@ def __init__(
135135 self .no_shell = no_shell
136136 self .run = run
137137 self .remote = remote
138+ self .api_token = api_token
138139 self .github_client = GithubClient (api_token )
139- self .use_github_eval = use_github_eval and not only_packages
140+ self .eval_type = eval_type
140141 self .checkout = checkout
141142 self .only_packages = only_packages
142143 self .additional_packages = additional_packages
@@ -164,6 +165,54 @@ def __init__(
164165 self .head_commit : str | None = None
165166 self .pr_object = pr_object
166167
168+ @property
169+ def _use_github_eval (self ) -> bool :
170+ # If the user explicitly asks for local eval, just do it
171+ if self .eval_type == "local" :
172+ return False
173+
174+ if self .only_packages :
175+ return False
176+
177+ # Handle the GH_TOKEN eventually not being provided
178+ if not self .api_token :
179+ warn ("No GitHub token provided via GITHUB_TOKEN variable." )
180+ match self .eval_type :
181+ case "auto" :
182+ warn (
183+ "Falling back to local evaluation.\n "
184+ "Tip: Install the `gh` command line tool and run `gh auth login` to authenticate."
185+ )
186+ return False
187+ case "github" :
188+ sys .exit (1 )
189+
190+ # GHA evaluation only evaluates nixpkgs with an empty config.
191+ # Its results might be incorrect when a non-default nixpkgs config is requested
192+ normalized_config = self .extra_nixpkgs_config .replace (" " , "" )
193+
194+ if normalized_config == "{}" :
195+ return True
196+
197+ warn ("Non-default --extra-nixpkgs-config provided." )
198+ match self .eval_type :
199+ # By default, fall back to local evaluation
200+ case "auto" :
201+ warn ("Falling back to local evaluation" )
202+ return False
203+
204+ # If the user explicitly requires GitHub eval, warn him, but proceed
205+ case "github" :
206+ warn (
207+ "Forcing `github` evaluation -> Be warned that the evaluation results might not correspond to the provided nixpkgs config"
208+ )
209+ return True
210+
211+ # This should never happen
212+ case _:
213+ warn ("Invalid eval_type" )
214+ sys .exit (1 )
215+
167216 def _process_aliases_for_systems (self , system : str ) -> set [str ]:
168217 match system :
169218 case "current" :
@@ -422,16 +471,7 @@ def build_pr(self, pr_number: int) -> dict[System, list[Attr]]:
422471
423472 packages_per_system : dict [System , set [str ]] | None = None
424473
425- # GHA evaluation only evaluates nixpkgs with an empty config.
426- # Its results should not be used when a non-default nixpkgs config is requested
427- normalized_config = self .extra_nixpkgs_config .replace (" " , "" )
428- if self .use_github_eval and (normalized_config != "{}" ):
429- print (
430- "Non-default --extra-nixpkgs-config provided. Falling back to local evaluation"
431- )
432- self .use_github_eval = False
433-
434- if self .use_github_eval :
474+ if self ._use_github_eval :
435475 assert all (system in PLATFORMS for system in self .systems )
436476 print ("-> Fetching eval results from GitHub actions" )
437477
@@ -911,6 +951,7 @@ def review_local_revision(
911951 run = args .run ,
912952 remote = args .remote ,
913953 only_packages = set (args .package ),
954+ eval_type = "local" ,
914955 additional_packages = set (args .additional_package ),
915956 package_regexes = args .package_regex ,
916957 skip_packages = set (args .skip_package ),
0 commit comments