introduce flattenTree

This commit is contained in:
zimbatm 2020-07-22 10:38:25 +02:00
parent f99f597082
commit b0d0c72b08
No known key found for this signature in database
GPG Key ID: 71BAF6D40C1D63D7
2 changed files with 46 additions and 0 deletions

View File

@ -40,6 +40,30 @@ eachSystem ["x86_64-linux"] (system: { hello = 42; })
A small utility that builds the structure expected by the special `apps` and `defaultApp` prefixes. A small utility that builds the structure expected by the special `apps` and `defaultApp` prefixes.
### `flattenTree -> attrs -> attrs`
Nix flakes insists on having a flat attribute set of derivations in
various places like the `packages` and `checks` attributes.
This function traverses a tree of attributes (by respecting
recurseIntoAttrs) and only returns their derivations, with a flattened
key-space.
Eg:
```nix
flattenTree { hello = pkgs.hello; gitAndTools = pkgs.gitAndTools }
```
Returns:
```nix
{
hello = «derivation»;
gitAndTools_git = «derivation»;
gitAndTools_hub = «derivation»;
# ...
}
```
## Example ## Example
Here is how it looks like in practice: Here is how it looks like in practice:

View File

@ -47,6 +47,27 @@ let
type = "app"; type = "app";
program = "${drv}${exePath}"; program = "${drv}${exePath}";
}; };
# Nix flakes insists on having a flat attribute set of derivations in
# various places like the `packages` and `checks` attributes.
#
# This function traverses a tree of attributes (by respecting
# recurseIntoAttrs) and only returns their derivations, with a flattened
# key-space.
#
# Eg:
#
# flattenTree { hello = pkgs.hello; gitAndTools = pkgs.gitAndTools };
#
# Returns:
#
# {
# hello = «derivation»;
# gitAndTools_git = «derivation»;
# gitAndTools_hub = «derivation»;
# # ...
# }
flattenTree = tree: import ./flattenTree.nix tree;
in in
{ {
inherit inherit
@ -55,4 +76,5 @@ in
eachSystem eachSystem
mkApp mkApp
; ;
} }