Created
July 19, 2018 22:11
-
-
Save infinisil/3bdb01689b5f84b71f8538f467159692 to your computer and use it in GitHub Desktop.
This file contains 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
{ nixpkgs ? <nixpkgs> | |
, includeBroken ? true | |
}: | |
# Results in all haskell packages that are instantiatable and are executables | |
# Buildable via `nix-build haskell-exes.nix` | |
let | |
pkgs = import nixpkgs { | |
config = { | |
allowBroken = includeBroken; | |
allowUnfree = true; | |
allowInsecurePredicate = p: true; | |
}; | |
}; | |
inherit (pkgs) lib; | |
# Checks for a predicate on a pkg to be true n levels deep into propagatedBuildInputs | |
# And non-recursing on buildInputs | |
allProp = n: pred: pkg: if lib.isDerivation pkg && n != 0 then | |
pred pkg | |
&& lib.all (allProp (n - 1) pred) pkg.propagatedBuildInputs | |
&& lib.all pred pkg.buildInputs | |
else true; | |
# Checks for a predicate on a pkg to be true n levels deep into propagatedBuildInputs | |
allProp' = n: pred: pkg: if lib.isDerivation pkg && n != 0 then | |
pred pkg | |
&& lib.all (allProp' (n - 1) pred) pkg.propagatedBuildInputs | |
else true; | |
# How deep to recurse to figure out broken packages (or dependencies) | |
# Increase this when you get "Marked as broken" error | |
brokenDepth = 3; | |
# How deep to recurse to figure out unsupported platform packages (or dependencies) | |
# Increase this when you get "Unsupported platform" error | |
platformDepth = 3; | |
sanity = name: pkg: (builtins.tryEval pkg).success && lib.isDerivation pkg && pkg ? env; | |
notbroken = allProp brokenDepth (pkg: ! pkg.meta.broken or false); | |
correctPlatform = allProp' platformDepth (pkg: let | |
anyMatch = lib.any (lib.meta.platformMatch pkgs.hostPlatform); | |
in anyMatch (pkg.meta.platforms or lib.platforms.all) && | |
! anyMatch (pkg.meta.badPlatforms or [])); | |
executable = pkg: (pkgs.haskell.lib.overrideCabal pkg (drv: { | |
passthru.isExecutable = drv.isExecutable or false; | |
})).isExecutable; | |
result = lib.filterAttrs (name: pkg: | |
sanity name pkg && | |
(if includeBroken then true else notbroken pkg) && | |
correctPlatform pkg && | |
executable pkg | |
) pkgs.haskellPackages; | |
in result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment