diff --git a/README.md b/README.md index 77f9227..907a73a 100644 --- a/README.md +++ b/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: diff --git a/default.nix b/default.nix index fcc17f5..26eced0 100644 --- a/default.nix +++ b/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 ; + }