Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib/attrsets: remove copies of recurseIntoAttrs, add recurseIntoAttrsIf #367489

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 49 additions & 7 deletions lib/attrsets.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ let
in

rec {
inherit (builtins) attrNames listToAttrs hasAttr isAttrs getAttr removeAttrs intersectAttrs;
inherit (builtins) attrNames listToAttrs hasAttr isAttrs getAttr removeAttrs intersectAttrs isBool;


/**
Expand Down Expand Up @@ -2035,6 +2035,52 @@ rec {
*/
chooseDevOutputs = builtins.map getDev;

/**
Make various Nix tools consider the contents of the resulting
attribute set when looking for what to build, find, etc if a
condition is true.

This function only affects a single attribute set; it does not
apply itself recursively for nested attribute sets.

# Inputs

`condition`

:A boolean that says whether a tool should consider the attrset
values.

`attrs`

:An attribute set to scan for derivations.

# Type

````
recurseIntoAttrsIf :: Bool -> AttrSet -> AttrSet
```

# Examples
:::{.example}
## `lib.attrsets.recurseIntoAttrsIf` usage example
```nix
{ pkgs ? import <nixpkgs> {} }:
{
myTools = pkgs.lib.recurseIntoAttrsIf true {
inherit (pkgs) hello figlet;
};
}
```

:::
*/
recurseIntoAttrsIf =
condition:
attrs:
assert isBool condition;
attrs // { recurseForDerivations = condition; };


/**
Make various Nix tools consider the contents of the resulting
attribute set when looking for what to build, find, etc.
Expand Down Expand Up @@ -2070,9 +2116,7 @@ rec {

:::
*/
recurseIntoAttrs =
attrs:
attrs // { recurseForDerivations = true; };
recurseIntoAttrs = recurseIntoAttrsIf true;

/**
Undo the effect of recurseIntoAttrs.
Expand All @@ -2090,9 +2134,7 @@ rec {
dontRecurseIntoAttrs :: AttrSet -> AttrSet
```
*/
dontRecurseIntoAttrs =
attrs:
attrs // { recurseForDerivations = false; };
dontRecurseIntoAttrs = recurseIntoAttrsIf false;

/**
`unionOfDisjoint x y` is equal to `x // y // z` where the
Expand Down
2 changes: 1 addition & 1 deletion maintainers/scripts/rebuild-amount.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ nixexpr() {
{ supportedSystems = cfg.systems or [ "x86_64-linux" "x86_64-darwin" ]; };
cfg = (import $1 {}).config.rebuild-amount or {};

recurseIntoAttrs = attrs: attrs // { recurseForDerivations = true; };
inherit (lib) recurseIntoAttrs;

# hydraJobs leaves recurseForDerivations as empty attrmaps;
# that would break nix-env and we also need to recurse everywhere.
Expand Down
2 changes: 1 addition & 1 deletion pkgs/top-level/release-outpaths.nix
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ let
};
};
};
recurseIntoAttrs = attrs: attrs // { recurseForDerivations = true; };
inherit (lib) recurseIntoAttrs;

# hydraJobs leaves recurseForDerivations as empty attrmaps;
# that would break nix-env and we also need to recurse everywhere.
Expand Down
Loading