···56565757[noflake](https://den.oeiuwq.com/tutorials/noflake): -flakes +npins +lib.evalModules +nix-maid
58585959+[microvm](https://den.oeiuwq.com/tutorials/microvm): MicroVM runnable-pkg and guests. custom ctx-pipeline.
6060+5961[example](https://den.oeiuwq.com/tutorials/example): cross-platform
60626163[ci](https://den.oeiuwq.com/tutorials/ci): Each feature tested as code examples
···9810099101## Code example (OS configuration domain)
100102103103+### Defining hosts, users and homes.
104104+101105```nix
102102-# Define hosts, users & homes
103106den.hosts.x86_64-linux.lap.users.vic = {};
104107den.hosts.aarch64-darwin.mac.users.vic = {};
105108den.homes.aarch64-darwin.vic = {};
···111114$ home-manager switch --flake .#vic
112115```
113116117117+### Extensible Schemas for hosts, users and homes.
118118+114119```nix
115120# extensible base modules for common, typed schemas
116121den.schema.user = { user, lib, ... }: {
···122127};
123128```
124129130130+### Dendritic Multi-Platform Hosts
131131+125132```nix
126133# modules/my-laptop.nix
127134{ den, inputs, ... }: {
128135 den.aspects.my-laptop = {
129129- # re-usable configuration aspects
130130- includes = [ den.aspects.work-vpn ];
136136+ # re-usable configuration aspects. Den batteries and yours.
137137+ includes = [ den.provides.hostname den.aspects.work-vpn ];
131138132139 # regular nixos/darwin modules or any other Nix class
133140 nixos = { pkgs, ... }: { imports = [ inputs.disko.nixosModules.disko ]; };
134141 darwin = { pkgs, ... }: { imports = [ inputs.nix-homebrew.darwinModules.nix-homebrew ]; };
135142136136- # Den `os` Nix class forwards to both nixos and darwin
143143+ # Custom Nix classes. `os` applies to both nixos and darwin. contributed by @Risa-G.
144144+ # See https://den.oeiuwq.com/guides/custom-classes/#user-contributed-examples
137145 os = { pkgs, ... }: {
138138- networking.hostName = "yavanna";
139139- environment.packages = [ pkgs.direnv ];
146146+ environment.systemPackages = [ pkgs.direnv ];
140147 };
141148142142- # host can contribute to its users' environment
149149+ # host can contribute default home environments to all its users.
143150 homeManager.programs.vim.enable = true;
144151 };
145152}
146153```
147154155155+### Multiple User Home Environments
156156+148157```nix
149158# modules/vic.nix
150159{ den, ... }: {
151160 den.aspects.vic = {
152152- # supports multiple home environments
161161+ # supports multiple home environments, eg: for migrating from homeManager.
153162 homeManager = { pkgs, ... }: { };
154163 hjem.files.".envrc".text = "use flake ~/hk/home";
155164 maid.kconfig.settings.kwinrc.Desktops.Number = 3;
156165157157- # user can contribute configurations to all hosts it lives on
166166+ # user can contribute OS-configurations to any host it lives on
158167 darwin.services.karabiner-elements.enable = true;
159168160169 # user class forwards into {nixos/darwin}.users.users.<userName>
···173182}
174183```
175184176176-```nix
177177-# Custom Nix classes.
185185+### Custom Dendritic Nix Classes
186186+187187+See [custom-classes docs](https://den.oeiuwq.com/guides/custom-classes) for explanation.
178188189189+```nix
179190# Example: A class for role-based configuration between users and hosts
180191181192roleClass =
···200211};
201212202213den.aspects.alice = {
203203- # enabled when host supports gaming role
214214+ # enabled when both support gaming role
204215 gaming = { pkgs, ... }: { programs.steam.enable = true; };
216216+};
205217206206- # enabled when host supports devops role
218218+den.aspects.bob = {
219219+ # enabled when both support devops role
207220 devops = { pkgs, ... }: { virtualisation.podman.enable = true; };
221221+222222+ # not enabled at igloo host (bob missing gaming role on that host)
223223+ gaming = {};
208224};
209225```
210226211211-```nix
212212-# Forward guards allow feature-detection without mkIf/mkMerge cluttering.
227227+### Guarded Forwarding Classes
228228+229229+Forward guards allow feature-detection without mkIf/mkMerge cluttering.
230230+231231+Aspects can simply assign configurations into a class (here `persys`)
232232+from any file, without any `mkIf`/`mkMerge` cluttering. The logic for
233233+determining if the class takes effect is defined at a single place.
213234235235+```nix
214236# Aspects use the `persys` class without any conditional. And guard guarantees
215237# settings are applied **only** when impermanence module has been imported.
216238persys = { host }: den._.forward {
···228250# aspects just attach config to custom class
229251den.aspects.my-laptop.persys.hideMounts = true;
230252```
253253+254254+### User-defined Extensions to Den Framework.
255255+256256+See example [`template/microvm`](https://den.oeiuwq.com/tutorials/microvm) for an example
257257+of custom `den.ctx` and `den.schema` extensions for supporting
258258+Declarative [MicroVM](https://microvm-nix.github.io/microvm.nix/declarative.html) guests with automatic host-shared `/nix/store`.
259259+260260+```nix
261261+den.hosts.x86_64-linux.guest = {};
262262+den.hosts.x86_64-linux.host = {
263263+ microvm.guests = [ den.hosts.x86_64-linux.guest ];
264264+};
265265+266266+den.aspects.guest = {
267267+ # propagated into host.nixos.microvm.vms.<name>;
268268+ microvm.autostart = true;
269269+270270+ # guest supports all Den features.
271271+ includes = [ den.provides.hostname ];
272272+ # As MicroVM guest propagated into host.nixos.microvm.vms.<name>.config;
273273+ nixos = { pkgs, ... }: { environment.systemPackages = [ pkgs.hello ]; };
274274+};
275275+```