-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* imp: filterPackages * Update filterPackages.nix * Update filterPackages.nix Co-authored-by: Jonas Chevalier <[email protected]>
- Loading branch information
Showing
2 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
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 |