introduce flattenTree
This commit is contained in:
parent
f99f597082
commit
b0d0c72b08
24
README.md
24
README.md
|
@ -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.
|
||||
|
||||
### `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
|
||||
|
||||
Here is how it looks like in practice:
|
||||
|
|
22
default.nix
22
default.nix
|
@ -47,6 +47,27 @@ let
|
|||
type = "app";
|
||||
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
|
||||
{
|
||||
inherit
|
||||
|
@ -55,4 +76,5 @@ in
|
|||
eachSystem
|
||||
mkApp
|
||||
;
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue