-
Notifications
You must be signed in to change notification settings - Fork 80
/
filterPackages.nix
33 lines (32 loc) · 1018 Bytes
/
filterPackages.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
{ allSystems }:
system: packages:
let
# Adopted from nixpkgs.lib
inherit (builtins) listToAttrs concatMap attrNames;
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";
isBroken = meta.broken or false;
platforms = meta.platforms or allSystems;
badPlatforms = meta.badPlatforms or [ ];
in
# check for isDerivation, so this is independently useful of
# flattenTree, which also does filter on derivations
isDerivation v && !isBroken && (builtins.elem system platforms) &&
!(builtins.elem system badPlatforms)
;
in
filterAttrs sieve packages