@@ -6,15 +6,15 @@ use anyhow::Context;
66use relative_path:: RelativePathBuf ;
77use serde:: Deserialize ;
88
9- use crate :: NixFileStore ;
109use crate :: nix_file:: CallPackageArgumentInfo ;
1110use crate :: problem:: {
1211 npv_100, npv_101, npv_102, npv_103, npv_104, npv_105, npv_106, npv_107, npv_108, npv_120,
1312} ;
1413use crate :: ratchet:: RatchetState :: { Loose , Tight } ;
15- use crate :: structure:: { self , Config } ;
14+ use crate :: structure:: { self , ByNameDir , Config } ;
1615use crate :: validation:: ResultIteratorExt as _;
1716use crate :: validation:: { self , Validation :: Success } ;
17+ use crate :: NixFileStore ;
1818use crate :: { location, ratchet} ;
1919
2020const EVAL_NIX : & [ u8 ] = include_bytes ! ( "eval.nix" ) ;
@@ -159,6 +159,7 @@ pub fn check_values(
159159 nixpkgs_path : & Path ,
160160 nix_file_store : & mut NixFileStore ,
161161 package_names : & [ String ] ,
162+ by_name_dir : & ByNameDir ,
162163 config : & Config ,
163164) -> validation:: Result < BTreeMap < String , ratchet:: Package > > {
164165 let work_dir = tempfile:: Builder :: new ( )
@@ -169,6 +170,8 @@ pub fn check_values(
169170 // Canonicalize the path so that if a symlink were returned, we wouldn't ask Nix to follow it.
170171 let work_dir_path = work_dir. path ( ) . canonicalize ( ) ?;
171172
173+ println ! ( "package_names: {}" , package_names. join( ", " ) ) ;
174+
172175 // Write the list of packages we need to check into a temporary JSON file.
173176 let package_names_path = work_dir_path. join ( "package-names.json" ) ;
174177 let package_names_file = fs:: File :: create ( & package_names_path) ?;
@@ -224,7 +227,11 @@ pub fn check_values(
224227
225228 if !result. status . success ( ) {
226229 // Early return in case evaluation fails
227- return Ok ( npv_120:: NixEvalError :: new ( String :: from_utf8_lossy ( & result. stderr ) ) . into ( ) ) ;
230+ return Ok ( npv_120:: NixEvalError :: new (
231+ String :: from_utf8_lossy ( & result. stderr ) ,
232+ by_name_dir. clone ( ) ,
233+ )
234+ . into ( ) ) ;
228235 }
229236
230237 // Parse the resulting JSON value
@@ -247,13 +254,15 @@ pub fn check_values(
247254 & attribute_name,
248255 non_by_name_attribute,
249256 config,
257+ by_name_dir,
250258 ) ?,
251259 Attribute :: ByName ( by_name_attribute) => by_name (
252260 nix_file_store,
253261 nixpkgs_path,
254262 & attribute_name,
255263 by_name_attribute,
256264 config,
265+ by_name_dir,
257266 ) ?,
258267 } ;
259268 Ok :: < _ , anyhow:: Error > ( check_result. map ( |value| ( attribute_name. clone ( ) , value) ) )
@@ -271,16 +280,18 @@ fn by_name(
271280 attribute_name : & str ,
272281 by_name_attribute : ByNameAttribute ,
273282 config : & Config ,
283+ by_name_dir : & ByNameDir ,
274284) -> validation:: Result < ratchet:: Package > {
275- // At this point we know that `pkgs/by-name/fo/foo/package.nix` has to exists. This match
285+ println ! ( "attribute_name: {attribute_name}" ) ;
286+ // At this point we know that `pkgs/by-name/fo/foo/package.nix` has to exist. This match
276287 // decides whether the attribute `foo` is defined accordingly and whether a legacy manual
277288 // definition could be removed.
278289 let manual_definition_result = match by_name_attribute {
279290 // The attribute is missing.
280291 ByNameAttribute :: Missing => {
281292 // This indicates a bug in the `pkgs/by-name` overlay, because it's supposed to
282293 // automatically define attributes in a `by-name` directory
283- npv_100:: ByNameUndefinedAttribute :: new ( attribute_name) . into ( )
294+ npv_100:: ByNameUndefinedAttribute :: new ( attribute_name, by_name_dir . clone ( ) ) . into ( )
284295 }
285296 // The attribute exists
286297 ByNameAttribute :: Existing ( AttributeInfo {
@@ -294,7 +305,7 @@ fn by_name(
294305 //
295306 // We can't know whether the attribute is automatically or manually defined for sure,
296307 // and while we could check the location, the error seems clear enough as is.
297- npv_101:: ByNameNonDerivation :: new ( attribute_name) . into ( )
308+ npv_101:: ByNameNonDerivation :: new ( attribute_name, by_name_dir . clone ( ) ) . into ( )
298309 }
299310 // The attribute exists
300311 ByNameAttribute :: Existing ( AttributeInfo {
@@ -310,7 +321,7 @@ fn by_name(
310321 let is_derivation_result = if is_derivation {
311322 Success ( ( ) )
312323 } else {
313- npv_101:: ByNameNonDerivation :: new ( attribute_name) . into ( )
324+ npv_101:: ByNameNonDerivation :: new ( attribute_name, by_name_dir . clone ( ) ) . into ( )
314325 } ;
315326
316327 // If the definition looks correct
@@ -366,6 +377,7 @@ fn by_name(
366377 definition,
367378 location,
368379 config,
380+ by_name_dir,
369381 )
370382 } else {
371383 // If manual definitions don't have a location, it's likely `mapAttrs`'d
@@ -401,13 +413,15 @@ fn by_name_override(
401413 definition : String ,
402414 location : location:: Location ,
403415 config : & Config ,
416+ by_name_dir : & ByNameDir ,
404417) -> validation:: Validation < ratchet:: RatchetState < ratchet:: ManualDefinition > > {
405418 let Some ( syntactic_call_package) = optional_syntactic_call_package else {
406419 // Something like `<attr> = foo`
407420 return npv_104:: ByNameOverrideOfNonSyntacticCallPackage :: new (
408421 attribute_name,
409422 location,
410423 definition,
424+ by_name_dir. clone ( ) ,
411425 )
412426 . into ( ) ;
413427 } ;
@@ -418,13 +432,19 @@ fn by_name_override(
418432 attribute_name,
419433 location,
420434 definition,
435+ by_name_dir. clone ( ) ,
421436 )
422437 . into ( ) ;
423438 }
424439
425440 let Some ( actual_package_path) = syntactic_call_package. relative_path else {
426- return npv_108:: ByNameOverrideContainsEmptyPath :: new ( attribute_name, location, definition)
427- . into ( ) ;
441+ return npv_108:: ByNameOverrideContainsEmptyPath :: new (
442+ attribute_name,
443+ location,
444+ definition,
445+ by_name_dir. clone ( ) ,
446+ )
447+ . into ( ) ;
428448 } ;
429449
430450 let expected_by_name_dir = structure:: expected_by_name_dir_for_package ( attribute_name, config) ;
@@ -436,6 +456,7 @@ fn by_name_override(
436456 attribute_name,
437457 actual_package_path,
438458 location,
459+ by_name_dir. clone ( ) ,
439460 )
440461 . into ( ) ;
441462 }
@@ -444,8 +465,13 @@ fn by_name_override(
444465 // continue to be allowed. This is the state to migrate away from.
445466 if syntactic_call_package. empty_arg {
446467 Success ( Loose (
447- npv_107:: ByNameOverrideContainsEmptyArgument :: new ( attribute_name, location, definition)
448- . into ( ) ,
468+ npv_107:: ByNameOverrideContainsEmptyArgument :: new (
469+ attribute_name,
470+ location,
471+ definition,
472+ by_name_dir. clone ( ) ,
473+ )
474+ . into ( ) ,
449475 ) )
450476 } else {
451477 // This is the state to migrate to.
@@ -461,9 +487,10 @@ fn handle_non_by_name_attribute(
461487 attribute_name : & str ,
462488 non_by_name_attribute : NonByNameAttribute ,
463489 config : & Config ,
490+ by_name_dir : & ByNameDir ,
464491) -> validation:: Result < ratchet:: Package > {
465- use NonByNameAttribute :: EvalSuccess ;
466492 use ratchet:: RatchetState :: { Loose , NonApplicable , Tight } ;
493+ use NonByNameAttribute :: EvalSuccess ;
467494
468495 // The ratchet state whether this attribute uses a `by-name` directory
469496 //
@@ -573,7 +600,7 @@ fn handle_non_by_name_attribute(
573600 _ => {
574601 // Otherwise, the path is outside a `by-name` directory, which means it can be
575602 // migrated.
576- Loose ( ( syntactic_call_package, location. file ) )
603+ Loose ( ( syntactic_call_package, location. file , by_name_dir . to_owned ( ) ) )
577604 }
578605 }
579606 }
0 commit comments