···174```
175176```nix
177-# custom user-defined Nix classes.
00000000000000000000000000000000000178179-# any aspect can use my `persys` class to forward configs into
180-# nixos.environment.persistance."/nix/persist/system"
181-# **ONLY** when environment.persistance option is present at host.
182persys = { host }: den._.forward {
183 each = lib.singleton true;
184 fromClass = _: "persys";
185 intoClass = _: host.class;
186 intoPath = _: [ "environment" "persistance" "/nix/persist/system" ];
187 fromAspect = _: den.aspects.${host.aspect};
188- guard = { options, ... }: options ? environment.persistance;
189};
190191# enable on all hosts
192den.ctx.host.includes = [ persys ];
193194-# becomes nixos.environment.persistance."/nix/persist/system".hideMounts = true;
195-# no mkIf, set configs and guard ensures to include only when Impermanence exists
196den.aspects.my-laptop.persys.hideMounts = true;
197```
···174```
175176```nix
177+# Custom Nix classes.
178+179+# Example: A class for role-based configuration between users and hosts
180+181+roleClass =
182+ { host, user }:
183+ { class, aspect-chain }:
184+ den._.forward {
185+ each = lib.intersectLists (host.roles or []) (user.roles or []);
186+ fromClass = lib.id;
187+ intoClass = _: host.class;
188+ intoPath = _: [ ];
189+ fromAspect = _: lib.head aspect-chain;
190+ };
191+192+den.ctx.user.includes = [ roleClass ];
193+194+den.hosts.x86_64-linux.igloo = {
195+ roles = [ "devops" "gaming" ];
196+ users = {
197+ alice.roles = [ "gaming" ];
198+ bob.roles = [ "devops" ];
199+ };
200+};
201+202+den.aspects.alice = {
203+ # enabled when host supports gaming role
204+ gaming = { pkgs, ... }: { programs.steam.enable = true; };
205+206+ # enabled when host supports devops role
207+ devops = { pkgs, ... }: { virtualisation.podman.enable = true; };
208+};
209+```
210+211+```nix
212+# Forward guards allow feature-detection without mkIf/mkMerge cluttering.
213214+# Aspects use the `persys` class without any conditional. And guard guarantees
215+# settings are applied **only** when impermanence module has been imported.
0216persys = { host }: den._.forward {
217 each = lib.singleton true;
218 fromClass = _: "persys";
219 intoClass = _: host.class;
220 intoPath = _: [ "environment" "persistance" "/nix/persist/system" ];
221 fromAspect = _: den.aspects.${host.aspect};
222+ guard = { options, config, ... }: options ? environment.persistance;
223};
224225# enable on all hosts
226den.ctx.host.includes = [ persys ];
227228+# aspects just attach config to custom class
0229den.aspects.my-laptop.persys.hideMounts = true;
230```
+35-1
docs/src/content/docs/guides/custom-classes.mdx
···153};
154```
15500000000000000000000000000000000000156#### Example: A git class that forwards to home-manager.
157158```nix
···195196# enable class for all users:
197den.ctx.user.includes = [ nixClass ];
198-199200# custom aspect that uses the `nix` class.
201nix-allowed = { user, ... }: { nix.allowed-users = [ user.userName ]; };
···153};
154```
155156+#### Example: Role based configuration between users and hosts
157+158+A dynamic class for matching roles between users and hosts.
159+160+```nix
161+roleClass =
162+ { host, user }:
163+ { class, aspect-chain }:
164+ den._.forward {
165+ each = lib.intersectLists (host.roles or []) (user.roles or []);
166+ fromClass = lib.id;
167+ intoClass = _: host.class;
168+ intoPath = _: [ ];
169+ fromAspect = _: lib.head aspect-chain;
170+ };
171+172+den.ctx.user.includes = [ roleClass ];
173+174+den.hosts.x86_64-linux.igloo = {
175+ roles = [ "devops" "gaming" ];
176+ users = {
177+ alice.roles = [ "gaming" ];
178+ bob.roles = [ "devops" ];
179+ };
180+};
181+182+den.aspects.alice = {
183+ # enabled when host supports gaming role
184+ gaming = { pkgs, ... }: { programs.steam.enable = true; };
185+186+ # enabled when host supports devops role
187+ devops = { pkgs, ... }: { virtualisation.podman.enable = true; };
188+};
189+```
190+191#### Example: A git class that forwards to home-manager.
192193```nix
···230231# enable class for all users:
232den.ctx.user.includes = [ nixClass ];
0233234# custom aspect that uses the `nix` class.
235nix-allowed = { user, ... }: { nix.allowed-users = [ user.userName ]; };