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.

README: Den is about parametric aspects. (#144)

authored by

Victor Borja and committed by
GitHub
b07ef22d 7431d485

+63 -7
+63 -7
README.md
··· 87 87 </td> 88 88 <td> 89 89 90 - 🏠 Define [Hosts, Users](templates/ci/modules/hosts.nix) & [Homes](templates/ci/modules/homes.nix) concisely. 90 + ### Den fundamental idea 91 + 92 + <details> 93 + 94 + <summary> 95 + 96 + > Configurations that can be applied to multiple host+user combinations. 97 + 98 + </summary> 99 + 100 + ```nix 101 + # context => aspect 102 + { host, user, ... }@context: { 103 + # any Nix configuration classes 104 + nixos = { }; 105 + darwin = { }; 106 + homeManager = { }; 107 + # supports conditional includes that inspect context 108 + # unlike nix-module imports 109 + includes = [ ]; 110 + } 111 + ``` 112 + 113 + You first define which [Hosts, Users](templates/ci/modules/hosts.nix) 114 + and [Homes](templates/ci/modules/homes.nix) exist 115 + using freeform-attributes or base-modules. 116 + 117 + ```nix 118 + { 119 + # isWarm or any other freeform attr 120 + den.hosts.x86_64-linux.igloo.isWarm = true; 121 + } 122 + ``` 123 + 124 + Then, you write functions from context `host`/`user` to configs. 125 + 126 + ```nix 127 + { 128 + den.aspects.heating = { host, user, ... }: { 129 + nixos = { ... }; # depends on host.isWarm, etc. 130 + homeManager = { ... }; 131 + }; 132 + 133 + # previous aspect can be included on any host 134 + # den.aspects.igloo.includes = [ den.aspects.heating ]; 135 + # or by default in all of them 136 + # den.default.includes = [ den.aspects.heating ]; 137 + } 138 + ``` 139 + 140 + This way, configurations are truly re-usable, 141 + as they are nothing more than functions of the 142 + particularities of the host or its users. 143 + 144 + </details> 145 + 146 + ### Code example 91 147 92 148 See schema in [`_types.nix`](modules/_types.nix). 93 149 94 150 ```nix 95 151 # modules/hosts.nix 96 152 { 97 - # same home-manager vic configuration 98 - # over laptop, macbook and standalone-hm 153 + # same vic home-manager aspect shared 154 + # on laptop, macbook and standalone-hm 99 155 den.hosts.x86_64-linux.lap.users.vic = {}; 100 156 den.hosts.aarch64-darwin.mac.users.vic = {}; 101 157 den.homes.aarch64-darwin.vic = {}; ··· 108 164 $ home-manager switch --flake .#vic 109 165 ``` 110 166 111 - 🧩 [Aspect-oriented](https://github.com/vic/flake-aspects) incremental features. 112 - 113 - Any module can contribute configurations to aspects. 167 + Any module can contribute configurations to [aspects](https://github.com/vic/flake-aspects). 114 168 115 169 ```nix 116 170 # modules/my-laptop.nix ··· 156 210 157 211 }; 158 212 } 213 + ``` 159 214 215 + ```nix 160 216 # modules/vic.nix 161 217 { den, ... }: { 162 218 den.aspects.vic = { ··· 167 223 }; 168 224 includes = [ 169 225 den.aspects.tiling-wm 170 - den._.primary-user 226 + den.provides.primary-user 171 227 ]; 172 228 }; 173 229 }