Dendritic Nix - Community-driven Nix distribution based on the Dendritic pattern.
1# Transposes an attribute set like:
2# {
3# nixos = {
4# foo = 1;
5# bar = 2;
6# };
7# darwin = {
8# bar = 3;
9# baz = 4;
10# };
11# }
12#
13# Into
14# {
15# foo = {
16# nixos = ...;
17# };
18# bar = {
19# nixos = ...;
20# darwin = ...;
21# };
22# baz = {
23# darwin = ...;
24# };
25# }
26#
27lib:
28let
29 transposeChild = child: parent: value: { inherit child parent value; };
30 eachChildAttrs = parent: lib.mapAttrsToList (transposeChild parent);
31 accTransposed =
32 acc:
33 {
34 parent,
35 child,
36 value,
37 }:
38 acc
39 // {
40 ${parent} = (acc.${parent} or { }) // {
41 ${child} = value;
42 };
43 };
44
45 transpose =
46 attrs:
47 lib.pipe attrs [
48 (lib.mapAttrsToList eachChildAttrs)
49 (lib.flatten)
50 (lib.foldl accTransposed { })
51 ];
52in
53transpose