imp: filterPackages (#28)

* imp: filterPackages

* Update filterPackages.nix

* Update filterPackages.nix

Co-authored-by: Jonas Chevalier <zimbatm@zimbatm.com>
This commit is contained in:
David Arnold 2021-04-12 03:52:05 -05:00 committed by GitHub
parent b2c27d1a81
commit c6169a2772
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 49 additions and 0 deletions

View File

@ -100,6 +100,27 @@ let
# }
flattenTree = tree: import ./flattenTree.nix tree;
# Nix check functionality validates packages for various conditions, like if
# they build for any given platform or if they are marked broken.
#
# This function filters a flattend package set for conditinos that
# would *trivially* break `nix flake check`. It does not flatten a tree and it
# does not implement advanced package validation checks.
#
# Eg:
#
# filterPackages "x86_64-linux" {
# hello = pkgs.hello;
# "gitAndTools/git" = pkgs.gitAndTools // {meta.broken = true;};
# };
#
# Returns:
#
# {
# hello = «derivation»;
# }
filterPackages = system: packages: import ./filterPackages.nix system packages;
# Returns the structure used by `nix app`
mkApp =
{ drv

28
filterPackages.nix Normal file
View File

@ -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