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

Evaluate hm-aspects shared between OS & Standalone wihout conflicts (#90)

Fixes #89

authored by oeiuwq.com and committed by

GitHub 5b49190b 89f9be7d

+35 -46
+19 -10
modules/_types.nix
··· 85 85 .${config.class}; 86 86 }; 87 87 mainModule = lib.mkOption { 88 - description = '' 89 - Defaults to: den.modules.<class>.<aspect> 90 - Can be set in order to access a module in a different place. 91 - ''; 88 + internal = true; 89 + visible = false; 90 + readOnly = true; 92 91 type = lib.types.deferredModule; 93 - default = den.modules.${config.class}.${config.aspect}; 92 + default = mainModule config "OS" "host"; 94 93 }; 95 94 }; 96 95 } ··· 179 178 .${config.class}; 180 179 }; 181 180 mainModule = lib.mkOption { 182 - description = '' 183 - Defaults to: den.modules.<class>.<aspect> 184 - Can be set in order to access a module in a different place. 185 - ''; 181 + internal = true; 182 + visible = false; 183 + readOnly = true; 186 184 type = lib.types.deferredModule; 187 - default = den.modules.${config.class}.${config.aspect}; 185 + default = mainModule config "HM" "home"; 188 186 }; 189 187 }; 190 188 } 191 189 ); 192 190 191 + mainModule = 192 + from: intent: name: 193 + let 194 + asp = den.aspects.${from.aspect}; 195 + ctx = { 196 + ${intent} = asp; 197 + ${name} = from; 198 + }; 199 + mod = (asp ctx).resolve { inherit (from) class; }; 200 + in 201 + mod; 193 202 in 194 203 { 195 204 inherit hostsOption homesOption;
+13 -33
modules/aspects/definition.nix
··· 7 7 let 8 8 inherit (den.lib) parametric; 9 9 10 - # creates den.aspects.${home.aspect} 11 - homeAspect = home: { 12 - ${home.aspect} = { 13 - ${home.class} = { }; 14 - includes = [ den.default ]; 15 - __functor = HM: parametric { inherit HM home; } HM; 16 - }; 17 - }; 18 - 19 - # creates den.aspects.${host.aspect} 20 - hostAspect = host: { 21 - ${host.aspect} = { 22 - ${host.class} = { }; 23 - includes = [ den.default ]; 24 - __functor = OS: parametric { inherit OS host; } OS; 25 - }; 26 - }; 27 - 28 - # creates aspects.${user.aspect} 29 - userAspect = user: { 30 - ${user.aspect} = { 31 - ${user.class} = { }; 10 + makeAspect = from: { 11 + ${from.aspect} = { 12 + ${from.class} = { }; 32 13 includes = [ den.default ]; 33 - __functor = parametric.expands { inherit user; }; 14 + __functor = parametric.atLeast; 34 15 }; 35 16 }; 36 17 37 - hosts = lib.flatten (map builtins.attrValues (builtins.attrValues den.hosts)); 38 - homes = lib.flatten (map builtins.attrValues (builtins.attrValues den.homes)); 18 + hosts = map builtins.attrValues (builtins.attrValues den.hosts); 19 + homes = map builtins.attrValues (builtins.attrValues den.homes); 20 + aspectClass = from: { inherit (from) aspect class; }; 39 21 40 - homeDeps = map homeAspect homes; 41 - hostDeps = map hostAspect hosts; 42 - userDeps = lib.pipe hosts [ 22 + deps = lib.pipe hosts [ 23 + (lib.flatten) 43 24 (map (h: builtins.attrValues h.users)) 25 + (users: users ++ hosts ++ homes) 44 26 (lib.flatten) 27 + (map aspectClass) 45 28 (lib.unique) 46 - (map userAspect) 29 + (map makeAspect) 47 30 ]; 48 - 49 - deps = hostDeps ++ userDeps ++ homeDeps; 50 - 51 31 in 52 32 { 53 - den.aspects = lib.mkMerge (lib.flatten deps); 33 + den.aspects = lib.mkMerge deps; 54 34 }
+1 -1
modules/aspects/dependencies.nix
··· 47 47 includes = [ 48 48 (owned USR) 49 49 (statics USR) 50 - (USR { inherit OS host; }) 50 + (USR { inherit OS host user; }) 51 51 ]; 52 52 }; 53 53
+1 -1
modules/aspects/provides/home-manager.nix
··· 41 41 }; 42 42 HM = den.aspects.${user.aspect}; 43 43 aspect = HM { 44 - inherit host; 44 + inherit host user; 45 45 OS-HM = { inherit OS HM; }; 46 46 }; 47 47 module = aspect.resolve ctx;
+1 -1
templates/default/modules/den.nix
··· 1 1 { 2 2 den.hosts.x86_64-linux.igloo.users.alice = { }; 3 3 den.hosts.aarch64-darwin.apple.users.alice = { }; 4 - # den.homes.x86_64-linux.alice = { }; 4 + den.homes.x86_64-linux.alice = { }; 5 5 }