Skip to content

Instantly share code, notes, and snippets.

@Atemu
Created November 2, 2020 17:35
Show Gist options
  • Save Atemu/283526e3e8c196107468209068562a7e to your computer and use it in GitHub Desktop.
Save Atemu/283526e3e8c196107468209068562a7e to your computer and use it in GitHub Desktop.
Filter out subsets of Nixpkgs' top-level pkgs attribute
{ pkgs ? import <nixpkgs> { } }:
with pkgs.lib;
with builtins;
rec {
canEval = x: with (tryEval x); success && (value != false);
sanitise = set: filterAttrs (n: v: canEval v) set;
attrsOf = filterAttrs (n: v: isAttrs v);
sizeOf = set: length (attrNames set);
notDrvsOf = filterAttrs (n: v: !isDerivation v);
drvsOf = filterAttrs (n: v: isDerivation v);
isMainSet = set: let
main = sizeOf pkgs;
size = sizeOf set;
in elem size [ main (main + 1)]; # some top-level copies have an additional `recurseIntoAttrs`
allPackages = pipe pkgs [
sanitise # are evaluable/comparable
attrsOf # are attrSets or drvs
(filterAttrs (n: v: !isMainSet v)) # aren't a copy of the main package set
];
packageSets = notDrvsOf allPackages;
all = pipe pkgs [ sanitise attrNames ];
setNames = pipe packageSets [ attrNames ];
setLengths = mapAttrs (n: v: length (attrNames v)) packageSets;
setSubNames = mapAttrs (n: v: pipe v [attrNames]) packageSets;
inherit pkgs;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment