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

Reduce warning spam from nix search #355271

Merged
merged 2 commits into from
Dec 2, 2024
Merged

Conversation

sersorrel
Copy link
Contributor

@sersorrel sersorrel commented Nov 11, 2024

When you nix search nixpkgs for the first time (or use nix-env -u), you get an enormous number of warnings printed due to renamed or deprecated packages, like:

trace: evaluation warning: cinnamon.bulky was moved to top-level. Please use pkgs.bulky directly.
trace: evaluation warning: cinnamon.cinnamon-common was moved to top-level. Please use pkgs.cinnamon-common directly.
trace: evaluation warning: cinnamon.cinnamon-control-center was moved to top-level. Please use pkgs.cinnamon-control-center directly.
trace: evaluation warning: cinnamon.cinnamon-desktop was moved to top-level. Please use pkgs.cinnamon-desktop directly.
trace: evaluation warning: cinnamon.cinnamon-gsettings-overrides was moved to top-level. Please use pkgs.cinnamon-gsettings-overrides directly.
...etc...

There seems to be no appetite on the Nix side to hide these warnings when doing a search (2024-08-21 Nix team meeting minutes), so let's work around the problem in Nixpkgs instead.

The approach I take is to modify a few attributes of the wrapped derivation so that they emit a warning when evaluated: each of the outputs, as well as drvPath, is wrapped with lib.warn. This is in contrast to the current approach, where evaluating the derivation itself (to do things like "find its name and version", which are necessary for nix search) causes the warning.

Outstanding issues:

  • This approach doesn't generalise well to things that aren't derivations. For example, the whole of cudaPackages is currently wrapped in a lib.warn, and writeReferencesToFile (a function) is as well, so these warnings persist after this PR.
  • I don't understand enough Nix internals to know why wrapping drvPath works here or if it's the right thing to do. In trace: warning while doing nix-env -u #306276 (comment), @roberth suggested instead wrapping outPath, but for me this didn't seem to ever print the warnings.
  • The name wrapWithWarn should probably be changed; other candidates include mkStub, mkWarnDrv, etc.
  • lib.derivations is perhaps not the correct place for this helper to live, and it may need tests too – I'm unlikely to have the energy to figure this out on my own, but if someone else wants to put in the work or tell me what to do, feel free.
  • Does this negatively impact time taken to evaluate Nixpkgs? Is any impact outweighed by the UX improvement?

Fixes #306276, related to NixOS/nix#10882

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 24.11 Release Notes (or backporting 23.11 and 24.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

@github-actions github-actions bot added 6.topic: GNOME GNOME desktop environment and its underlying platform 6.topic: lib The Nixpkgs function library labels Nov 11, 2024
lib/derivations.nix Outdated Show resolved Hide resolved
@sersorrel sersorrel force-pushed the deprecation-stubs branch 3 times, most recently from f5f0b59 to d3de41f Compare November 11, 2024 21:09
Copy link
Contributor

@drupol drupol left a comment

Choose a reason for hiding this comment

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

Nice, this improves the UX !


:::
*/
wrapWithWarn =
Copy link
Member

Choose a reason for hiding this comment

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

I'm ok for this to be top level in lib, but then a slightly more specific name would be nice.
Starting with warn makes it more discoverable in the repl.
How about warnOnInstantiate or warnOutputs?
(well, depends on the outcome of the other comment - maybe skip this one for now)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've switched to warnOnInstantiate at least for now, I agree that starting with warn is nice.


/**
Wrap a derivation such that instantiating it produces a warning.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe also wrap override and overrideAttrs if they exist? That doesn't cover all possible overriding functions (passthru.withFoo = finalAttrs.finalPackage.overrideAttrs ...;) but that's quite rare.

Perhaps it'd be better to cover all attributes except like meta, name and type?

Regardless of what works best, it would be good to document how it works.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed it to wrap everything except those three attributes. Also added a sentence on what exactly it does, and a hint that it's related to nix search.

:::
*/
wrapWithWarn =
msg: pkg:
Copy link
Contributor

Choose a reason for hiding this comment

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

Since package is not as well defined as a derivation is. And you also call it 'The derivation to wrap.' in your docs.

Suggested change
msg: pkg:
msg: drv:

Or did you really mean package? This includes derivations that are built by mkDerivation rather than only builtins.derivation

Copy link
Member

Choose a reason for hiding this comment

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

I think it's good to talk about these things as packages at the language level, because of the package attrset definition, but until packages and derivations are untangled in more places I don't expect anyone to get it right anyway, if there even is such a thing as right (before more untangling, e.g. NixOS/nix#6507, Nixpkgs code for rfc 92 dynamic derivations, etc).
(Also let's not make a fuss about it until that stuff is more relevant in Nixpkgs. I'm already oversharing.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed to drv – may as well be consistent.

// {
drvPath = lib.warn msg pkg.drvPath;
}
// builtins.listToAttrs (
Copy link
Contributor

Choose a reason for hiding this comment

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

This reminds me of

https://github.com/NixOS/nix/blob/2e2198fd912a8725eabd96fc4530cc92401dafad/src/libexpr/primops/derivation.nix#L35

instead of adding a new default output here pkgs.outputs or [ "out" ] i would map over the existing list
pkg.all which is an empty list.

Your current line assumes there must be some default output added called "out"

Copy link
Member

Choose a reason for hiding this comment

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

pkg.outputs is the correct source of truth here.

all only has the values, and you can't get the output attribute name from those, or at least not without questionable code with many assumptions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this is not relevant if we just wrap (almost) all attributes, rather than specifically targetting outputs.

@Ma27
Copy link
Member

Ma27 commented Nov 12, 2024

May I ask why we're showing aliases in search tooling in the first place? Given that these are removed frequently it seems better to not show them in the first place (unless explicitly enabled perhaps).

Like, please don't consider this comment blocking, this seems like a reasonable (and probably quicker) fix. But to me it seems we have an underlying issue here.

@roberth
Copy link
Member

roberth commented Nov 12, 2024

@Ma27 great question. This is a problem at the interface between Nix and Nixpkgs. As far as I know, we currently don't have a good way to make explicit that an attribute or package is an alias. Some ideas:

A meta.isAlias attribute

  • would require deep-ish evaluation by the CLI, and probably a new function that sets it
  • doesn't work for whole package sets

A special attribute in the package set, e.g. recurseIntoAttrs { __aliases = ["foo"]; foo = pkgs.foo_2; }

  • efficient (unless you would derive it from package values, in which case it'd be ~equal)
  • more robust, as an alias that fails to eval would not even be traversed by the CLI
  • perhaps less "intuitive", not being part of the package, but often that's actually accurate because it's the attribute that's to be avoided, not the package

@hsjobeki
Copy link
Contributor

@sersorrel can you rebase this?
@roberth anything open to pevent merging?

Keeping this open for too long will require continous rebases. And this is a nice improvement already.

@github-actions github-actions bot removed the 6.topic: GNOME GNOME desktop environment and its underlying platform label Dec 2, 2024
@sersorrel
Copy link
Contributor Author

rebased. now we see only the trace: evaluation warning: CUDA versions older than 12.0 will be removed in Nixpkgs 25.05; see the 24.11 release notes for more information warning repeated nine times, which is 86 fewer warnings than current master.

Copy link
Member

@roberth roberth left a comment

Choose a reason for hiding this comment

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

Found a small simplification, but let's get this in first, so we don't get more conflicts.

lib/derivations.nix Outdated Show resolved Hide resolved
Copy link
Member

@infinisil infinisil left a comment

Choose a reason for hiding this comment

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

No need to wait for ofborg evaluation anymore, since we have the new GitHub Action-based evaluation now :)

This LGTM! I say let's merge this while it's hot and do the simplification in a new PR

lib/derivations.nix Outdated Show resolved Hide resolved
@infinisil infinisil merged commit 56340f0 into NixOS:master Dec 2, 2024
16 of 17 checks passed
@sersorrel sersorrel deleted the deprecation-stubs branch December 2, 2024 20:56
@philiptaron
Copy link
Contributor

Wow, this is great!

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.

trace: warning while doing nix-env -u
8 participants