-
-
Notifications
You must be signed in to change notification settings - Fork 18.2k
haskellPackages: add script to sweep for unused overrides #384591
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
Open
alexfmpe
wants to merge
1
commit into
NixOS:haskell-updates
Choose a base branch
from
alexfmpe:sweep
base: haskell-updates
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| set -euo pipefail | ||
|
|
||
| function help { | ||
| cat <<END_HELP | ||
| Usage: $0 | ||
|
|
||
| Call nix-build on derivations passed in standard input and report the ones with successful output paths | ||
| Can be used in combination with ./sweep-packages.nix to search for unnecessary property overrides by attempting builds with the default value | ||
|
|
||
| Examples: | ||
| $0 /nix/store/123-hello.drv /nix/store/456-cowsay.drv | ||
| nix-instantiate sweep-packages.nix -A derivationsWithout.overrideCabal.jailbreak | $0 | ||
| END_HELP | ||
| exit 1 | ||
| } | ||
|
|
||
| if [[ $# > 0 ]]; then | ||
| help | ||
| fi | ||
|
|
||
| echo "Reading derivations list" | ||
| derivations=$(</dev/stdin) | ||
| echo "Attempting build - successful derivations will be reported at the end" | ||
| echo "To skip to current results press ctrl-c" | ||
| nix-build --keep-going $derivations > /dev/null || : # ignore error code here so we can report successes | ||
|
|
||
| echo "Checking which derivations actually placed output paths in the store..." | ||
| for drv in $derivations; do | ||
| outputs=$(nix-store --query $drv) | ||
| failures=false; | ||
| for out in $outputs; do | ||
| if [[ ! -d $out ]]; then | ||
| failures=true | ||
| fi; | ||
| done; | ||
| if ! $failures; then | ||
| echo $drv | ||
| fi; | ||
| done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| # Utils for sweeping through packages based on some property discoverable at eval time | ||
| # Useful for narrowing down package candidates on which to test some build time property | ||
| # | ||
| # Example 1: finding packages with patches that no longer apply | ||
| # nix-build sweep-packages.nix -A derivationsWith.overrideAttrs.patches --keep-going | ||
| # The desired packages are reported in the error message or on a subsequent `--dry-run` | ||
| # | ||
| # Example 2: finding packages with unnecessarily disabled test suite | ||
| # nix-instantiate sweep-packages.nix -A derivationsWithout.overrideAttrs.doCheck | ./report-successes.sh | ||
| # Here we use `derivationsWithout` to reset the `doCheck` override and then look at builds that *don't* fail | ||
|
|
||
| { | ||
| nixpkgs ? import ../../.. { }, # nixpkgs to obtain utils from | ||
| pkgs ? nixpkgs.haskellPackages, # package set to sweep | ||
| }: | ||
|
|
||
| with nixpkgs; | ||
|
|
||
| rec { | ||
| inherit pkgs lib; | ||
|
|
||
| id = x: x; | ||
|
|
||
| canEval = v: (builtins.tryEval v.outPath).success; | ||
|
|
||
| isValidPackage = | ||
| n: v: | ||
| lib.all id [ | ||
| (n != "ghc") | ||
| (!(v.meta.broken or true)) | ||
| ((v.meta.hydraPlatforms or null) != [ ]) | ||
| ]; | ||
|
|
||
| original = lens: lib.filterAttrs (n: v: isValidPackage n v && lens.get v) pkgs; | ||
|
|
||
| modified = | ||
| modify: lens: | ||
| lib.pipe (original lens) [ | ||
| (builtins.mapAttrs (_: modify lens)) | ||
| (lib.filterAttrs (_: canEval)) | ||
| ]; | ||
|
|
||
| lenses = { | ||
| overrideAttrs = { | ||
| doCheck = rec { | ||
| get = v: !(v.doCheck or true); | ||
| set = x: v: v.overrideAttrs { doCheck = x; }; | ||
| reset = set true; | ||
| }; | ||
|
|
||
| patches = rec { | ||
| get = v: v.patches != [ ]; | ||
| set = x: v: v.overrideAttrs { patches = x; }; | ||
| reset = set [ ]; | ||
| }; | ||
| }; | ||
|
|
||
| overrideCabal = with haskell.lib.compose; { | ||
| doHaddock = rec { | ||
| get = v: v.isHaskellLibrary && !(lib.hasInfix "Setup haddock" v.haddockPhase); | ||
| set = x: overrideCabal { doHaddock = x; }; | ||
| reset = set true; | ||
| }; | ||
|
|
||
| jailbreak = rec { | ||
| get = v: lib.hasInfix "jailbreak-cabal" v.postPatch; | ||
| set = x: overrideCabal { jailbreak = x; }; | ||
| reset = set false; | ||
| }; | ||
|
|
||
| enableParallelBuilding = rec { | ||
| get = v: !lib.hasInfix "-j$NIX_BUILD_CORES" v.setupCompilerEnvironmentPhase; | ||
| set = x: overrideCabal { enableParallelBuilding = x; }; | ||
| reset = set true; | ||
| }; | ||
| }; | ||
| }; | ||
|
|
||
| sweep = f: builtins.mapAttrs (_: builtins.mapAttrs (_: modified f)) lenses; | ||
|
|
||
| derivationsWithout = sweep (l: l.reset); | ||
| derivationsWith = sweep (_: id); | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Arguably, here the better approach is to build
srcOnly pkgand see whether it fails which is much cheaper.