Modular, context-aware and aspect-oriented dendritic Nix configurations. Discussions: https://oeiuwq.zulipchat.com/join/nqp26cd4kngon6mo3ncgnuap/ den.oeiuwq.com
configurations den dendritic nix aspect oriented
8
fork

Configure Feed

Select the types of activity you want to include in your feed.

cleanup(repo): Remove unused code (#357)

authored by

Victor Borja and committed by
GitHub
afc9ac0b 2afa0546

+75 -63
+75 -63
nix/lib/ctx-apply.nix
··· 3 3 let 4 4 inherit (den.lib) parametric; 5 5 6 - ctxKeys = [ 7 - "name" 8 - "description" 9 - "into" 10 - "provides" 11 - "__functor" 12 - "__functionArgs" 13 - "_module" 14 - "_" 15 - ]; 6 + noop = _: { }; 16 7 17 - cleanCtx = self: builtins.removeAttrs self ctxKeys; 18 - 19 - # Flatten nested into result to [ { path = [str]; into = [ctx_value]; } ]. 20 8 flattenInto = 21 9 attrset: prefix: 22 10 lib.concatLists ( ··· 37 25 ) attrset 38 26 ); 39 27 40 - transformAll = 41 - source: ctxPrev: self: ctxValue: key: 42 - [ 43 - { 44 - inherit source ctxPrev key; 45 - ctx = ctxValue; 46 - ctxDef = self; 47 - } 48 - ] 49 - ++ lib.concatMap ( 50 - { path, into }: 51 - let 52 - target = lib.attrByPath path null ctxNs; 53 - tkey = lib.concatStringsSep "." path; 54 - recurse = t: k: lib.concatMap (v: transformAll self ctxValue t v k) into; 55 - in 56 - if target != null then 57 - recurse target tkey 58 - else if builtins.length path == 1 && self.provides ? ${lib.head path} then 28 + resolveAspect = path: lib.attrByPath path null ctxNs; 29 + 30 + getCrossProvider = p: (p.prev.provides.${p.key} or (_: noop)) p.prevCtx; 31 + 32 + traverse = 33 + args@{ 34 + prev, 35 + prevCtx, 36 + self, 37 + ctx, 38 + key, 39 + }: 40 + let 41 + intoList = flattenInto ((self.into or noop) ctx) [ ]; 42 + expandOne = 43 + { path, into }: 59 44 let 60 - name = lib.head path; 45 + aspect = resolveAspect path; 46 + aspectKey = lib.concatStringsSep "." path; 47 + pathHead = lib.head path; 48 + hasProvider = self.provides ? ${pathHead}; 61 49 in 62 - recurse { 63 - inherit name; 64 - into = noop; 65 - } name 66 - else 67 - [ ] 68 - ) (flattenInto ((self.into or noop) ctxValue) [ ]); 69 - 70 - noop = _: { }; 71 - 72 - crossProvider = p: p.source.provides.${p.key} or (_: noop); 50 + if aspect != null then 51 + lib.concatMap ( 52 + c: 53 + traverse { 54 + prev = self; 55 + prevCtx = ctx; 56 + self = aspect; 57 + ctx = c; 58 + key = aspectKey; 59 + } 60 + ) into 61 + else if builtins.length path == 1 && hasProvider then 62 + lib.concatMap ( 63 + c: 64 + traverse { 65 + prev = self; 66 + prevCtx = ctx; 67 + self = { 68 + name = pathHead; 69 + into = noop; 70 + }; 71 + ctx = c; 72 + key = pathHead; 73 + } 74 + ) into 75 + else 76 + [ ]; 77 + in 78 + [ args ] ++ lib.concatMap expandOne intoList; 73 79 74 80 buildIncludes = 81 + item: 82 + let 83 + isFirst = !(item.seen ? ${item.key}); 84 + selfProvider = item.self.provides.${item.self.name} or noop; 85 + crossProvider = getCrossProvider item; 86 + in 87 + [ 88 + (if isFirst then parametric.fixedTo item.ctx item.self else parametric.atLeast item.self item.ctx) 89 + (selfProvider item.ctx) 90 + (crossProvider item.ctx) 91 + ]; 92 + 93 + assembleIncludes = 75 94 items: 76 95 let 77 - step = 78 - acc: p: 79 - let 80 - clean = cleanCtx p.ctxDef; 81 - isFirst = !(acc.seen ? ${p.key}); 82 - selfFun = p.ctxDef.provides.${p.ctxDef.name} or noop; 83 - crossFun = crossProvider p p.ctxPrev; 84 - in 85 - { 86 - seen = acc.seen // { 87 - ${p.key} = true; 88 - }; 89 - result = acc.result ++ [ 90 - (if isFirst then parametric.fixedTo p.ctx clean else parametric.atLeast clean p.ctx) 91 - (selfFun p.ctx) 92 - (crossFun p.ctx) 93 - ]; 96 + step = acc: item: { 97 + seen = acc.seen // { 98 + ${item.key} = true; 94 99 }; 100 + result = acc.result ++ (buildIncludes (item // { inherit (acc) seen; })); 101 + }; 95 102 in 96 103 (lib.foldl' step { 97 104 seen = { }; 98 105 result = [ ]; 99 106 } items).result; 100 107 101 - ctxApply = self: ctxValue: { 102 - includes = buildIncludes (transformAll null null self ctxValue self.name); 108 + ctxApply = self: ctx: { 109 + includes = assembleIncludes (traverse { 110 + prev = null; 111 + prevCtx = null; 112 + key = self.name; 113 + inherit self ctx; 114 + }); 103 115 }; 104 116 105 117 in