-
-
Notifications
You must be signed in to change notification settings - Fork 14.3k
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
Conversation
Detect inherit's better, such that a future commit can use this information in an error message
An edge case was allowed when it shouldn't be: A package defined in `pkgs/by-name` could be overridden in `all-packages.nix` if it was of the form `callPackage (<expr>) { <non-empty> }`. This is not right, it's required that the first argument be the path matching the package to be overridden.
Or rather, make it more consistent
There was a problem hiding this 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> { |
There was a problem hiding this comment.
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}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"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".
There was a problem hiding this comment.
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 :)
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 | ||
}) |
There was a problem hiding this comment.
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
- Changing the sense of
path == relative_package_file
topath != relative_package_file
and commenting theTight
bound as to why it'sTight
. - Putting the
if syntactic_call_package.empty_arg
check into theelse
case so it goes down an indentation level. - 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" |
There was a problem hiding this comment.
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.
let base_thread = thread::spawn(move || check_nixpkgs(&base_nixpkgs, keep_nix_path)); | ||
let main_result = check_nixpkgs(&main_nixpkgs, keep_nix_path)?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀
pkgs/test/nixpkgs-check-by-name/tests/new-package-non-by-name/expected
Outdated
Show resolved
Hide resolved
pkgs/test/nixpkgs-check-by-name/tests/new-package-non-by-name/expected
Outdated
Show resolved
Hide resolved
@@ -2,5 +2,4 @@ self: super: { | |||
|
|||
bar = (x: x) self.callPackage ./pkgs/by-name/fo/foo/package.nix { someFlag = true; }; | |||
foo = self.bar; | |||
|
There was a problem hiding this comment.
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?
Please define it in {} instead. | ||
See `pkgs/by-name/README.md` for more details. | ||
{extra} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, doing that!
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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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 |
There was a problem hiding this 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. |
There was a problem hiding this comment.
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
14cc4ed
to
fb0a072
Compare
Description of changes
This is a bit of a random assortment of
pkgs/by-name
improvements:pkgs/by-name
is overridden with a manual definition inall-packages.nix
, but it's not of the expected form.pkgs/by-name
is overridden with acallPackage
whose first argument is not a path. This also makes the code easier to understand.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
Add a 👍 reaction to pull requests you find important.