Better pkgs/by-name errors, minor fixes and improvements#290743
Better pkgs/by-name errors, minor fixes and improvements#290743infinisil merged 18 commits intoNixOS:masterfrom
pkgs/by-name errors, minor fixes and improvements#290743Conversation
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.
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.
|
|
||
| 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.
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.
| "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.
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.
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_filetopath != relative_package_fileand commenting theTightbound as to why it'sTight. - Putting the
if syntactic_call_package.empty_argcheck into theelsecase 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.
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)?; |
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
|
|
||
| bar = (x: x) self.callPackage ./pkgs/by-name/fo/foo/package.nix { someFlag = true; }; | ||
| foo = self.bar; | ||
|
|
There was a problem hiding this comment.
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.
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.
| 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.
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.
Co-Authored-By: Philip Taron <philip.taron@gmail.com>
|
@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 |
philiptaron
left a comment
There was a problem hiding this comment.
Tests and messages look good.
There was a problem hiding this comment.
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-nameimprovements:pkgs/by-nameis overridden with a manual definition inall-packages.nix, but it's not of the expected form.pkgs/by-nameis overridden with acallPackagewhose 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.