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.

docs: add section about Aspects custom modules (#388)

Signed-off-by: Pol Dellaiera <pol.dellaiera@protonmail.com>

authored by

Pol Dellaiera and committed by
GitHub
53c30ea9 509fc879

+59 -9
+59 -9
docs/src/content/docs/guides/configure-aspects.mdx
··· 30 30 31 31 ```nix "homeManager" "hjem" "maid" "x86_64-linux" 32 32 den.hosts.x86_64-linux.igloo.users = { 33 - tux = { 33 + tux = { 34 34 classes = [ "homeManager" "hjem" ]; 35 35 }; 36 36 pingu = { ··· 91 91 ## Owned Configs 92 92 93 93 Attributes named after a Nix class (`nixos`, `darwin`, `homeManager`, or any 94 - custom class) are referred by this documentation as **owned configs**. 94 + custom class) are referred by this documentation as **owned configs**. 95 95 96 96 They are just a regular Nix module: 97 97 ··· 134 134 being resolved and an `aspect-chain` that lead to the current aspect (most recent last). 135 135 136 136 137 - `(3)` is a more interesting kind of aspect that is used by Den to pass host/user defitions 137 + `(3)` is a more interesting kind of aspect that is used by Den to pass host/user defitions 138 138 into these functions, so they can inspect the host features and provide 139 139 configuration accordingly. 140 140 ··· 186 186 stage. Use `den.lib.take.exactly` if a function should only run in specific contexts. 187 187 </Aside> 188 188 189 - 190 189 ## Aspect Meta-Data 191 190 192 191 Aspects have a `meta` submodule that can be used to attach meta-data ··· 207 206 aspect.meta.self # a reference to the aspect module `config`. 208 207 ``` 209 208 210 - You can acess meta values by referencing an aspect: 209 + You can access meta values by referencing an aspect: 211 210 212 211 ```nix 213 212 den.aspects.igloo.meta.name ··· 216 215 Or if an aspect needs to access its own meta data as part of its parametric functor, 217 216 it can do something like: 218 217 219 - 220 218 ```nix 221 - den.aspects.foo = 219 + den.aspects.foo = 222 220 { config, lib, ... }: # module args to access `config.meta` 223 221 { 224 222 meta.foo = "bar"; 225 - __functor = self: ctx: 226 - if config.meta.foo == "bar" 223 + __functor = self: ctx: 224 + if config.meta.foo == "bar" 227 225 then { } # do nothing, skip. 228 226 { 229 227 includes = filter (i: someCondition i) self.includes; 230 228 }; 231 229 } 230 + ``` 232 231 232 + ## Aspect Custom Submodule 233 + 234 + In case an aspect needs a custom submodule, it can be added this way: 235 + 236 + ```nix 237 + den.aspects.tux = 238 + { config, ... }: # The function-args style is required for `imports` not to be interpreted as an Aspect class. 239 + { 240 + imports = [ 241 + { 242 + options = { 243 + default-key = lib.mkOption { 244 + type = with lib.types; str; 245 + }; 246 + keygrip = lib.mkOption { 247 + type = with lib.types; str; 248 + }; 249 + }; 250 + } 251 + ]; 252 + 253 + default-key = "Hello World!"; 254 + keygrip = "Hello World!"; 255 + } 233 256 ``` 234 257 258 + And then, you can refer to this custom submodule from other aspects: 235 259 260 + ```nix 261 + { den, ... }: 262 + { 263 + den.aspects.igloo = { 264 + homeManager = 265 + { config, ... }: 266 + { 267 + programs = { 268 + gpg = { 269 + enable = true; 270 + settings.default-key = den.aspects.${config.home.username}.default-key; 271 + }; 272 + }; 236 273 274 + services = { 275 + gpg-agent = { 276 + enable = true; 277 + enableSshSupport = true; 278 + sshKeys = [ 279 + den.aspects.${config.home.username}.keygrip 280 + ]; 281 + }; 282 + }; 283 + }; 284 + }; 285 + } 286 + ```