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

make batteries use parametric.exactly (#220)

authored by oeiuwq.com and committed by

GitHub 904f9749 d40fa311

+26 -34
+1 -3
modules/aspects/defaults.nix
··· 3 3 { lib, ... }: 4 4 { 5 5 imports = [ (lib.mkAliasOptionModule [ "default" ] [ "ctx" "default" ]) ]; 6 - 7 - ctx.default._.default = _: { }; 8 - 6 + ctx.default = { }; 9 7 }; 10 8 }
+7 -15
modules/aspects/definition.nix
··· 8 8 9 9 mkAspect = aspect: classes: { ${aspect} = parametric (lib.genAttrs classes (_: { })); }; 10 10 11 - toClasses = 12 - from: 13 - if from ? classes then 14 - map (c: { 15 - aspect = from.aspect; 16 - class = c; 17 - }) from.classes 18 - else 19 - [ 20 - { 21 - aspect = from.aspect; 22 - class = from.class; 23 - } 24 - ]; 11 + toClasses = from: [ 12 + { 13 + aspect = from.aspect; 14 + classes = from.classes or [ from.class ]; 15 + } 16 + ]; 25 17 26 18 hosts = map builtins.attrValues (builtins.attrValues den.hosts); 27 19 homes = map builtins.attrValues (builtins.attrValues den.homes); ··· 29 21 groupByAspect = 30 22 pairs: 31 23 lib.foldl' ( 32 - acc: { aspect, class }: acc // { ${aspect} = (acc.${aspect} or [ ]) ++ [ class ]; } 24 + acc: { aspect, classes }: acc // { ${aspect} = (acc.${aspect} or [ ]) ++ classes; } 33 25 ) { } pairs; 34 26 35 27 deps = lib.pipe hosts [
+3 -3
modules/aspects/provides/define-user.nix
··· 23 23 if lib.hasSuffix "darwin" host.system then "/Users/${user.userName}" else "/home/${user.userName}"; 24 24 25 25 userContext = 26 - { host, user, ... }: 26 + { host, user }: 27 27 { 28 28 nixos.users.users.${user.userName} = { 29 29 name = user.userName; ··· 41 41 }; 42 42 43 43 hmContext = 44 - { home, ... }: 44 + { home }: 45 45 userContext { 46 46 host.system = home.system; 47 47 user.userName = home.userName; 48 48 }; 49 49 in 50 50 { 51 - den.provides.define-user = den.lib.parametric { 51 + den.provides.define-user = den.lib.parametric.exactly { 52 52 inherit description; 53 53 includes = [ 54 54 userContext
+12 -10
modules/aspects/provides/unfree/unfree-predicate-builder.nix
··· 30 30 }; 31 31 }; 32 32 33 - osAspect = take.exactly ( 33 + osAspect = 34 34 { host }: 35 35 { 36 36 ${host.class}.imports = [ unfreeModule ]; 37 - } 38 - ); 39 - userAspect = take.exactly ( 40 - { host, user }: lib.mkMerge (map (c: { ${c}.imports = [ unfreeModule ]; }) user.classes) 41 - ); 42 - homeAspect = take.exactly ( 37 + }; 38 + 39 + userAspect = 40 + { host, user }: 41 + lib.optionalAttrs (lib.elem "homeManager" user.classes) { 42 + homeManager.imports = [ unfreeModule ]; 43 + }; 44 + 45 + homeAspect = 43 46 { home }: 44 47 { 45 48 ${home.class}.imports = [ unfreeModule ]; 46 - } 47 - ); 49 + }; 48 50 49 - aspect = parametric { 51 + aspect = parametric.exactly { 50 52 inherit description; 51 53 includes = [ 52 54 osAspect
+3 -3
modules/aspects/provides/user-shell.nix
··· 32 32 { 33 33 den.provides.user-shell = 34 34 shell: 35 - den.lib.parametric { 35 + den.lib.parametric.exactly { 36 36 inherit description; 37 37 includes = [ 38 - ({ user, ... }: userShell shell user) 39 - ({ home, ... }: userShell shell home) 38 + ({ host, user }: userShell shell user) 39 + ({ home }: userShell shell home) 40 40 ]; 41 41 }; 42 42 }