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

check-by-name: Refactor to prepare for enforcing pkgs/by-name, make --base required #278805

Merged
merged 8 commits into from
Jan 9, 2024

Conversation

infinisil
Copy link
Member

Description of changes

This is a preparation PR for #275539, including only internal improvements to the code and comments, without changing any functionality. This makes the diff for the above PR much smaller.

The only somewhat interesting change is that --base is now required for nixpkgs-check-by-name, which was already prepared for in #274591 by always passing the flag in CI.

This PR is best reviewed commit-by-commit.

Things done

  • Built and tested on x86_64-linux

Add a 👍 reaction to pull requests you find important.

Does a bunch of cleanups to the eval.{rs,nix} code to make future
changes easier, no functionality is changed.
This was previously a checking impurity that could produce different
results when run on different systems.
CI now passes the flag, so it doesn't have to be optional anymore
@infinisil infinisil added this to the RFC 140 milestone Jan 5, 2024
@infinisil infinisil changed the title check-by-name: Refactore to prepare for enforcing pkgs/by-name, make --base required check-by-name: Refactor to prepare for enforcing pkgs/by-name, make --base required Jan 5, 2024
This makes the attribute ratchet check logic more re-usable, which will
be used in a future commit.

It also renames the ratchet states to something more intuitive
Makes errors for attributes deterministic so it's easier to test (also,
reproducibility is always nice)
Strips the Nixpkgs prefix from the callPackage paths,
makes future error messages using this path be deterministic.
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm assuming this is a sentinel 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.

Yeah, just so that git can track that the directory exists. Marginally easier than changing the code to handle a missing directory

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.

OK, I took a look at the Rust code here, and skimmed the test-only Nix code.

I have three non-blocking refactoring suggestions, in descending order of "want to see":

  1. Simplify the traits in ratchet.rs and use them more broadly.
  2. Use anyhow::Context::with_context to avoid allocating error strings in the non-error case.
  3. Minor typo and comment fixes as noted.

There's a slightly larger refactoring that I see that's not directly related to the changes in this PR. In main, everywhere the error_writer is used could instead use a ratchet::Nixpkgs that's cased on its trivial success.

pkgs/test/nixpkgs-check-by-name/src/ratchet.rs Outdated Show resolved Hide resolved
pkgs/test/nixpkgs-check-by-name/src/ratchet.rs Outdated Show resolved Hide resolved
Comment on lines 65 to 66
/// What error to produce in case the ratchet went in the wrong direction
fn to_error(name: &str, context: &Self, existed_before: bool) -> NixpkgsProblem;
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks like a IntoNixpkgsProblem trait. I think it can consume Self, and have context be self.

Copy link
Member Author

Choose a reason for hiding this comment

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

It looks like making it consume Self is a bit trickier, since the values come from a HashMap originally. And not sure what you mean with context being self!

pkgs/test/nixpkgs-check-by-name/src/eval.rs Show resolved Hide resolved
Comment on lines +137 to +141
Missing => NixpkgsProblem::UndefinedAttr {
relative_package_file: relative_package_file.clone(),
package_name: attribute_name.clone(),
}
.into(),
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks like it's implementing IntoNixpkgsProblem on ByNameAttribute.

The same thing holds for the cases below on their specific types.

Copy link
Member Author

Choose a reason for hiding this comment

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

Not entirely because in some cases there won't be an error.

Copy link
Contributor

Choose a reason for hiding this comment

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

Not entirely because in some cases there won't be an error.

Agreed. I took a swing at this (PR not sent out) and ran into the same thing. There's some fine tuning that could be done for sure but I think the trait-based approach I suggested isn't right.

pkgs/test/nixpkgs-check-by-name/src/eval.nix Outdated Show resolved Hide resolved
pkgs/test/nixpkgs-check-by-name/src/eval.rs Outdated Show resolved Hide resolved
@delroth delroth added the 12.approvals: 1 This PR was reviewed and approved by one reputable person label Jan 8, 2024
Copy link
Member

@Ericson2314 Ericson2314 left a comment

Choose a reason for hiding this comment

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

LGTM!

@delroth delroth added 12.approvals: 2 This PR was reviewed and approved by two reputable people and removed 12.approvals: 1 This PR was reviewed and approved by one reputable person labels Jan 8, 2024
infinisil and others added 2 commits January 9, 2024 19:35
- Typo
- Rename AttributeRatchet to ToNixpkgsProblem
- Make the compare trait method into a RatchetState method

Co-Authored-By: Philip Taron <[email protected]>
Avoids allocation in the non-error case
@infinisil
Copy link
Member Author

Feedback addressed, I'll merge once CI passes since the feedback isn't blocking :)

@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/2024-01-09-nixpkgs-architecture-team-meeting-47/38037/1

@delroth delroth removed the 12.approvals: 2 This PR was reviewed and approved by two reputable people label Jan 9, 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.

Ship it.

Comment on lines +137 to +141
Missing => NixpkgsProblem::UndefinedAttr {
relative_package_file: relative_package_file.clone(),
package_name: attribute_name.clone(),
}
.into(),
Copy link
Contributor

Choose a reason for hiding this comment

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

Not entirely because in some cases there won't be an error.

Agreed. I took a swing at this (PR not sent out) and ran into the same thing. There's some fine tuning that could be done for sure but I think the trait-based approach I suggested isn't right.

@infinisil infinisil merged commit da3e72b into NixOS:master Jan 9, 2024
21 of 22 checks passed
@infinisil infinisil deleted the by-name-enforce-preparation branch January 9, 2024 21:59
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.

5 participants