1
0
Fork 0
mirror of https://github.com/numtide/flake-utils.git synced 2025-03-14 12:48:46 +00:00
flake-utils/filterPackages.nix
David Arnold c6169a2772
imp: filterPackages (#28)
* imp: filterPackages

* Update filterPackages.nix

* Update filterPackages.nix

Co-authored-by: Jonas Chevalier <zimbatm@zimbatm.com>
2021-04-12 10:52:05 +02:00

28 lines
875 B
Nix

system: packages:
let
# Adopted from nixpkgs.lib
inherit (builtins) listToAttrs concatMap attrName;
nameValuePair = name: value: { inherit name value; };
filterAttrs = pred: set:
listToAttrs (
concatMap (name:
let v = set.${name}; in
if pred name v then [(nameValuePair name v)] else []
)
(attrNames set)
);
# Everything that nix flake check requires for the packages output
sieve = n: v:
with v;
let
inherit (builtins) isAttrs;
isDerivation = x: isAttrs x && x ? type && x.type == "derivation";
platforms = meta.hydraPlatforms or meta.platforms or [ ];
in
# check for isDerivation, so this is independently useful of
# flattenTree, which also does filter on derviations
isDerivation v && !meta.broken && builtins.elem system platforms
;
in
filterAttrs sieve packages