diff --git a/doc/functions/library/attrsets.xml b/doc/functions/library/attrsets.xml index b1ea05a2381..3c5823c2589 100644 --- a/doc/functions/library/attrsets.xml +++ b/doc/functions/library/attrsets.xml @@ -1667,4 +1667,48 @@ recursiveUpdate ]]> + +
+ <function>lib.attrsets.recurseIntoAttrs</function> + + recurseIntoAttrs :: AttrSet -> AttrSet + + + + + + Make various Nix tools consider the contents of the resulting + attribute set when looking for what to build, find, etc. + + + + This function only affects a single attribute set; it does not apply itself recursively for nested attribute sets. + + + + + + attrs + + + + An attribute set to scan for derivations. + + + + + + + Making Nix look inside an attribute set + {} }: +{ + myTools = pkgs.lib.recurseIntoAttrs { + inherit (pkgs) hello figlet; + }; +} +]]> + +
+ diff --git a/lib/attrsets.nix b/lib/attrsets.nix index 32994432d53..72430522f7d 100644 --- a/lib/attrsets.nix +++ b/lib/attrsets.nix @@ -473,6 +473,20 @@ rec { /* Pick the outputs of packages to place in buildInputs */ chooseDevOutputs = drvs: builtins.map getDev drvs; + /* Make various Nix tools consider the contents of the resulting + attribute set when looking for what to build, find, etc. + + This function only affects a single attribute set; it does not + apply itself recursively for nested attribute sets. + */ + recurseIntoAttrs = + attrs: attrs // { recurseForDerivations = true; }; + + /* Undo the effect of recurseIntoAttrs. + */ + dontRecurseIntoAttrs = + attrs: attrs // { recurseForDerivations = false; }; + /*** deprecated stuff ***/ zipWithNames = zipAttrsWithNames; diff --git a/lib/default.nix b/lib/default.nix index d2fe018aa6a..f8cc5c4d816 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -73,7 +73,8 @@ let genAttrs isDerivation toDerivation optionalAttrs zipAttrsWithNames zipAttrsWith zipAttrs recursiveUpdateUntil recursiveUpdate matchAttrs overrideExisting getOutput getBin - getLib getDev chooseDevOutputs zipWithNames zip; + getLib getDev chooseDevOutputs zipWithNames zip + recurseIntoAttrs dontRecurseIntoAttrs; inherit (lists) singleton forEach foldr fold foldl foldl' imap0 imap1 concatMap flatten remove findSingle findFirst any all count optional optionals toList range partition zipListsWith zipLists diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index c7bfb8a7acf..839ca5a4d40 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -62,9 +62,7 @@ in inherit (lib) lowPrio hiPrio appendToName makeOverridable; - # Applying this to an attribute set will cause nix-env to look - # inside the set for derivations. - recurseIntoAttrs = attrs: attrs // { recurseForDerivations = true; }; + inherit (lib) recurseIntoAttrs; # This is intended to be the reverse of recurseIntoAttrs, as it is # defined now it exists mainly for documentation purposes, but you @@ -72,7 +70,7 @@ in # the Attrs which is useful for testing massive changes. Ideally, # every package subset not marked with recurseIntoAttrs should be # marked with this. - dontRecurseIntoAttrs = x: x; + inherit (lib) dontRecurseIntoAttrs; stringsWithDeps = lib.stringsWithDeps;