nix-helpers: df601a438e733445cc989025c2e8a92a0122d973

     1: # Turns nested attribute sets into a single level, with dot-separated names.
     2: {
     3:   die,
     4:   hello,
     5:   lib,
     6: }:
     7: 
     8: with builtins;
     9: with lib;
    10: with rec {
    11:   # Recurses through attrsets looking for derivations or non-attrsets. 'path'
    12:   # keeps track of where we are in the overall structure.
    13:   go =
    14:     path: val:
    15:     if
    16:       !(isAttrs val) || isDerivation val
    17:     # A leaf: use 'path' to make the attribute name and keep value as-is
    18:     then
    19:       { "${concatStringsSep "." path}" = val; }
    20:     # An attrset: process every entry, appending their 'path' as needed, and
    21:     # merge all results.
    22:     else
    23:       fold mergeAttrs { } (
    24:         map (name: go (path ++ [ name ]) (getAttr name val)) (attrNames val)
    25:       );
    26: };
    27: 
    28: # Only call 'go' if we've got an attrset (and hence 'path' makes sense)
    29: val: if !(isAttrs val) || isDerivation val then val else go [ ] val

Generated by git2html.