From 8935bfb4ac3680e38a8811c12282e2026f7e82ae Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Wed, 11 Sep 2019 12:57:38 +0200 Subject: lib: Add recurseIntoAttrs This makes the function available without having to evaluate the Nixpkgs fix-point, making it available in a more natural way for code that deals with multiple Nixpkgs invocations. Its definition is coupled to Nix rather than Nixpkgs, so it will feel right at home in lib. --- lib/attrsets.nix | 6 ++++++ lib/default.nix | 3 ++- pkgs/top-level/all-packages.nix | 6 +++--- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/attrsets.nix b/lib/attrsets.nix index d374d229f597..4b73735fd850 100644 --- a/lib/attrsets.nix +++ b/lib/attrsets.nix @@ -473,6 +473,12 @@ 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. + */ + recurseIntoAttrs = + attrs: attrs // { recurseForDerivations = true; }; + /*** deprecated stuff ***/ zipWithNames = zipAttrsWithNames; diff --git a/lib/default.nix b/lib/default.nix index 18d2dfae1e18..34c72a3512ee 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -70,7 +70,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; 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 cd36574e1240..c50e8eaca23b 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -62,9 +62,9 @@ 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; }; + # Make various Nix tools consider the contents of the resulting + # attribute set when looking for what to build, find, etc. + 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 -- cgit v1.2.3 From fc64cf65abfd6f42910a639f7ffb996788a95797 Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Wed, 11 Sep 2019 13:03:48 +0200 Subject: top-level: Fix dontRecurseIntoAttrs and include in lib dontRecurseIntoAttrs was a noop (x: x), causing the expression dontRecurseIntoAttrs (recurseIntoAttrs a) to have the wrong effect. --- lib/attrsets.nix | 5 +++++ lib/default.nix | 2 +- pkgs/top-level/all-packages.nix | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/attrsets.nix b/lib/attrsets.nix index 4b73735fd850..607a22393f8a 100644 --- a/lib/attrsets.nix +++ b/lib/attrsets.nix @@ -479,6 +479,11 @@ rec { 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 34c72a3512ee..88083214a31a 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -71,7 +71,7 @@ let zipAttrsWithNames zipAttrsWith zipAttrs recursiveUpdateUntil recursiveUpdate matchAttrs overrideExisting getOutput getBin getLib getDev chooseDevOutputs zipWithNames zip - recurseIntoAttrs; + 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 c50e8eaca23b..5fa010558ca5 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -72,7 +72,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; -- cgit v1.2.3 From a96f37db10fb2892d0420a7ef51c5b157d9e58dd Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Wed, 11 Sep 2019 14:51:28 +0200 Subject: Document attrsets.recurseIntoAttrs --- doc/functions/library/attrsets.xml | 44 ++++++++++++++++++++++++++++++++++++++ lib/attrsets.nix | 3 +++ pkgs/top-level/all-packages.nix | 2 -- 3 files changed, 47 insertions(+), 2 deletions(-) diff --git a/doc/functions/library/attrsets.xml b/doc/functions/library/attrsets.xml index 65d0b40e2e82..8fe2e324b3b2 100644 --- a/doc/functions/library/attrsets.xml +++ b/doc/functions/library/attrsets.xml @@ -1728,4 +1728,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 607a22393f8a..ae6e4e7c8518 100644 --- a/lib/attrsets.nix +++ b/lib/attrsets.nix @@ -475,6 +475,9 @@ rec { /* 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; }; diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 5fa010558ca5..5a1b52938d1c 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -62,8 +62,6 @@ in inherit (lib) lowPrio hiPrio appendToName makeOverridable; - # Make various Nix tools consider the contents of the resulting - # attribute set when looking for what to build, find, etc. inherit (lib) recurseIntoAttrs; # This is intended to be the reverse of recurseIntoAttrs, as it is -- cgit v1.2.3