From b0d0c72b0808e013620cd36927215dd49289bc41 Mon Sep 17 00:00:00 2001 From: zimbatm Date: Wed, 22 Jul 2020 10:38:25 +0200 Subject: [PATCH] introduce flattenTree --- README.md | 24 ++++++++++++++++++++++++ default.nix | 22 ++++++++++++++++++++++ 2 files changed, 46 insertions(+) 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 ; + }