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

treewide: with stdenv.lib; in meta -> with lib; #108978

Merged
merged 1 commit into from Jan 11, 2021

Conversation

Profpatsch
Copy link
Member

Part of: #108938

meta = with stdenv.lib;

is a widely used pattern. We want to slowly remove
the stdenv.lib indirection and encourage people
to use lib directly. Thus let’s start with the meta
field.

This used a rewriting script to mostly automatically
replace all occurances of this pattern, and add the
lib argument to the package header if it doesn’t
exist yet.

The script in its current form is available at
https://cs.tvl.fyi/depot@2f807d7f141068d2d60676a89213eaa5353ca6e0/-/blob/users/Profpatsch/nixpkgs-rewriter/default.nix

Motivation for this change
Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.

@Profpatsch
Copy link
Member Author

Strategies used to sanity check the changes involve using a script to randomly evaluate packages, so all important packages should still evaluate.

nix eval --raw '(let pkgs = import ./. {}; in builtins.toJSON (builtins.attrNames pkgs))' \
   | jq -r '.[]' \
   | shuf \
    | head -n 1000 \
     | xargs -n1 nix-instantiate -A

Some leaf packages might have problems if they don’t follow the callPackage standard but pass arguments manually. Hopefully ofborg finds them.

@Profpatsch
Copy link
Member Author

The output of

$ git diff --numstat HEAD^ | sort -n | tail -n30
2	2	pkgs/tools/X11/xvkbd/default.nix
2	2	pkgs/tools/X11/xwallpaper/default.nix
2	2	pkgs/tools/X11/xwinwrap/default.nix
3	3	pkgs/applications/audio/clementine/default.nix
3	3	pkgs/applications/misc/ape/default.nix
3	3	pkgs/applications/misc/plover/default.nix
3	3	pkgs/applications/networking/instant-messengers/salut-a-toi/requirements.nix
3	3	pkgs/applications/science/logic/coq/default.nix
3	3	pkgs/applications/video/kodi/plugins.nix
3	3	pkgs/development/tools/parsing/antlr/4.8.nix
3	3	pkgs/games/openxray/default.nix
3	3	pkgs/games/riko4/default.nix
3	3	pkgs/misc/vim-plugins/overrides.nix
3	3	pkgs/os-specific/linux/guvcview/default.nix
3	3	pkgs/servers/kippo/default.nix
3	3	pkgs/tools/package-management/nix-prefetch-scripts/default.nix
3	3	pkgs/tools/typesetting/tex/texlive/bin.nix
4	4	pkgs/applications/audio/dfasma/default.nix
4	4	pkgs/applications/misc/dockbarx/default.nix
4	4	pkgs/applications/misc/subsurface/default.nix
4	4	pkgs/applications/virtualization/qemu/default.nix
4	4	pkgs/misc/tmux-plugins/default.nix
5	5	pkgs/tools/text/gawk/default.nix
7	7	pkgs/applications/networking/znc/modules.nix
8	8	pkgs/applications/video/vdr/plugins.nix
9	9	pkgs/misc/vscode-extensions/default.nix
10	10	pkgs/applications/editors/jetbrains/default.nix
16	16	pkgs/applications/misc/octoprint/plugins.nix
26	26	pkgs/applications/editors/eclipse/plugins.nix

shows that there are only a few files which got more than two lines of changes.

@AndersonTorres
Copy link
Member

Good to know. Following.

@SuperSandro2000
Copy link
Member

EditorCheck fails with Error: Argument list too long. I think it is save to ignore it for this PR.

@deliciouslytyped
Copy link
Contributor

deliciouslytyped commented Jan 10, 2021

Couldn't you test it by generating all the drvs and making sure they're invariant? This should apply generally to refactorings that should not change semantics. I don't know if generating all drvs is hard or something but if yes, https://discourse.nixos.org/t/using-nixos-in-an-isolated-environment/3369 is probably relevant.

@Profpatsch Profpatsch force-pushed the stdlib-lib-rewrite-meta branch 2 times, most recently from ecea912 to 8d15008 Compare January 11, 2021 07:54
@Profpatsch
Copy link
Member Author

I did a dudu while rebasing, I think it’s fixed now.

@Profpatsch
Copy link
Member Author

Thanks to @cole-h running the ofborg check locally, full evaluation should now work again.

@Profpatsch
Copy link
Member Author

Waiting for ofborg eval to be green, then rebasing & merging (otherwise there will be new merge conflicts before ofborg evals)

Part of: NixOS#108938

meta = with stdenv.lib;

is a widely used pattern. We want to slowly remove
the `stdenv.lib` indirection and encourage people
to use `lib` directly. Thus let’s start with the meta
field.

This used a rewriting script to mostly automatically
replace all occurances of this pattern, and add the
`lib` argument to the package header if it doesn’t
exist yet.

The script in its current form is available at
https://cs.tvl.fyi/depot@2f807d7f141068d2d60676a89213eaa5353ca6e0/-/blob/users/Profpatsch/nixpkgs-rewriter/default.nix
@Profpatsch
Copy link
Member Author

ofborg takes a while to reach this eval in its queue, and then chickens out immediately if there is a merge conflict … we are running the https://github.com/nixos/ofborg#running-meta-checks-locally check on a big machine and will merge once that succeeds.

@Profpatsch
Copy link
Member Author

Okay, ran the eval and made sure the check from above

    git diff nixpkgs/master...FETCH_HEAD --word-diff=porcelain --word-diff-regex="[a-zA-Z_][a-zA-Z0-9_'-]*" |
        grep -e '^[+-]' |
        grep -ve '^\(+++\|---\)' |
        sort -u

proudces

+lib
-stdenv

Copy link
Member

@alyssais alyssais left a comment

Choose a reason for hiding this comment

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

Ran the OfBorg checks locally. All good.

@Profpatsch Profpatsch merged commit 4a7f99d into NixOS:master Jan 11, 2021
@sternenseemann
Copy link
Member

I think a pass with a secondary tool over files changed by this addressing left over stdenv.lib.versionAtLeast etc. usages could be worthwhile.

@FRidh
Copy link
Member

FRidh commented Jan 11, 2021

This broke eval in pkgs/os-specific/linux/nvidia-x11/persistenced.nix blocking hydra on staging-next. Please test treewide changes with hydra-eval-jobs.

FRidh added a commit that referenced this pull request Jan 11, 2021
FRidh added a commit that referenced this pull request Jan 11, 2021
@cole-h
Copy link
Member

cole-h commented Jan 11, 2021

Please test treewide changes with hydra-eval-jobs.

A good idea -- but how (what is the incantation)?

@jonringer
Copy link
Contributor

There's probably a better way, but:

nix-shell -p hydra-unstable --run "hydra-eval-jobs -I nixpkgs=$PWD nixos/release.nix"

@cole-h
Copy link
Member

cole-h commented Jan 12, 2021

And how do we know that there's an issue, given that loads of packages fail to evaluate (e.g. unfree and broken)? Is there some pattern that's easily greppable for? Running hydra-eval-jobs -I . pkgs/top-level/release.nix gave me more than 1.6 million lines of output, after filtering out all the broken and unfree packages.

@jonringer
Copy link
Contributor

that's an excellent question :)

@FRidh
Copy link
Member

FRidh commented Jan 12, 2021

And how do we know that there's an issue, given that loads of packages fail to evaluate (e.g. unfree and broken)? Is there some pattern that's easily greppable for? Running hydra-eval-jobs -I . pkgs/top-level/release.nix gave me more than 1.6 million lines of output, after filtering out all the broken and unfree packages.

An actual eval error will kill the evaluation. Note one should test pkgs/top-level/release.nix but also those under nixos/. Probably should write a section on this in the Nixpkgs manual.

@cole-h
Copy link
Member

cole-h commented Jan 12, 2021

I see. So as long as hydra-eval-jobs exits zero, all is fine, and one should test both pkgs/top-level/release.nix and nixos/release.nix. Thanks for the help, I'll keep this in mind for the next time. Since I didn't say so earlier: thanks for catching and fixing the issue.

@sternenseemann
Copy link
Member

An actual eval error will kill the evaluation. Note one should test pkgs/top-level/release.nix but also those under nixos/. Probably should write a section on this in the Nixpkgs manual.

hydra-eval-jobs exits 0 sometimes even when ofborg still finds evaluation errors.

@OPNA2608 OPNA2608 mentioned this pull request Jan 14, 2021
10 tasks
@B4dM4n B4dM4n mentioned this pull request Jan 14, 2021
10 tasks
B4dM4n added a commit to B4dM4n/nixpkgs that referenced this pull request Jan 14, 2021
This fixes an evaluation error indroduced by NixOS#108978
@Profpatsch
Copy link
Member Author

This is a best-effort refactor as long as we don’t have well-documented ways of making sure the whole tree still evaluates. We used the ofborg check for that, running it locally.

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.

None yet

9 participants