Skip to content

Commit 4334122

Browse files
committed
treefmt
1 parent df6d7c1 commit 4334122

File tree

10 files changed

+70
-61
lines changed

10 files changed

+70
-61
lines changed

src/eval.nix

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ let
4545
# This overrides the above `callPackage` information. It's OK because we don't need that one,
4646
# since `pkgs/by-name` always uses `callPackage` underneath.
4747
_internalCallByNamePackageFile =
48-
file:
49-
addVariantInfo (prev._internalCallByNamePackageFile file) { AutoDefinition = null; };
48+
file: addVariantInfo (prev._internalCallByNamePackageFile file) { AutoDefinition = null; };
5049
};
5150

5251
# We can't just replace attribute values with their info in the overlay, because attributes can
@@ -91,7 +90,14 @@ let
9190
location = builtins.unsafeGetAttrPos (trace "eval.nix:89: attrPath = ${builtins.toJSON attrPath}; location = ${builtins.toJSON (builtins.unsafeGetAttrPos pname parent)}" pname) parent;
9291
# location = builtins.unsafeGetAttrPos pname parent;
9392
attribute_variant = (
94-
if (trace "path ${builtins.toJSON attrPath}; isAttrs: ${pkgs.lib.boolToString (builtins.isAttrs value)}; (value ? \"_callPackageVariant\") = ${pkgs.lib.boolToString (value ? "_callPackageVariant")}" (!(builtins.isAttrs value))) then
93+
if
94+
(trace
95+
"path ${builtins.toJSON attrPath}; isAttrs: ${pkgs.lib.boolToString (builtins.isAttrs value)}; (value ? \"_callPackageVariant\") = ${
96+
pkgs.lib.boolToString (value ? "_callPackageVariant")
97+
}"
98+
(!(builtins.isAttrs value))
99+
)
100+
then
95101
{ NonAttributeSet = null; }
96102
else
97103
{
@@ -111,7 +117,7 @@ let
111117
byNameAttrsForDir =
112118
byNameDir:
113119
pkgs.lib.mergeAttrsList (
114-
# pkgs.lib.foldl pkgs.lib.recursiveUpdate { } (
120+
# pkgs.lib.foldl pkgs.lib.recursiveUpdate { } (
115121
map (
116122
package:
117123
let
@@ -160,13 +166,14 @@ let
160166
# then (builtins.any pkgs.lib.id (pkgs.lib.mapAttrsToList attrSetIsOrContainsDerivation value))
161167
then
162168
(trace "${name} has recurseForDerivations true" (
163-
let result = builtins.any pkgs.lib.id (
164-
pkgs.lib.mapAttrsToList (
165-
k: v:
166-
(trace "Seeing if ${k} is or contains a derivation" (attrSetIsOrContainsDerivation k v))
167-
) value
168-
);
169-
in trace "`attrSetIsOrContainsDerivation ${name}` is ${pkgs.lib.boolToString result}" result
169+
let
170+
result = builtins.any pkgs.lib.id (
171+
pkgs.lib.mapAttrsToList (
172+
k: v: (trace "Seeing if ${k} is or contains a derivation" (attrSetIsOrContainsDerivation k v))
173+
) value
174+
);
175+
in
176+
trace "`attrSetIsOrContainsDerivation ${name}` is ${pkgs.lib.boolToString result}" result
170177
))
171178
else
172179
trace "isDerivation ${name} is false" false
@@ -205,7 +212,9 @@ let
205212
then
206213
(
207214
let
208-
recursiveResult = builtins.mapAttrs (newName: newValue: markNonByNameAttribute (attrPath ++ [newName]) newValue) value;
215+
recursiveResult = builtins.mapAttrs (
216+
newName: newValue: markNonByNameAttribute (attrPath ++ [ newName ]) newValue
217+
) value;
209218
in
210219
(trace "recursing into name = ${builtins.toJSON pname}" (
211220
builtins.seq (trace "result of recursing into ${builtins.toJSON pname}: ${builtins.toJSON recursiveResult}" recursiveResult) (
@@ -233,8 +242,7 @@ let
233242

234243
# Second-newest
235244
nonByNameAttrs = (
236-
builtins.mapAttrs markNonByNameAttribute
237-
(
245+
builtins.mapAttrs markNonByNameAttribute (
238246
builtins.removeAttrs pkgs (
239247
allAttrPaths ++ [ "lib" ] # Need to exclude lib to avoid infinite recursion
240248
)

src/eval.rs

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -255,10 +255,7 @@ pub fn check_values(
255255
if !result.status.success() {
256256
// println!("{}:{}: : eval failed for {full_path}", file!(), line!());
257257
// Early return in case evaluation fails
258-
return Ok(npv_120::NixEvalError::new(
259-
String::from_utf8_lossy(&result.stderr),
260-
)
261-
.into());
258+
return Ok(npv_120::NixEvalError::new(String::from_utf8_lossy(&result.stderr)).into());
262259
}
263260

264261
// println!("{}:{}: result (stderr): {}", file!(), line!(), std::str::from_utf8(result.stderr.as_slice()).unwrap());
@@ -331,7 +328,11 @@ fn by_name(
331328
ByNameAttribute::Missing => {
332329
// This indicates a bug in the `pkgs/by-name` overlay, because it's supposed to
333330
// automatically define attributes in a `by-name` directory
334-
npv_100::ByNameUndefinedAttribute::new(attribute_name, structure::expected_by_name_dir_for_package(attribute_name, config).unwrap()).into()
331+
npv_100::ByNameUndefinedAttribute::new(
332+
attribute_name,
333+
structure::expected_by_name_dir_for_package(attribute_name, config).unwrap(),
334+
)
335+
.into()
335336
}
336337
// The attribute exists
337338
ByNameAttribute::Existing(AttributeInfo {
@@ -345,7 +346,11 @@ fn by_name(
345346
//
346347
// We can't know whether the attribute is automatically or manually defined for sure,
347348
// and while we could check the location, the error seems clear enough as is.
348-
npv_101::ByNameNonDerivation::new(attribute_name, structure::expected_by_name_dir_for_package(attribute_name, config).unwrap()).into()
349+
npv_101::ByNameNonDerivation::new(
350+
attribute_name,
351+
structure::expected_by_name_dir_for_package(attribute_name, config).unwrap(),
352+
)
353+
.into()
349354
}
350355
// The attribute exists
351356
ByNameAttribute::Existing(AttributeInfo {
@@ -361,7 +366,11 @@ fn by_name(
361366
let is_derivation_result = if is_derivation {
362367
Success(())
363368
} else {
364-
npv_101::ByNameNonDerivation::new(attribute_name, structure::expected_by_name_dir_for_package(attribute_name, config).unwrap()).into()
369+
npv_101::ByNameNonDerivation::new(
370+
attribute_name,
371+
structure::expected_by_name_dir_for_package(attribute_name, config).unwrap(),
372+
)
373+
.into()
365374
};
366375

367376
// If the definition looks correct
@@ -501,12 +510,9 @@ fn by_name_override(
501510

502511
let expected_by_name_dir = structure::expected_by_name_dir_for_package(attribute_name, config);
503512

504-
505513
let expected_package_path = match expected_by_name_dir {
506514
None => return Success(ratchet::RatchetState::NonApplicable), // The package doesn't belong in a by-name directory.
507-
Some(x) => {
508-
structure::relative_file_for_package(attribute_name, &x.path)
509-
}
515+
Some(x) => structure::relative_file_for_package(attribute_name, &x.path),
510516
};
511517

512518
if actual_package_path != expected_package_path {

src/main.rs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ fn main() -> ExitCode {
6363
let config_file = Path::new(&config_file);
6464
let config = read_config(config_file);
6565

66-
let status: ColoredStatus =
67-
process(&args.base, &args.nixpkgs, &config).into();
66+
let status: ColoredStatus = process(&args.base, &args.nixpkgs, &config).into();
6867
eprintln!("{status}");
6968
status.into()
7069
}
@@ -187,11 +186,7 @@ fn main() -> ExitCode {
187186
/// - `base_nixpkgs`: Path to the base Nixpkgs to run ratchet checks against.
188187
/// - `main_nixpkgs`: Path to the main Nixpkgs to check.
189188
/// - `config`: The by-name configuration object
190-
fn process(
191-
base_nixpkgs: &Path,
192-
main_nixpkgs: &Path,
193-
config: &Config,
194-
) -> Status {
189+
fn process(base_nixpkgs: &Path, main_nixpkgs: &Path, config: &Config) -> Status {
195190
// println!("{}:{}: base_nixpkgs {base_nixpkgs:?}, main_nixpkgs {main_nixpkgs:?}", file!(), line!());
196191
let (base_result, main_result) = std::thread::scope(|s| {
197192
let base_thread = s.spawn(move || check_nixpkgs(base_nixpkgs, config));
@@ -230,9 +225,13 @@ fn process(
230225
let main_result = main_result.unwrap();
231226
match (base_result, main_result) {
232227
(Failure(base_errors), Failure(errors)) => {
233-
println!("{}:{}: base_errors {base_errors:?}, main errors {errors:?}", file!(), line!());
228+
println!(
229+
"{}:{}: base_errors {base_errors:?}, main errors {errors:?}",
230+
file!(),
231+
line!()
232+
);
234233
Status::BranchStillBroken(errors)
235-
},
234+
}
236235
(Success(..), Failure(errors)) => Status::ProblemsIntroduced(errors),
237236
(Failure(..), Success(..)) => Status::BranchHealed,
238237
(Success(base), Success(main)) => {
@@ -251,10 +250,7 @@ fn process(
251250
/// This does not include ratchet checks, see ../README.md#ratchet-checks
252251
/// Instead a `ratchet::Nixpkgs` value is returned, whose `compare` method allows performing the
253252
/// ratchet check against another result.
254-
fn check_nixpkgs(
255-
nixpkgs_path: &Path,
256-
config: &Config,
257-
) -> validation::Result<ratchet::Nixpkgs> {
253+
fn check_nixpkgs(nixpkgs_path: &Path, config: &Config) -> validation::Result<ratchet::Nixpkgs> {
258254
let nixpkgs_path = nixpkgs_path.canonicalize().with_context(|| {
259255
format!(
260256
"Nixpkgs path {} could not be resolved",
@@ -265,7 +261,7 @@ fn check_nixpkgs(
265261
let mut nix_file_store = NixFileStore::default();
266262

267263
let package_result = {
268-
let structure = check_structure(&nixpkgs_path, &mut nix_file_store, config)?;
264+
let structure = check_structure(&nixpkgs_path, &mut nix_file_store, config)?;
269265

270266
// Only if we could successfully parse the structure, we do the evaluation checks
271267
structure.result_map(|package_names| {

src/problem/npv_160.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ impl fmt::Display for TopLevelPackageMovedOutOfByName {
2525
file,
2626
config,
2727
} = self;
28-
let by_name_path =
29-
structure::expected_by_name_dir_for_package(package_name, config).unwrap().path;
28+
let by_name_path = structure::expected_by_name_dir_for_package(package_name, config)
29+
.unwrap()
30+
.path;
3031
let relative_package_file =
3132
structure::relative_file_for_package(package_name, &by_name_path);
3233
let call_package_arg = call_package_path

src/problem/npv_161.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ impl fmt::Display for TopLevelPackageMovedOutOfByNameWithCustomArguments {
2525
file,
2626
config,
2727
} = self;
28-
let by_name_path =
29-
structure::expected_by_name_dir_for_package(package_name, config).unwrap().path;
28+
let by_name_path = structure::expected_by_name_dir_for_package(package_name, config)
29+
.unwrap()
30+
.path;
3031
let relative_package_file =
3132
structure::relative_file_for_package(package_name, &by_name_path);
3233
let call_package_arg = call_package_path

src/problem/npv_162.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ impl fmt::Display for NewTopLevelPackageShouldBeByName {
2525
file,
2626
config,
2727
} = self;
28-
let by_name_path =
29-
structure::expected_by_name_dir_for_package(attr_path, config).unwrap().path;
30-
let relative_package_file =
31-
structure::relative_file_for_package(attr_path, &by_name_path);
28+
let by_name_path = structure::expected_by_name_dir_for_package(attr_path, config)
29+
.unwrap()
30+
.path;
31+
let relative_package_file = structure::relative_file_for_package(attr_path, &by_name_path);
3232
// println!("{}:{}: attr_path {attr_path}, by_name_path {by_name_path}, relative_package_file {relative_package_file}", file!(), line!());
3333
let call_package_arg = call_package_path
3434
.as_ref()

src/problem/npv_163.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ impl fmt::Display for NewTopLevelPackageShouldBeByNameWithCustomArgument {
2525
file,
2626
config,
2727
} = self;
28-
let by_name_path =
29-
structure::expected_by_name_dir_for_package(package_name, config).unwrap().path;
28+
let by_name_path = structure::expected_by_name_dir_for_package(package_name, config)
29+
.unwrap()
30+
.path;
3031
let relative_package_file =
3132
structure::relative_file_for_package(package_name, &by_name_path);
3233
let call_package_arg = call_package_path

src/ratchet.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ impl Nixpkgs {
3434
// comparison
3535
to.packages
3636
.iter()
37-
.map(|(name, pkg)| {
38-
Package::compare(name, from.packages.get(name), pkg)
39-
}),
37+
.map(|(name, pkg)| Package::compare(name, from.packages.get(name), pkg)),
4038
)
41-
.and_(validation::sequence_(to.files.iter().map(
42-
|(name, file)| File::compare(name, from.files.get(name), file),
43-
)))
39+
.and_(validation::sequence_(
40+
to.files
41+
.iter()
42+
.map(|(name, file)| File::compare(name, from.files.get(name), file)),
43+
))
4444
}
4545
}
4646

src/structure.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,7 @@ pub fn relative_file_for_package(
133133
relative_dir_for_package(attr_path, by_name_dir_path).join(PACKAGE_NIX_FILENAME)
134134
}
135135

136-
pub fn expected_by_name_dir_for_package(
137-
attr_path: &str,
138-
config: &Config,
139-
) -> Option<ByNameDir> {
136+
pub fn expected_by_name_dir_for_package(attr_path: &str, config: &Config) -> Option<ByNameDir> {
140137
let matching_dirs: Vec<&ByNameDir> = config
141138
.by_name_dirs
142139
.iter()
@@ -160,7 +157,6 @@ pub fn expected_by_name_dir_for_package(
160157
}
161158
}
162159

163-
164160
// /// Check the structure of Nixpkgs, returning the attribute names that are defined in
165161
// /// the given by-name directory.
166162
// pub fn check_structure(
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{ someDrv }: someDrv# // {type = "derivation";}
1+
{ someDrv }: someDrv

0 commit comments

Comments
 (0)