···5657[noflake](https://den.oeiuwq.com/tutorials/noflake): -flakes +npins +lib.evalModules +nix-maid
580059[example](https://den.oeiuwq.com/tutorials/example): cross-platform
6061[ci](https://den.oeiuwq.com/tutorials/ci): Each feature tested as code examples
···9899## Code example (OS configuration domain)
10000101```nix
102-# Define hosts, users & homes
103den.hosts.x86_64-linux.lap.users.vic = {};
104den.hosts.aarch64-darwin.mac.users.vic = {};
105den.homes.aarch64-darwin.vic = {};
···111$ home-manager switch --flake .#vic
112```
11300114```nix
115# extensible base modules for common, typed schemas
116den.schema.user = { user, lib, ... }: {
···122};
123```
12400125```nix
126# modules/my-laptop.nix
127{ den, inputs, ... }: {
128 den.aspects.my-laptop = {
129- # re-usable configuration aspects
130- includes = [ den.aspects.work-vpn ];
131132 # regular nixos/darwin modules or any other Nix class
133 nixos = { pkgs, ... }: { imports = [ inputs.disko.nixosModules.disko ]; };
134 darwin = { pkgs, ... }: { imports = [ inputs.nix-homebrew.darwinModules.nix-homebrew ]; };
135136- # Den `os` Nix class forwards to both nixos and darwin
0137 os = { pkgs, ... }: {
138- networking.hostName = "yavanna";
139- environment.packages = [ pkgs.direnv ];
140 };
141142- # host can contribute to its users' environment
143 homeManager.programs.vim.enable = true;
144 };
145}
146```
14700148```nix
149# modules/vic.nix
150{ den, ... }: {
151 den.aspects.vic = {
152- # supports multiple home environments
153 homeManager = { pkgs, ... }: { };
154 hjem.files.".envrc".text = "use flake ~/hk/home";
155 maid.kconfig.settings.kwinrc.Desktops.Number = 3;
156157- # user can contribute configurations to all hosts it lives on
158 darwin.services.karabiner-elements.enable = true;
159160 # user class forwards into {nixos/darwin}.users.users.<userName>
···173}
174```
175176-```nix
177-# Custom Nix classes.
01780179# Example: A class for role-based configuration between users and hosts
180181roleClass =
···200};
201202den.aspects.alice = {
203- # enabled when host supports gaming role
204 gaming = { pkgs, ... }: { programs.steam.enable = true; };
0205206- # enabled when host supports devops role
0207 devops = { pkgs, ... }: { virtualisation.podman.enable = true; };
000208};
209```
210211-```nix
212-# Forward guards allow feature-detection without mkIf/mkMerge cluttering.
000002130214# Aspects use the `persys` class without any conditional. And guard guarantees
215# settings are applied **only** when impermanence module has been imported.
216persys = { host }: den._.forward {
···228# aspects just attach config to custom class
229den.aspects.my-laptop.persys.hideMounts = true;
230```
00000000000000000000000
···5657[noflake](https://den.oeiuwq.com/tutorials/noflake): -flakes +npins +lib.evalModules +nix-maid
5859+[microvm](https://den.oeiuwq.com/tutorials/microvm): MicroVM runnable-pkg and guests. custom ctx-pipeline.
60+61[example](https://den.oeiuwq.com/tutorials/example): cross-platform
6263[ci](https://den.oeiuwq.com/tutorials/ci): Each feature tested as code examples
···100101## Code example (OS configuration domain)
102103+### Defining hosts, users and homes.
104+105```nix
0106den.hosts.x86_64-linux.lap.users.vic = {};
107den.hosts.aarch64-darwin.mac.users.vic = {};
108den.homes.aarch64-darwin.vic = {};
···114$ home-manager switch --flake .#vic
115```
116117+### Extensible Schemas for hosts, users and homes.
118+119```nix
120# extensible base modules for common, typed schemas
121den.schema.user = { user, lib, ... }: {
···127};
128```
129130+### Dendritic Multi-Platform Hosts
131+132```nix
133# modules/my-laptop.nix
134{ den, inputs, ... }: {
135 den.aspects.my-laptop = {
136+ # re-usable configuration aspects. Den batteries and yours.
137+ includes = [ den.provides.hostname den.aspects.work-vpn ];
138139 # regular nixos/darwin modules or any other Nix class
140 nixos = { pkgs, ... }: { imports = [ inputs.disko.nixosModules.disko ]; };
141 darwin = { pkgs, ... }: { imports = [ inputs.nix-homebrew.darwinModules.nix-homebrew ]; };
142143+ # Custom Nix classes. `os` applies to both nixos and darwin. contributed by @Risa-G.
144+ # See https://den.oeiuwq.com/guides/custom-classes/#user-contributed-examples
145 os = { pkgs, ... }: {
146+ environment.systemPackages = [ pkgs.direnv ];
0147 };
148149+ # host can contribute default home environments to all its users.
150 homeManager.programs.vim.enable = true;
151 };
152}
153```
154155+### Multiple User Home Environments
156+157```nix
158# modules/vic.nix
159{ den, ... }: {
160 den.aspects.vic = {
161+ # supports multiple home environments, eg: for migrating from homeManager.
162 homeManager = { pkgs, ... }: { };
163 hjem.files.".envrc".text = "use flake ~/hk/home";
164 maid.kconfig.settings.kwinrc.Desktops.Number = 3;
165166+ # user can contribute OS-configurations to any host it lives on
167 darwin.services.karabiner-elements.enable = true;
168169 # user class forwards into {nixos/darwin}.users.users.<userName>
···182}
183```
184185+### Custom Dendritic Nix Classes
186+187+See [custom-classes docs](https://den.oeiuwq.com/guides/custom-classes) for explanation.
188189+```nix
190# Example: A class for role-based configuration between users and hosts
191192roleClass =
···211};
212213den.aspects.alice = {
214+ # enabled when both support gaming role
215 gaming = { pkgs, ... }: { programs.steam.enable = true; };
216+};
217218+den.aspects.bob = {
219+ # enabled when both support devops role
220 devops = { pkgs, ... }: { virtualisation.podman.enable = true; };
221+222+ # not enabled at igloo host (bob missing gaming role on that host)
223+ gaming = {};
224};
225```
226227+### Guarded Forwarding Classes
228+229+Forward guards allow feature-detection without mkIf/mkMerge cluttering.
230+231+Aspects can simply assign configurations into a class (here `persys`)
232+from any file, without any `mkIf`/`mkMerge` cluttering. The logic for
233+determining if the class takes effect is defined at a single place.
234235+```nix
236# Aspects use the `persys` class without any conditional. And guard guarantees
237# settings are applied **only** when impermanence module has been imported.
238persys = { host }: den._.forward {
···250# aspects just attach config to custom class
251den.aspects.my-laptop.persys.hideMounts = true;
252```
253+254+### User-defined Extensions to Den Framework.
255+256+See example [`template/microvm`](https://den.oeiuwq.com/tutorials/microvm) for an example
257+of custom `den.ctx` and `den.schema` extensions for supporting
258+Declarative [MicroVM](https://microvm-nix.github.io/microvm.nix/declarative.html) guests with automatic host-shared `/nix/store`.
259+260+```nix
261+den.hosts.x86_64-linux.guest = {};
262+den.hosts.x86_64-linux.host = {
263+ microvm.guests = [ den.hosts.x86_64-linux.guest ];
264+};
265+266+den.aspects.guest = {
267+ # propagated into host.nixos.microvm.vms.<name>;
268+ microvm.autostart = true;
269+270+ # guest supports all Den features.
271+ includes = [ den.provides.hostname ];
272+ # As MicroVM guest propagated into host.nixos.microvm.vms.<name>.config;
273+ nixos = { pkgs, ... }: { environment.systemPackages = [ pkgs.hello ]; };
274+};
275+```