mirror of
https://github.com/numtide/flake-utils.git
synced 2024-11-26 10:34:00 +03:00
imp: filterPackages (#28)
* imp: filterPackages * Update filterPackages.nix * Update filterPackages.nix Co-authored-by: Jonas Chevalier <zimbatm@zimbatm.com>
This commit is contained in:
parent
b2c27d1a81
commit
c6169a2772
21
default.nix
21
default.nix
@ -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
28
filterPackages.nix
Normal 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
|
Loading…
Reference in New Issue
Block a user