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.

improve(lib): split lib.nix into files (#290)

fixes #241

authored by

Victor Borja and committed by
GitHub
0def158d 2f1eace1

+185 -224
+4
Justfile
··· 4 4 check-all: 5 5 nix-build ./templates/noflake --no-out-link -A flake.nixosConfigurations.igloo 6 6 just all check 7 + just unit 7 8 8 9 update-all: 9 10 cd templates/noflake && npins update den flake-aspects ··· 37 38 38 39 fmt: 39 40 nix run github:vic/checkmate#fmt --override-input target . 41 + 42 + unit: 43 + nix flake check --override-input target . github:vic/checkmate
+1 -2
checkmate/modules/aspect-functor.nix
··· 2 2 lib, 3 3 inputs, 4 4 config, 5 + den, 5 6 ... 6 7 }: 7 8 let 8 - den.lib = inputs.target.lib { inherit lib inputs config; }; 9 - 10 9 inherit (den.lib) parametric canTake; 11 10 12 11 aspect-example = parametric.atLeast {
-40
checkmate/modules/den-brackets.nix
··· 1 - { ... }@top: 2 - let 3 - lib = top.inputs.nixpkgs.lib; 4 - 5 - # deadnix: skip 6 - __findFile = 7 - if true then 8 - import "${top.inputs.target}/nix/den-brackets.nix" { inherit lib config inputs; } 9 - else 10 - __findFile; 11 - 12 - inputs = { 13 - 14 - }; 15 - 16 - config.den = { 17 - default.foo = 1; 18 - 19 - provides.foo.a = 2; 20 - provides.foo.provides.bar.b = 3; 21 - provides.foo.provides.c = 4; 22 - 23 - d = 5; 24 - 25 - aspects.foo.a = 6; 26 - aspects.foo.provides.bar.b = 7; 27 - aspects.foo.provides.c = 8; 28 - 29 - }; 30 - in 31 - { 32 - flake.tests."<den.default>" = 33 - let 34 - expr = <den.default>; 35 - expected.foo = 2; 36 - in 37 - { 38 - inherit expr expected; 39 - }; 40 - }
+1 -1
checkmate/modules/function_can_take.nix
··· 2 2 lib, 3 3 inputs, 4 4 config, 5 + den, 5 6 ... 6 7 }: 7 8 let 8 - den.lib = inputs.target.lib { inherit inputs lib config; }; 9 9 takes = den.lib.canTake; 10 10 11 11 flake.tests."test exactly fails" = {
+4
checkmate/modules/lib.nix
··· 1 + { inputs, ... }: 2 + { 3 + imports = [ (inputs.target.nixModule inputs) ]; 4 + }
+1 -12
default.nix
··· 1 - { 2 - __functor = self: import ./nix/lib.nix; 3 - nixModule = 4 - inputs: 5 - { config, lib, ... }: 6 - let 7 - den-lib = import ./nix/lib.nix { inherit inputs config lib; }; 8 - in 9 - { 10 - imports = [ den-lib.nixModule ]; 11 - }; 12 - } 1 + import ./nix
+1 -1
modules/options.nix
··· 6 6 }: 7 7 let 8 8 inherit (config) den; 9 - types = import ./../nix/types.nix { inherit inputs lib den; }; 9 + types = import ./../nix/lib/types.nix { inherit inputs lib den; }; 10 10 baseMod = lib.mkOption { 11 11 type = lib.types.deferredModule; 12 12 default = { };
nix/ctx-apply.nix nix/lib/ctx-apply.nix
nix/ctx-types.nix nix/lib/ctx-types.nix
+16 -8
nix/default.nix
··· 1 1 let 2 + den-lib = import ./lib; 3 + 4 + nixModule = inputs: { config, lib, ... }: (den-lib { inherit inputs config lib; }).nixModule; 5 + 2 6 flakeModules.default = ./flakeModule.nix; 3 7 flakeModules.dendritic = ./dendritic.nix; 4 - in 5 - { 6 - # flake-parts conventions 7 - flakeModule = flakeModules.default; 8 - inherit flakeModules; 9 - modules.flake = flakeModules; 10 8 11 9 templates = { 12 10 default.path = ../templates/default; ··· 24 22 bogus.path = ../templates/bogus; 25 23 bogus.description = "For bug reproduction"; 26 24 }; 25 + in 26 + { 27 + __functor = _: den-lib; 28 + lib = den-lib; 29 + 30 + inherit nixModule templates; 31 + namespace = import ./lib/namespace.nix; 27 32 packages = import ./flake-packages.nix; 28 - namespace = import ./namespace.nix; 29 - lib = import ./lib.nix; 33 + 34 + # flake-parts conventions 35 + flakeModule = flakeModules.default; 36 + inherit flakeModules; 37 + modules.flake = flakeModules; 30 38 }
nix/den-brackets.nix nix/lib/den-brackets.nix
+1 -1
nix/fn-can-take.nix nix/lib/can-take.nix
··· 1 - lib: 1 + { lib, ... }: 2 2 let 3 3 check = 4 4 params: func:
nix/home-env.nix nix/lib/home-env.nix
-158
nix/lib.nix
··· 1 - { 2 - inputs, 3 - lib, 4 - config, 5 - ... 6 - }: 7 - let 8 - inherit (config) den; 9 - 10 - # "Just Give 'Em One of These" - Moe Szyslak 11 - # A __functor that applies context to parametric includes (functions) 12 - funk = 13 - apply: aspect: 14 - aspect 15 - // { 16 - __functor = self: ctx: { 17 - includes = builtins.filter (x: x != { }) ( 18 - map (apply ctx) (builtins.filter isFn (self.includes or [ ])) 19 - ); 20 - }; 21 - }; 22 - 23 - isFn = f: (builtins.isFunction f) || (builtins.isAttrs f && f ? __functor); 24 - canTake = import ./fn-can-take.nix lib; 25 - 26 - # an aspect producing only owned configs 27 - owned = (lib.flip builtins.removeAttrs) [ 28 - "includes" 29 - "__functor" 30 - ]; 31 - 32 - # only static includes from an aspect. 33 - statics = 34 - aspect: 35 - aspect 36 - // { 37 - __functor = 38 - self: 39 - { class, aspect-chain }: 40 - { 41 - includes = map (applyStatics { inherit class aspect-chain; }) (self.includes or [ ]); 42 - }; 43 - }; 44 - 45 - applyStatics = 46 - ctx: f: 47 - if !isFn f then 48 - f 49 - else if isStatic f && isCtxStatic ctx then 50 - f ctx 51 - else 52 - { }; 53 - 54 - isStatic = canTake.atLeast { 55 - class = ""; 56 - aspect-chain = [ ]; 57 - }; 58 - isCtxStatic = (lib.flip canTake.exactly) ({ class, aspect-chain }: class aspect-chain); 59 - 60 - take.unused = _unused: used: used; 61 - take.exactly = take canTake.exactly; 62 - take.atLeast = take canTake.atLeast; 63 - take.__functor = 64 - _: takes: fn: ctx: 65 - if takes ctx fn then fn ctx else { }; 66 - 67 - parametric.atLeast = funk (lib.flip take.atLeast); 68 - parametric.exactly = funk (lib.flip take.exactly); 69 - parametric.expands = 70 - attrs: parametric.withOwn (aspect: ctx: parametric.atLeast aspect (ctx // attrs)); 71 - parametric.fixedTo = 72 - attrs: aspect: 73 - aspect 74 - // { 75 - __functor = 76 - self: 77 - { class, aspect-chain }: 78 - { 79 - includes = [ 80 - (owned self) 81 - (statics self { inherit class aspect-chain; }) 82 - (parametric.atLeast self attrs) 83 - ]; 84 - }; 85 - }; 86 - parametric.withOwn = 87 - functor: aspect: 88 - aspect 89 - // { 90 - __functor = self: ctx: { 91 - includes = 92 - if isCtxStatic ctx then 93 - [ 94 - (owned self) 95 - (statics self ctx) 96 - ] 97 - else 98 - [ (functor self ctx) ]; 99 - }; 100 - }; 101 - parametric.__functor = _: parametric.withOwn parametric.atLeast; 102 - 103 - aspects = 104 - let 105 - fa-lib = inputs.flake-aspects.lib lib; 106 - defaultFunctor = (parametric { }).__functor; 107 - typesConf = { inherit defaultFunctor; }; 108 - types = lib.mapAttrs (n: v: v typesConf) fa-lib.types; 109 - in 110 - fa-lib // { inherit types; }; 111 - 112 - __findFile = import ./den-brackets.nix { inherit lib config; }; 113 - 114 - nh = import ./nh.nix { 115 - inherit 116 - lib 117 - config 118 - den 119 - inputs 120 - ; 121 - }; 122 - 123 - nsTypes = import ./namespace-types.nix { inherit lib den; }; 124 - ctxTypes = import ./ctx-types.nix { inherit lib den; }; 125 - ctxApply = import ./ctx-apply.nix { inherit lib den; }; 126 - 127 - home-env = import ./home-env.nix { inherit lib den inputs; }; 128 - 129 - nixModule = import ./nixModule { 130 - inherit 131 - lib 132 - inputs 133 - config 134 - den-lib 135 - ; 136 - }; 137 - 138 - den-lib = { 139 - inherit 140 - parametric 141 - aspects 142 - __findFile 143 - statics 144 - owned 145 - isFn 146 - canTake 147 - take 148 - isStatic 149 - ctxApply 150 - ctxTypes 151 - nsTypes 152 - nh 153 - home-env 154 - nixModule 155 - ; 156 - }; 157 - in 158 - den-lib
+13
nix/lib/aspects.nix
··· 1 + { 2 + lib, 3 + inputs, 4 + den, 5 + ... 6 + }: 7 + let 8 + fa-lib = inputs.flake-aspects.lib lib; 9 + defaultFunctor = (den.lib.parametric { }).__functor; 10 + typesConf = { inherit defaultFunctor; }; 11 + types = lib.mapAttrs (n: v: v typesConf) fa-lib.types; 12 + in 13 + fa-lib // { inherit types; }
+37
nix/lib/default.nix
··· 1 + { 2 + lib, 3 + config, 4 + inputs, 5 + ... 6 + }: 7 + let 8 + inherit (config) den; 9 + load = 10 + f: 11 + import f { 12 + inherit 13 + lib 14 + config 15 + inputs 16 + den 17 + den-lib 18 + ; 19 + }; 20 + den-lib = builtins.mapAttrs (_: load) { 21 + aspects = ./aspects.nix; 22 + canTake = ./can-take.nix; 23 + ctxApply = ./ctx-apply.nix; 24 + ctxTypes = ./ctx-types.nix; 25 + __findFile = ./den-brackets.nix; 26 + functor = ./functor.nix; 27 + fwTypes = ./types.nix; 28 + home-env = ./home-env.nix; 29 + nh = ./nh.nix; 30 + nixModule = ../nixModule; 31 + nsTypes = ./namespace-types.nix; 32 + parametric = ./parametric.nix; 33 + statics = ./statics.nix; 34 + take = ./take.nix; 35 + }; 36 + in 37 + den-lib
+12
nix/lib/functor.nix
··· 1 + # "Just Give 'Em One of These" - Moe Szyslak 2 + # A __functor that applies context to parametric includes (functions) 3 + { lib, ... }: 4 + apply: aspect: 5 + aspect 6 + // { 7 + __functor = self: ctx: { 8 + includes = builtins.filter (x: x != { }) ( 9 + map (apply ctx) (builtins.filter lib.isFunction (self.includes or [ ])) 10 + ); 11 + }; 12 + }
+42
nix/lib/parametric.nix
··· 1 + { lib, den, ... }: 2 + let 3 + inherit (den.lib) take functor; 4 + inherit (den.lib.statics) owned statics isCtxStatic; 5 + 6 + parametric.atLeast = functor (lib.flip take.atLeast); 7 + parametric.exactly = functor (lib.flip take.exactly); 8 + parametric.expands = 9 + attrs: parametric.withOwn (aspect: ctx: parametric.atLeast aspect (ctx // attrs)); 10 + parametric.fixedTo = 11 + attrs: aspect: 12 + aspect 13 + // { 14 + __functor = 15 + self: 16 + { class, aspect-chain }: 17 + { 18 + includes = [ 19 + (owned self) 20 + (statics self { inherit class aspect-chain; }) 21 + (parametric.atLeast self attrs) 22 + ]; 23 + }; 24 + }; 25 + parametric.withOwn = 26 + functor: aspect: 27 + aspect 28 + // { 29 + __functor = self: ctx: { 30 + includes = 31 + if isCtxStatic ctx then 32 + [ 33 + (owned self) 34 + (statics self ctx) 35 + ] 36 + else 37 + [ (functor self ctx) ]; 38 + }; 39 + }; 40 + parametric.__functor = _: parametric.withOwn parametric.atLeast; 41 + in 42 + parametric
+41
nix/lib/statics.nix
··· 1 + { lib, den, ... }: 2 + let 3 + # an aspect producing only owned configs 4 + owned = (lib.flip builtins.removeAttrs) [ 5 + "includes" 6 + "__functor" 7 + ]; 8 + 9 + # only static includes from an aspect. 10 + statics = 11 + aspect: 12 + aspect 13 + // { 14 + __functor = 15 + self: 16 + { class, aspect-chain }: 17 + { 18 + includes = map (applyStatics { inherit class aspect-chain; }) (self.includes or [ ]); 19 + }; 20 + }; 21 + 22 + applyStatics = 23 + ctx: f: 24 + if !lib.isFunction f then 25 + f 26 + else if isStatic f && isCtxStatic ctx then 27 + f ctx 28 + else 29 + { }; 30 + 31 + isStatic = den.lib.canTake.atLeast { 32 + class = ""; 33 + aspect-chain = [ ]; 34 + }; 35 + isCtxStatic = (lib.flip den.lib.canTake.exactly) ({ class, aspect-chain }: class aspect-chain); 36 + 37 + in 38 + { 39 + __functor = _: statics; 40 + inherit isCtxStatic owned statics; 41 + }
+10
nix/lib/take.nix
··· 1 + { den, ... }: 2 + let 3 + take.unused = _unused: used: used; 4 + take.exactly = take den.lib.canTake.exactly; 5 + take.atLeast = take den.lib.canTake.atLeast; 6 + take.__functor = 7 + _: takes: fn: ctx: 8 + if takes ctx fn then fn ctx else { }; 9 + in 10 + take
nix/namespace-types.nix nix/lib/namespace-types.nix
nix/namespace.nix nix/lib/namespace.nix
nix/nh.nix nix/lib/nh.nix
nix/types.nix nix/lib/types.nix
+1 -1
templates/ci/modules/features/angle-brackets.nix
··· 7 7 { den, __findFile, ... }: 8 8 { 9 9 _module.args.__findFile = den.lib.__findFile; 10 - expr = <den.lib> ? owned; 10 + expr = <den.lib.statics> ? owned; 11 11 expected = true; 12 12 } 13 13 );