diff --git a/default.nix b/default.nix index f94262f..6ab5779 100644 --- a/default.nix +++ b/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 diff --git a/filterPackages.nix b/filterPackages.nix new file mode 100644 index 0000000..f3d7147 --- /dev/null +++ b/filterPackages.nix @@ -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