Import all nix files in a directory tree. Discussions: https://oeiuwq.zulipchat.com/join/nqp26cd4kngon6mo3ncgnuap/ dendrix.oeiuwq.com/Dendritic.html
dendritic inputs

better names

+22 -11
+22 -11
default.nix
··· 138 138 139 139 callable = 140 140 let 141 - __config = { 141 + initial = { 142 142 # Accumulated configuration 143 143 api = { }; 144 144 mapf = (i: i); 145 145 filterf = _: true; 146 146 paths = [ ]; 147 147 148 + # config is our state (initial at first). this functor allows it 149 + # to work as if it was a function, taking an update function 150 + # that will return a new state. for example: 151 + # in mergeAttrs: `config (c: c // x)` will merge x into new config. 148 152 __functor = 149 - self: f: 153 + config: update: 150 154 let 151 - __config = (f self); 152 - boundAPI = builtins.mapAttrs (_: g: g (self f)) __config.api; 153 - accAttr = attrName: acc: self (c: mapAttr (f c) attrName acc); 154 - mergeAttrs = attrs: self (c: (f c) // attrs); 155 + # updated is another config 156 + updated = update config; 157 + 158 + # current is the result of this functor. 159 + # it is not a config, but an import-tree object containing a __config. 160 + current = config update; 161 + boundAPI = builtins.mapAttrs (_: g: g current) updated.api; 162 + 163 + # these two helpers are used to **append** aggregated configs. 164 + accAttr = attrName: acc: config (c: mapAttr (update c) attrName acc); 165 + mergeAttrs = attrs: config (c: (update c) // attrs); 155 166 in 156 167 boundAPI 157 168 // { 158 - inherit __config; 159 - __functor = functor; 169 + __config = updated; 170 + __functor = functor; # user-facing callable 160 171 161 172 # Configuration updates (accumulating) 162 173 filter = filterf: accAttr "filterf" (and filterf); ··· 174 185 leafs = mergeAttrs { pipef = (i: i); }; 175 186 176 187 # Applies empty (for already path-configured trees) 177 - result = (self f) [ ]; 188 + result = current [ ]; 178 189 179 190 # Return a list of all filtered files. 180 - files = (self f).leafs.result; 191 + files = current.leafs.result; 181 192 182 193 # returns the original empty state 183 194 new = callable; 184 195 }; 185 196 }; 186 197 in 187 - __config (c: c); 198 + initial (config: config); 188 199 189 200 in 190 201 callable