Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better pkgs/by-name errors, minor fixes and improvements #290743

Merged
merged 18 commits into from
Mar 2, 2024

Conversation

infinisil
Copy link
Member

@infinisil infinisil commented Feb 23, 2024

Description of changes

This is a bit of a random assortment of pkgs/by-name improvements:

  • Better errors in many cases. In particular errors when a package in pkgs/by-name is overridden with a manual definition in all-packages.nix, but it's not of the expected form.
  • A more spaced-out error formatting for some errors (could do all in the future)
  • A minor false negative fix, for when a package in pkgs/by-name is overridden with a callPackage whose first argument is not a path. This also makes the code easier to understand.
  • A low-hanging performance improvement by running the check on two cores, which should shave around 25 seconds from CI.
  • Indications about whether the PR would break master, fixes master, or doesn't affect it when merged. This should make sure that we don't run into cases like Investigate failing PR check (check-by-name) #289649 again. This essentially re-implements workflows/check-by-name: Better error when base branch also fails #257735, but now in Rust

I fully admit that the code isn't the best, but I've been getting side-tracked trying to improve it for like 2 days 🙃

This relates to NixOS/nixpkgs-vet#6, more is needed to address that, probably just more docs, but that can be done separately

This work is sponsored by Antithesis

Things done

  • Updated/added tests

Add a 👍 reaction to pull requests you find important.

@infinisil infinisil added this to the RFC 140 milestone Feb 23, 2024
Copy link
Contributor

@philiptaron philiptaron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests not being reproducible outside your enlistment (/home/tweagysil/src) looks like a blocker. There's also just a lot of English verbiage suggestions that in total add up to "request changes." I'm not tied to any particular suggestion, so if you see a better way of saying it, please do so immediately.

@@ -51,6 +51,23 @@ struct Location {
pub column: usize,
}

impl Location {
// Returns the [file] field, but relative to Nixpkgs
fn relative_file(&self, nixpkgs_path: &Path) -> anyhow::Result<PathBuf> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Future: This makes me think that Nixpkgs object ought to be passed in here, then use its .path

let relative_file =
location.relative_file(nixpkgs_path).with_context(|| {
format!(
"Failed to resolve location file of attribute {attribute_name}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"Failed to resolve location file of attribute {attribute_name}"
"Failed to resolve the file where attribute {attribute_name} is declared"

Not in love with "declared" (possibly: "defined"?) but this sentence doesn't read nicely to me with "location file".

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like "defined", will change :)

Comment on lines 337 to 351
if let Some(path) = syntactic_call_package.relative_path {
if path == relative_package_file {
// Manual definitions with empty arguments are not allowed
// anymore
Success(if syntactic_call_package.empty_arg {
Loose(NixpkgsProblem::EmptyArgument {
package_name: attribute_name.to_owned(),
file: relative_file,
line: location.line,
column: location.column,
definition,
})
} else {
Tight
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This case isn't clear to me (and the indentation is starting to get out of control 😬 )

Might be helped by

  1. Changing the sense of path == relative_package_file to path != relative_package_file and commenting the Tight bound as to why it's Tight.
  2. Putting the if syntactic_call_package.empty_arg check into the else case so it goes down an indentation level.
  3. Finally putting the remaining case into its own block and commenting as to why it's Tight.


[dev-dependencies]
temp-env = "0.3.5"
indoc = "2.0.4"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note for myself: this is no longer a dev dependency because it's being used to write some error messages in NixpkgsProblem.

Comment on lines +82 to +83
let base_thread = thread::spawn(move || check_nixpkgs(&base_nixpkgs, keep_nix_path));
let main_result = check_nixpkgs(&main_nixpkgs, keep_nix_path)?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@@ -2,5 +2,4 @@ self: super: {

bar = (x: x) self.callPackage ./pkgs/by-name/fo/foo/package.nix { someFlag = true; };
foo = self.bar;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't a meaningful or load-bearing change, right?

Comment on lines 393 to 395
Please define it in {} instead.
See `pkgs/by-name/README.md` for more details.
{extra}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reading the tests, it looks like the *empty_arg case should be split out into its own NixpkgsProblem case. This formatting would get better if it was just two writedoc! calls rather than jammed together as they are today.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, doing that!

Comment on lines 5 to 27
Notably the second argument must not be empty, which is not the case.
It is defined in all-packages.nix:2 as

a = self.callPackage ./pkgs/by-name/a/a/package.nix { };

- Attribute `pkgs.b` is a new top-level package using `pkgs.callPackage ... { /* ... */ }`.
Please define it in pkgs/by-name/b/b/package.nix instead.
See `pkgs/by-name/README.md` for more details.
Since the second `callPackage` argument is `{ }`, no manual `callPackage` in /home/tweagysil/src/nixpkgs/by-name-improv/pkgs/test/nixpkgs-check-by-name/tests/sorted-order/all-packages.nix is needed anymore.

- Because pkgs/by-name/c/c exists, the attribute `pkgs.c` must be defined like

c = callPackage ./pkgs/by-name/c/c/package.nix { /* ... */ };

Notably the second argument must not be empty, which is not the case.
It is defined in all-packages.nix:4 as

c = self.callPackage ./pkgs/by-name/c/c/package.nix { };

- Attribute `pkgs.d` is a new top-level package using `pkgs.callPackage ... { /* ... */ }`.
Please define it in pkgs/by-name/d/d/package.nix instead.
See `pkgs/by-name/README.md` for more details.
Since the second `callPackage` argument is `{ }`, no manual `callPackage` in /home/tweagysil/src/nixpkgs/by-name-improv/pkgs/test/nixpkgs-check-by-name/tests/sorted-order/all-packages.nix is needed anymore.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are the tests that made me think that the wording in NewPackageNotUsingByName should be improved; they're both wordy and not as helpful as the others you added in this PR; plus, the vertical spacing is not as generous, and I think that also hurts them.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@infinisil
Copy link
Member Author

@philiptaron Thanks for the extensive review! I either addressed or implemented all of them now. I was also able to do a nice refactoring using RelativePath[Buf]

Copy link
Contributor

@philiptaron philiptaron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests and messages look good.

@@ -339,7 +371,7 @@ pub enum ResolvedPath {
Outside,
/// The path is within the given absolute path.
/// The `PathBuf` is the relative path under the given absolute path.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment now out of date

Makes the code easier to understand and less error-prone
Now that the previous commit removed all the .display()'s that were
previously necessary for PathBuf's, but now aren't for RelativePathBuf,
we can also inline the format! arguments
@infinisil infinisil merged commit 4b8265a into NixOS:master Mar 2, 2024
23 of 24 checks passed
@infinisil infinisil deleted the by-name-better-errors branch March 2, 2024 01:28
infinisil added a commit that referenced this pull request Mar 11, 2024
infinisil added a commit to NixOS/nixpkgs-vet that referenced this pull request Mar 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants