### Run Den Virtual Machine Source: https://github.com/vic/den/wiki/start This command shows how to execute the virtual machine included with your Den project. This allows for quick testing of configuration changes without requiring a full system reboot. ```console nix run .#vm ``` -------------------------------- ### Initialize Den Project with Nix Flake Source: https://github.com/vic/den/wiki/start This snippet demonstrates how to create a new Den project using the default template and initialize it with Nix flakes. It involves creating a directory, initializing the flake, and updating dependencies. ```console mkdir my-den && cd my-den nix flake init -t github:vic/den nix flake update den ``` -------------------------------- ### Quick Start: Initialize and Update Den Project Source: https://github.com/vic/den/blob/main/docs/src/content/docs/tutorials/overview.md Sets up a new Den project by creating a directory, initializing it with the default template, and then updating the Den flake. This is the recommended starting point for new projects. ```console mkdir my-nix && cd my-nix nix flake init -t github:vic/den nix flake update den ``` -------------------------------- ### Den Library Deployment Pipeline Example (Nix) Source: https://github.com/vic/den/blob/main/docs/src/content/docs/explanation/library-vs-framework.mdx Demonstrates how to define a deployment pipeline using Den's library for context transformations. This example shows how to create aspects for deployment targets, enumerate services, and generate Terraform configurations. ```nix den.ctx.deploy._.deploy = { target: den.aspects.${target.name}; }; den.ctx.deploy.into.service = { target: map (s: { service = s; target = target; }) target.services; }; den.ctx.service._.service = { service, target: { terraform.resource.${service.name} = { ... }; }; }; ``` -------------------------------- ### Test Case for Bidirectional Providers (Nix) Source: https://github.com/vic/den/blob/main/docs/src/content/docs/tutorials/example.md Example test cases to verify the bidirectional provider configurations. These checks ensure that the 'nh' program is enabled on 'igloo' for 'alice' and 'helix' is enabled for 'alice' on 'igloo'. ```nix # modules/tests.nix — verifies the template works { checks."alice enabled igloo nh" = checkCond "..." igloo.programs.nh.enable; checks."igloo enabled alice helix" = checkCond "..." alice-at-igloo.programs.helix.enable; } ``` -------------------------------- ### Cross-Platform Host Configuration (Nix) Source: https://github.com/vic/den/blob/main/docs/src/content/docs/tutorials/example.md Defines user configurations across different host architectures and operating systems (x86_64-linux, aarch64-darwin). It demonstrates how a single user aspect ('alice') can generate appropriate configurations for NixOS, Darwin, and standalone Home-Manager setups. ```nix # modules/den.nix { den.hosts.x86_64-linux.igloo.users.alice = { }; den.hosts.aarch64-darwin.apple.users.alice = { }; den.homes.x86_64-linux.alice = { }; } ``` -------------------------------- ### Nix Build Commands Source: https://github.com/vic/den/wiki/README Provides example command-line instructions for rebuilding Nix configurations on different systems. These commands are used to apply the defined Nix configurations to the respective machines. ```bash $ nixos-rebuild switch --flake .#lap $ darwin-rebuild switch --flake .#mac $ home-manager switch --flake .#vic ``` -------------------------------- ### Defining Hosts, Users, and Homes in Nix Source: https://github.com/vic/den/wiki/README Demonstrates how to define host, user, and home configurations using Nix. This example shows the structure for specifying users for different host architectures and operating systems, and how to reference them. ```nix # modules/hosts.nix { # same vic home-manager aspect shared # on laptop, macbook and standalone-hm den.hosts.x86_64-linux.lap.users.vic = {}; den.hosts.aarch64-darwin.mac.users.vic = {}; den.homes.aarch64-darwin.vic = {}; } ``` -------------------------------- ### Build Minimal Den Configuration Source: https://github.com/vic/den/blob/main/docs/src/content/docs/tutorials/minimal.md Command to build the NixOS configuration for the 'igloo' host defined in the minimal Den setup. This command targets the toplevel system build of the configuration. ```console nix build .#nixosConfigurations.igloo.config.system.build.toplevel ``` -------------------------------- ### Initialize Den Project Source: https://github.com/vic/den/blob/main/docs/src/content/docs/tutorials/example.md Commands to create a new Den project using a flake template and update its dependencies. This sets up the basic project structure. ```console mkdir my-nix && cd my-nix nix flake init -t github:vic/den#example nix flake update den ``` -------------------------------- ### Complete Flake Example with Den and flake-parts (Nix) Source: https://context7.com/vic/den/llms.txt A comprehensive example of a Nix flake using Den and flake-parts. It includes definitions for flake outputs, inputs, and several module files (`dendritic.nix`, `hosts.nix`, `defaults.nix`, `igloo.nix`, `tux.nix`) that configure Den aspects and settings. ```nix # flake.nix { outputs = inputs: inputs.flake-parts.lib.mkFlake { inherit inputs; } (inputs.import-tree ./modules); inputs = { den.url = "github:vic/den"; flake-parts.url = "github:hercules-ci/flake-parts"; home-manager.url = "github:nix-community/home-manager"; import-tree.url = "github:vic/import-tree"; nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; }; } # modules/dendritic.nix { imports = [ inputs.den.flakeModules.dendritic ]; } # modules/hosts.nix { den.hosts.x86_64-linux.igloo.users.tux = { }; } # modules/defaults.nix { den, ... }: { den.default = { nixos.system.stateVersion = "25.11"; homeManager.home.stateVersion = "25.11"; includes = [ den._.define-user ]; }; } # modules/igloo.nix { den, ... }: { den.aspects.igloo.nixos = { pkgs, ... }: { environment.systemPackages = [ pkgs.hello ]; }; } # modules/tux.nix { den, ... }: { den.aspects.tux = { includes = [ den._.primary-user (den._.user-shell "fish") ]; homeManager = { pkgs, ... }: { home.packages = [ pkgs.htop ]; }; }; } ``` -------------------------------- ### Minimal Den flake.nix Configuration Source: https://github.com/vic/den/blob/main/docs/src/content/docs/tutorials/minimal.md The main flake definition for a minimal Den setup. It uses 'lib.evalModules' to load modules and specifies essential inputs like nixpkgs, import-tree, flake-aspects, and den. ```nix { outputs = inputs: (inputs.nixpkgs.lib.evalModules { modules = [ (inputs.import-tree ./modules) ]; specialArgs = { inherit inputs; }; }).config.flake; inputs = { nixpkgs.url = "https://channels.nixos.org/nixpkgs-unstable/nixexprs.tar.xz"; import-tree.url = "github:vic/import-tree"; flake-aspects.url = "github:vic/flake-aspects"; den.url = "github:vic/den"; }; } ``` -------------------------------- ### Initialize Minimal Den Project Source: https://github.com/vic/den/blob/main/docs/src/content/docs/tutorials/minimal.md Commands to create a new Nix project using the minimal Den template and update dependencies. This involves initializing a flake from a template and updating the 'den' input. ```console mkdir my-nix && cd my-nix nix flake init -t github:vic/den#minimal nix flake update den ``` -------------------------------- ### Enhancing Aspects in Nix Source: https://github.com/vic/den/wiki/README Illustrates how to extend or enhance existing aspects in Den. This example shows how to define a new aspect 'my-laptop' that includes configurations for NixOS, Darwin, and Home Manager, and imports external modules. ```nix # modules/my-laptop.nix { den.aspects.my-laptop = { # this aspect includes configurations # available from other aspects includes = [ # your own parametric aspects den.aspects.workplace-vpn # den's opt-in batteries includes. den.provides.home-manager ]; # any NixOS configuration nixos = { pkgs, ... }: { # A nixos class module, see NixOS options. # import third-party NixOS modules imports = [ inputs.disko.nixosModules.disko ]; disko.devices = { /* ... */ }; }; # any nix-darwin configuration darwin = { # import third-party Darwin modules imports = [ inputs.nix-homebrew.darwinModules.nix-homebrew ]; nix-homebrew.enableRosetta = true; }; # For all users of my-laptop homeManager.programs.vim.enable = true; }; } ``` -------------------------------- ### Bidirectional Provider Configuration (Nix) Source: https://github.com/vic/den/blob/main/docs/src/content/docs/tutorials/example.md Illustrates how hosts and users can exchange configuration using `provides`. The 'alice' aspect enables 'nh' on the 'igloo' host, while the 'igloo' aspect enables 'helix' for the 'alice' user. These are cross-providers activated during context transformation. ```nix # modules/aspects/alice.nix — user provides config TO the host den.aspects.alice = { provides.igloo = { host, ... }: { nixos.programs.nh.enable = host.name == "igloo"; }; }; # modules/aspects/igloo.nix — host provides config TO the user den.aspects.igloo = { provides.alice = { user, ... }: { homeManager.programs.helix.enable = user.name == "alice"; }; }; ``` -------------------------------- ### Organize Aspects with 'provides' Attribute Source: https://github.com/vic/den/wiki/aspects This example illustrates how to use the 'provides' attribute to create a nested structure for aspects, allowing for better organization of related configurations. The '_' alias for 'provides' is also shown. ```nix den.aspects.gaming = { description = "Games"; nixos = { }; provides = { emulation = { description = "Old is still good"; nixos = { }; }; }; }; ``` -------------------------------- ### Namespace Aspect Definition (Nix) Source: https://github.com/vic/den/blob/main/docs/src/content/docs/tutorials/example.md Shows how to define nested 'provides' within a namespace aspect. 'eg.vm._.gui' and 'eg.vm._.tui' are sub-aspects accessed using the '_. ' provider syntax, allowing for modular configuration. ```nix # modules/aspects/eg/vm.nix { eg.vm.provides = { gui.includes = [ eg.vm eg.vm-bootable._.gui eg.xfce-desktop ]; tui.includes = [ eg.vm eg.vm-bootable._.tui ]; }; } ``` -------------------------------- ### Integrate Den with existing nixosSystem configuration Source: https://github.com/vic/den/blob/main/docs/src/content/docs/guides/migrate.md Illustrates how to use `mainModule` to merge Den configurations with existing `nixosSystem` setups. This allows Den aspects to be included alongside traditional NixOS modules. ```nix let denCfg = (lib.evalModules { modules = [ (import-tree ./modules) ]; specialArgs = { inherit inputs; }; }).config; in lib.nixosSystem { modules = [ ./hardware-configuration.nix # your existing modules ./networking.nix denCfg.den.hosts.x86_64-linux.igloo.mainModule # Den modules ]; } ``` -------------------------------- ### Den Library Configuration Resolution Example (Nix) Source: https://github.com/vic/den/blob/main/docs/src/content/docs/explanation/library-vs-framework.mdx Illustrates how to obtain a Nix configuration for a specific class, like 'terranix', using Den's library. This involves resolving aspects and applying them to generate the final configuration. ```nix aspect = den.ctx.deploy { target.name = "web"; }; module = aspect.resolve { class = "terranix"; }; terranix.lib.terranixConfiguration { modules = [ module ]; }; ``` -------------------------------- ### Nix Module as a Function Example Source: https://github.com/vic/den/wiki/motivation Demonstrates how a NixOS module can be structured as a function, accepting arguments like 'pkgs' and returning NixOS settings. This is a fundamental concept for creating composable modules. ```nix # Just like any nixos module can be a function: { pkgs, ... }: { } ``` -------------------------------- ### Apply den.ctx.host for NixOS Configurations Source: https://github.com/vic/den/blob/main/docs/src/content/docs/explanation/context-system.mdx This example shows how to use the den API to apply the den.ctx.host context for creating NixOS configurations. It resolves the NixOS module and uses the NixOS API to build the system. ```nix # use den API to apply the context to data aspect = den.ctx.host { # value is `den.hosts..`. host = den.hosts.x86_64-linux.igloo; }; # use flake-aspects API to resolve nixos module nixosModule = aspect.resolve { class = "nixos"; }; # use NixOS API to build the system nixosConfigurations.igloo = lib.nixosSystem { modules = [ nixosModule ]; }; ``` -------------------------------- ### Initial Host Context Application (Nix) Source: https://github.com/vic/den/blob/main/docs/src/content/docs/explanation/context-pipeline.mdx Applies the initial context 'den.ctx.host' to a specific host configuration. This is the starting point of the NixOS/nix-Darwin pipeline for processing host definitions. ```nix den.ctx.host { host = den.hosts.x86_64-linux.igloo; } ``` -------------------------------- ### Minimal Den Host and User Configuration Source: https://github.com/vic/den/blob/main/docs/src/content/docs/tutorials/minimal.md Nix module defining a minimal Den host ('igloo') and user ('tux'). It includes the Den flake module, sets up a basic NixOS configuration for the host with a 'hello' package, and configures the user aspect. ```nix { inputs, den, ... }: { imports = [ inputs.den.flakeModule ]; den.hosts.x86_64-linux.igloo.users.tux = { }; den.aspects.igloo = { nixos = { pkgs, ... }: { environment.systemPackages = [ pkgs.hello ]; boot.loader.grub.enable = false; # TODO: remove for real hardware fileSystems."/".device = "/dev/null"; }; }; den.aspects.tux = { includes = [ den.provides.primary-user ]; }; } ``` -------------------------------- ### Setting Global Options with den.default (Nix) Source: https://github.com/vic/den/blob/main/docs/src/content/docs/explanation/context-pipeline.mdx Provides an example of using den.default for global settings like home.stateVersion and including user-defined aspects. It highlights that den.default is an alias for den.ctx.default. ```nix den.default.homeManager.home.stateVersion = "25.11"; den.default.includes = [ den._.define-user ]; ``` -------------------------------- ### Access Den Resolved Configuration Instances Source: https://github.com/vic/den/wiki/migration Explains how to access fully resolved Den configuration instances, such as `denCfg.flake.nixosConfigurations.igloo` and `denCfg.flake.homeConfigurations.tux`. These instances can be directly exposed in a flake's outputs. ```nix denCfg.flake.nixosConfigurations.igloo denCfg.flake.homeConfigurations.tux ``` -------------------------------- ### User Contributions to Host Configurations in Nix Source: https://github.com/vic/den/wiki/README Shows how user-specific configurations can contribute to host aspects. This example defines an aspect 'vic' that includes tiling window manager and primary user configurations, and also adds user-specific settings to NixOS. ```nix # modules/vic.nix { den.aspects.vic = { homeManager = { pkgs, ... }: { /* ... */ }; # User contribs to host nixos.users.users = { vic.description = "oeiuwq"; }; includes = [ den.aspects.tiling-wm den.provides.primary-user ]; }; } ``` -------------------------------- ### Extending den.ctx.hm-host context with includes Source: https://github.com/vic/den/blob/main/docs/src/content/docs/reference/ctx.mdx Shows how to extend the 'den.ctx.hm-host' context type by adding custom configurations to its 'includes'. This example specifically sets the 'backupFileExtension' for NixOS Home Manager, demonstrating module system merging capabilities. ```nix den.ctx.hm-host.includes = [ ({ host, ... }: { nixos.home-manager.backupFileExtension = "bak"; }) ]; ``` -------------------------------- ### Namespace Creation (Nix) Source: https://github.com/vic/den/blob/main/docs/src/content/docs/tutorials/example.md Illustrates how to create and import a local namespace 'eg' within a Den project. The 'true' flag makes the namespace available as a flake output. Angle brackets are enabled by default when using `__findFile`. ```nix # modules/namespace.nix { imports = [ (inputs.den.namespace "eg" true) ]; _module.args.__findFile = den.lib.__findFile; } ``` -------------------------------- ### Angle Bracket Syntax for Aspect Lookup (Nix) Source: https://github.com/vic/den/blob/main/docs/src/content/docs/tutorials/example.md Demonstrates the use of angle brackets (``) as a shorthand for aspect lookup. `` resolves to `eg.routes`, and `` resolves to `den.provides.define-user`, simplifying aspect inclusion. ```nix # modules/aspects/defaults.nix { den.default.includes = [ # resolves to eg.routes # resolves to den.provides.define-user ]; } ``` -------------------------------- ### Declare a Host with Expanded Attributes in Nix Source: https://github.com/vic/den/wiki/declarative This example demonstrates a more detailed declaration of a host, including its hostname, description, class, aspect, and nested user configurations with their own attributes. It utilizes Nix's attribute set expansion. ```nix den.hosts.x86_64-linux = { my-laptop = { hostName = "yavanna"; # default was my-laptop description = "lover of all things that grow on earth"; class = "nixos"; # default is guessed from platform aspect = "workstation"; # default was my-laptop users = { vic = { description = "Victor Borja"; userName = "vborja"; # default was vic aspect = "oeiuwq"; # default was vic class = "homeManager"; # default is homeManager }; }; }; }; ``` -------------------------------- ### define-user Battery for User Setup (Nix) Source: https://context7.com/vic/den/llms.txt Automatically sets up user accounts at both OS and Home-Manager levels. This battery can be applied globally via `den.default.includes` or to specific users using `den.aspects..includes`. ```nix { den, ... }: { # Apply to all users by including in den.default den.default.includes = [ den._.define-user ]; # For a specific user den.aspects.vic.includes = [ den._.define-user ]; } # This automatically sets: # - users.users..{name, home, isNormalUser} (NixOS) # - users.users..{name, home} (Darwin) # - home.{username, homeDirectory} (Home-Manager) ``` -------------------------------- ### Declaring Hosts and Users in Nix Source: https://context7.com/vic/den/llms.txt Defines hosts and users with a single line per machine, automatically detecting the OS class and creating appropriate configurations. Supports NixOS, nix-darwin, and standalone Home-Manager setups. ```nix # modules/hosts.nix { # NixOS host with a user den.hosts.x86_64-linux.my-laptop.users.vic = { }; # Darwin host with a user den.hosts.aarch64-darwin.macbook.users.vic = { }; # Standalone Home-Manager (no OS host) den.homes.aarch64-darwin.vic = { }; } # Build commands: # nixos-rebuild switch --flake .#my-laptop # darwin-rebuild switch --flake .#macbook # home-manager switch --flake .#vic ``` -------------------------------- ### Nix Configuration - Den Setup (modules/den.nix) Source: https://github.com/vic/den/blob/main/docs/src/content/docs/tutorials/noflake.md Nix code defining Den configurations for NixOS, hosts, and aspects. It imports Den's flake module and utilizes `nix-maid` as an alternative to Home-Manager for user configurations. ```nix { inputs, ... }: { imports = [ inputs.den.flakeModule ]; den.default.nixos = { fileSystems."/".device = "/dev/fake"; boot.loader.grub.enable = false; }; den.hosts.x86_64-linux.igloo.users.tux = { }; den.aspects.igloo = { nixos = { pkgs, ... }: { environment.systemPackages = [ pkgs.vim ]; }; }; den.aspects.tux = { nixos = { imports = [ inputs.nix-maid.nixosModules.default ]; users.users.tux = { isNormalUser = true; maid.file.home.".gitconfig".text = '' [user] name=Tux ''; }; }; }; } ``` -------------------------------- ### Nix Module and Dendritic Aspect Function Examples Source: https://github.com/vic/den/blob/main/docs/src/content/docs/motivation.mdx Demonstrates the structure of a basic NixOS module as a function and how a Dendritic aspect can be represented as a function returning multiple configuration classes (NixOS, Darwin, etc.), highlighting parametricity. ```nix # Just like any nixos module can be a function: { pkgs, ... }: { } # A function returning nixos and darwin configs { host, user }: { nixos = { pkgs, ... }: { }; darwin = { pkgs, ... }: { }; # any other nix-configuration class } ``` -------------------------------- ### Update den using Nix Flake Source: https://github.com/vic/den/blob/main/templates/default/README.md Updates the den flake to the latest version. This command ensures that you are using the most recent dependencies and features available for den. ```console nix flake update den ``` -------------------------------- ### Den Aspect Owned Configurations Example Source: https://github.com/vic/den/blob/main/docs/src/content/docs/explanation/aspects.mdx An example of 'Owned Configurations' within a Den aspect. These are direct settings defined under a class name, such as `nixos`, `darwin`, or `homeManager`. ```nix den.aspects.igloo = { nixos.networking.hostName = "igloo"; darwin.nix-homebrew.enable = true; homeManager.programs.vim.enable = true; }; ``` -------------------------------- ### Den Aspect Provides Example Source: https://github.com/vic/den/blob/main/docs/src/content/docs/explanation/aspects.mdx An example of 'Provides' in Den aspects, which defines nested sub-aspects forming a tree structure. This allows for organizing related configurations under a common parent aspect. ```nix den.aspects.gaming.provides.emulation = { nixos.programs.retroarch.enable = true; }; ``` -------------------------------- ### Running den configurations with Nix Source: https://github.com/vic/den/blob/main/README.md These commands demonstrate how to execute den configurations using Nix. The first command directly runs the den project, while the second initializes a new flake using the den template and then runs a virtual machine defined within it. These are essential for testing and deploying den-based configurations. ```console nix run github:vic/den nix flake init -t github:vic/den && nix run .#vm ``` -------------------------------- ### Nix __functor Pattern Example Source: https://github.com/vic/den/blob/main/docs/src/content/docs/explanation/aspects.mdx Demonstrates the basic __functor pattern in Nix. An attribute set with a `__functor` can be called like a function, receiving `self` (the attribute set) and an argument. This example shows a simple counter. ```nix let counter = { value = 42; __functor = self: n: self.value + n; }; in counter 8 # => 50 ``` -------------------------------- ### Instantiate Home Manager Configuration Source: https://github.com/vic/den/blob/main/docs/src/content/docs/reference/output.mdx This snippet demonstrates how a home configuration in den.homes.. is built. It specifies the package set and the main module for the home configuration. ```nix home.instantiate { pkgs = home.pkgs; modules = [ home.mainModule ]; } ``` -------------------------------- ### Initialize Den Project Source: https://github.com/vic/den/blob/main/docs/src/content/docs/tutorials/default.md Commands to create a new Den project directory and initialize it with the default template from GitHub. It also updates the 'den' flake input. ```console mkdir my-nix && cd my-nix nix flake init -t github:vic/den#default nix flake update den ``` -------------------------------- ### Defining a Basic Parametric Aspect Source: https://github.com/vic/den/blob/main/docs/src/content/docs/explanation/parametric.mdx Demonstrates the structure of a parametric aspect in Nix, showing how it propagates context to its includes. This example highlights the `__functor` for context propagation and owned configurations. ```nix foo = { # context propagation into includes __functor = self: ctx: map (f: f ctx) self.includes; # owned configs nixos.foo = 1; includes = [ # functions receiving context (ctx: { nixos.bar = 2; }) ]; } ``` -------------------------------- ### Writing to Namespaced Aspects Source: https://github.com/vic/den/wiki/namespaces This example shows how to directly write aspects into a defined namespace. By referencing the namespace (e.g., `vix.gaming.nixos`), you can assign values to specific aspects within that namespace. ```nix { vix.gaming.nixos = ...; } ``` -------------------------------- ### Automatic Aspect Creation in Nix Source: https://github.com/vic/den/blob/main/docs/src/content/docs/reference/aspects.mdx Demonstrates how den automatically creates aspects for hosts, users, and homes based on declarations. This simplifies the setup by generating aspect definitions from common patterns. ```nix den.hosts.x86_64-linux.igloo.users.tux = { }; # will create: den.aspects.igloo = parametric { }; den.aspects.tux = parametric { }; ``` -------------------------------- ### Standalone Home-Manager with OS Config Access (Nix) Source: https://github.com/vic/den/blob/main/docs/src/content/docs/guides/home-manager.mdx Enables access to the NixOS configuration from a standalone Home-Manager setup. This allows referencing OS-level settings within the Home-Manager configuration. ```nix den.homes.x86_64-linux.pingu = { instantiate = { pkgs, modules }: inputs.home-manager.lib.homeManagerConfiguration { inherit pkgs modules; extraSpecialArgs.osConfig = config.flake.nixosConfigurations.igloo.config; }; }; den.aspects.pingu.homeManager = { osConfig, ... }: { programs.emacs.enable = osConfig.programs.vim.enable; }; ``` -------------------------------- ### Applying NixOS, nix-darwin, and home-manager configurations Source: https://github.com/vic/den/blob/main/README.md These commands demonstrate how to apply system configurations using Nix. They show the respective commands for switching NixOS configurations (using a flake named 'lap'), switching nix-darwin configurations (using a flake named 'mac'), and applying home-manager configurations (using a flake named 'vic'). These are standard commands for managing Nix-based systems. ```console $ nixos-rebuild switch --flake .#lap $ darwin-rebuild switch --flake .#mac $ home-manager switch --flake .#vic ``` -------------------------------- ### Instantiate NixOS Configuration Source: https://github.com/vic/den/blob/main/docs/src/content/docs/reference/output.mdx This snippet shows how a host in den.hosts.. is built. It defines the modules to be used, including the host's main module and a default host platform setting. ```nix host.instantiate { modules = [ host.mainModule { nixpkgs.hostPlatform = lib.mkDefault host.system; } ]; } ``` -------------------------------- ### Compose Named Sub-aspects - Nix Source: https://github.com/vic/den/blob/main/docs/src/content/docs/guides/configure-aspects.mdx Organizes aspects hierarchically using the 'provides' attribute. This example defines a 'gaming' aspect with sub-aspects for 'emulation' and 'streaming', which can then be included in other aspects like 'my-pc'. ```nix den.aspects.gaming = { nixos.programs.steam.enable = true; provides.emulation.nixos.programs.retroarch.enable = true; provides.streaming = { nixos.services.sunshine.enable = true; homeManager.programs.moonlight.enable = true; }; }; den.aspects.my-pc.includes = [ den.aspects.gaming den.aspects.gaming._.emulation ]; ``` -------------------------------- ### Nix Configuration - Entry Point (default.nix) Source: https://github.com/vic/den/blob/main/docs/src/content/docs/tutorials/noflake.md The Nix code for `default.nix`, serving as the entry point for the noflake configuration. It uses `lib.evalModules` to evaluate modules and `with-inputs.nix` to resolve inputs. ```nix let outputs = inputs: (inputs.nixpkgs.lib.evalModules { modules = [ (inputs.import-tree ./modules) ]; specialArgs = { inherit inputs; inherit (inputs) self; }; }).config; in import ./with-inputs.nix outputs ``` -------------------------------- ### Conditional Config by Host/User - Nix Source: https://github.com/vic/den/blob/main/docs/src/content/docs/guides/configure-aspects.mdx Specializes configurations using aspect arguments to conditionally apply settings based on host or user. This example enables 'git' for the 'tux' user specifically. ```nix den.aspects.igloo.includes = [ den.aspects.tuxGit ]; den.aspects.tuxGit = den.lib.take.exactly ({ host, user }: if user.userName == "tux" then { homeManager.programs.git.enable = true; } else { } ); ``` -------------------------------- ### Reading Aspects from Namespaces Source: https://github.com/vic/den/wiki/namespaces This code illustrates how to read aspects from a namespace. The namespace is typically passed as an argument to the module. You can then access its aspects, for example, `vix.security`, and include them in other configurations like `den.default.includes`. ```nix # Access the namespace from module args { vix, ... }: { den.default.includes = [ vix.security ]; } ``` -------------------------------- ### Provide Community Features in Den Source: https://github.com/vic/den/blob/main/docs/src/content/docs/motivation.mdx This example illustrates how to contribute features to the community using Den's common namespace. It shows a typical structure for defining aspects, such as 'omfnix.niri.nixos', making them available for others to use. ```nix { omfnix, ... }: { omfnix.niri.nixos = ...; } ``` -------------------------------- ### Den Context Transformation to Default (Nix) Source: https://github.com/vic/den/blob/main/docs/src/content/docs/explanation/context-pipeline.mdx Illustrates how different context types (host, user, home) transform into the default context using lib.singleton. This explains how data flows into den.default via the declarative context pipeline. ```nix den.ctx.host.into.default = lib.singleton; # passes { host } den.ctx.user.into.default = lib.singleton; # passes { host, user } den.ctx.home.into.default = lib.singleton; # passes { home } ``` -------------------------------- ### Define Custom Greeting Context Type Source: https://github.com/vic/den/blob/main/docs/src/content/docs/explanation/context-system.mdx Illustrates the creation of custom context types. This example defines a 'greeting' context that can be transformed into a 'shout' context, producing both original and uppercase versions of a greeting. ```nix den.ctx.greeting._.greeting = { hello }: { funny.names = [ hello ]; }; den.ctx.greeting.into.shout = { hello }: [{ shout = lib.toUpper hello; }]; den.ctx.shout._.shout = { shout }: { funny.names = [ shout ]; }; ``` -------------------------------- ### Den Framework for Declarative System Configuration Source: https://github.com/vic/den/blob/main/docs/src/content/docs/index.mdx This example demonstrates using the Den framework within a flake-parts or lib.evalModules context. It shows how to declare hosts, users, and homes, attach configurations via aspects, and include reusable aspects or Den batteries. It covers generic configurations for all hosts, users, and homes. ```nix # use in flake-parts or any lib.evalModules where den.nixModule is imported { den, ... }: { # declare your hosts, users and homes den.x86_64-linux.hosts.igloo.users.tux = { }; # attach configurations via aspects den.igloo.nixos.networking.hostName = "warm-home"; # user aspects can configure its home and host environment den.tux.homeManager = { pkgs, ... }: { home.packages = [ pkgs.cowsay ]; }; den.tux.nixos.users.users.tux.desscription = "cute pinguin"; # include other re-usable aspects of yours or den batteries den.tux.includes = [ (den.provides.user-shell "fish") ]; # generic config for all hosts, users, homes. den.default.nixos.system.stateVersion = "25.11"; den.default.homeManager.home.stateVersion = "25.11"; den.default.includes = [ den._.inputs' ]; } ``` -------------------------------- ### Override Output Placement for Configurations Source: https://github.com/vic/den/blob/main/docs/src/content/docs/reference/output.mdx This example shows how to override the default `intoAttr` to place configurations in a custom location within the flake. This is useful for organizing configurations or when using custom output attributes. ```nix den.hosts.x86_64-linux.my-wsl = { intoAttr = "wslConfigurations"; users.vic = { }; }; ``` -------------------------------- ### Configure Static Host Options - Nix Source: https://github.com/vic/den/blob/main/docs/src/content/docs/guides/configure-aspects.mdx Sets NixOS/Darwin/HM options directly on an aspect. This example configures the 'igloo' aspect to include the 'hello' package in the system environment and enable Vim for the user. ```nix den.aspects.igloo = { nixos = { pkgs, ... }: { environment.systemPackages = [ pkgs.hello ]; }; homeManager.programs.vim.enable = true; }; ``` -------------------------------- ### Interactive REPL Exploration (Nix) Source: https://github.com/vic/den/blob/main/docs/src/content/docs/guides/debug.md Demonstrates how to load a Den flake into the Nix REPL and interactively explore its configurations. This involves using the `:lf .` command to load the flake and then accessing specific attributes like `nixosConfigurations.igloo.config.networking.hostName`. ```console $ nix repl nix-repl> :lf . nix-repl> nixosConfigurations.igloo.config.networking.hostName ``` -------------------------------- ### Standalone Home-Manager with osConfig Source: https://context7.com/vic/den/llms.txt Create standalone Home-Manager configurations that can access NixOS configuration. This allows for modular management of user environments while retaining access to system-level configurations. ```nix { den, config, inputs, ... }: { den.homes.x86_64-linux.pingu = { instantiate = { pkgs, modules }: inputs.home-manager.lib.homeManagerConfiguration { inherit pkgs modules; extraSpecialArgs.osConfig = config.flake.nixosConfigurations.igloo.config; }; }; den.aspects.pingu.homeManager = { osConfig, ... }: { # Access NixOS config from standalone HM programs.emacs.enable = osConfig.programs.vim.enable; }; } ``` -------------------------------- ### Run Den Project Tests Source: https://github.com/vic/den/blob/main/docs/src/content/docs/tutorials/bogus.md Executes the tests defined within the Den project's flake. This command is used to verify the bug reproduction setup and ensure that the tests pass. ```console nix flake check ``` -------------------------------- ### Custom Instantiation with Nixpkgs Channels (Nix) Source: https://github.com/vic/den/blob/main/docs/src/content/docs/guides/declare-hosts.mdx Demonstrates custom instantiation for hosts, allowing the use of different Nixpkgs channels per host. This is useful for managing dependencies or testing with specific Nixpkgs versions. ```nix den.hosts.x86_64-linux.stable-server = { instantiate = inputs.nixpkgs-stable.lib.nixosSystem; users.admin = { }; }; ``` -------------------------------- ### Consume Namespace from External Flake (Nix) Source: https://context7.com/vic/den/llms.txt This example demonstrates consuming a Den namespace from an external flake. It imports a namespace named 'provider' from 'inputs.other-flake' and includes 'provider.tools._.editors' in the 'den.aspects.igloo.includes' configuration. ```nix { inputs, ... }: { imports = [ (inputs.den.namespace "provider" [ true inputs.other-flake ]) ]; den.aspects.igloo.includes = [ provider.tools._.editors ]; } ``` -------------------------------- ### Include Features Affecting All Entities in Den Source: https://github.com/vic/den/blob/main/docs/src/content/docs/motivation.mdx This example shows how to include features that apply to all entities managed by Den. It uses `den.default.includes` to list features, such as unfree packages like 'vscode', ensuring they are available across the configuration. ```nix den.default.includes = [ (den._.unfree ["vscode"]) ] ``` -------------------------------- ### Den Aspect Includes Examples Source: https://github.com/vic/den/blob/main/docs/src/content/docs/explanation/aspects.mdx Demonstrates various ways to define 'Includes' for dependencies on other aspects within Den. This includes static aspects, functional includes based on context matching, and references to other aspects. ```nix den.aspects.igloo.includes = [ # an static include { nixos.programs.vim.enable = true } # function includes # # activates on both { host, user }, { host } ({ host, ... }: { nixos.time.timeZone = "UTC"; }) # activates only on { host } (den.lib.take.exactly ({ host }: { nixos.networking.hostName = host.hostName; })) # a reference to any other aspect den.aspects.tools._.editors ]; ``` -------------------------------- ### Initialize Bug Reproduction Project Source: https://github.com/vic/den/blob/main/docs/src/content/docs/tutorials/bogus.md Initializes a new project for bug reproduction using the 'bogus' template from the Den flake. It creates a directory, initializes the flake, and updates the Den dependency. ```console mkdir bogus && cd bogus nix flake init -t github:vic/den#bogus nix flake update den ```