NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
16.6k stars 13.08k forks source link

`lib.hiPrio` gets erased after calling `override` or `overrideAttrs` #323624

Open andrewhamon opened 2 weeks ago

andrewhamon commented 2 weeks ago

Describe the bug

lib.hiPrio and related functions update meta using simple merging.

If a package later has an override applied, though, the updated meta is discarded. This can be really surprising, particularly to those less well-versed in nix.

Steps To Reproduce

Try this in a REPL:

(pkgs.lib.hiPrio pkgs.cowsay).meta.priority
# => -10

((pkgs.lib.hiPrio pkgs.cowsay).overrideAttrs { }).meta.priority or "priority is not set"
# => "priority is not set"

# also impacts `override`
((pkgs.lib.hiPrio pkgs.cowsay).override { }).meta.priority or "priority is not set"
# => "priority is not set"

Expected behavior

Functions that "mutate" derivations should do so using overrideAttrs, so that later invocations of overrideAttrs don't discard information.

Screenshots

If applicable, add screenshots to help explain your problem.

Additional context

Add any other context about the problem here.

Notify maintainers

Metadata

Please run nix-shell -p nix-info --run "nix-info -m" and paste the result.

[user@system:~]$ nix-shell -p nix-info --run "nix-info -m"
 - system: `"aarch64-darwin"`
 - host os: `Darwin 23.5.0, macOS 14.5`
 - multi-user?: `yes`
 - sandbox: `no`
 - version: `nix-env (Nix) 2.22.0`
 - nixpkgs: `/nix/store/rhg90jpryc286xn9xjy6qjiaap6pjgdc-source`

Add a :+1: reaction to issues you find important.

andrewhamon commented 2 weeks ago

Similar issue from long ago where this is mentioned: https://github.com/NixOS/nixpkgs/issues/7425

eclairevoyant commented 2 weeks ago

Why not move the hiPrio outside the override?

andrewhamon commented 2 weeks ago

Yes, that's an easy workaround to apply, if you know what the problem is. But if you don't know already, I don't think the solution is obvious.

Do you see any downsides to adopting a merge function such as this?