Aspects & Functors
What is an aspect?
Section titled “What is an aspect?”An aspect is a composable unit of configuration that bundles modules
for one or more Nix classes (nixos, darwin, homeManager, or custom)
in a single attrset. Aspects declare what behavior applies — one
concern, all platforms. They compose via includes (DAG edges) and
provides (named sub-aspects).
den.aspects.gaming = { host, user }: { nixos = { pkgs, ... }: { programs.steam.enable = true; }; homeManager = { pkgs, ... }: { programs.mangohud.enable = true; }; includes = [ den.aspects.performance ];};The __functor Pattern
Section titled “The __functor Pattern”Any Nix attrset with __functor can be called as a function:
let counter = { value = 42; __functor = self: n: self.value + n; };in counter 8 # => 50The __functor receives self (the attrset itself) and returns a function.
Aspects as Functors
Section titled “Aspects as Functors”Every aspect in Den has a default __functor that inspects context
parameters to decide what to produce. Bare attrsets and functions work
directly — den.lib.parametric is no longer needed:
# Bare functions work directly — no wrapper required{ nixos.foo = 1; includes = [ ({ host }: { nixos.networking.hostName = host.hostName; }) ({ user }: { homeManager.home.username = user.userName; }) ];}Aspect Structure
Section titled “Aspect Structure”Aspects have three kinds of attributes:
Owned Configurations
Section titled “Owned Configurations”Direct settings per Nix class:
den.aspects.igloo = { nixos.networking.hostName = "igloo"; darwin.nix-homebrew.enable = true; homeManager.programs.vim.enable = true;};Includes
Section titled “Includes”A list forming a dependency graph:
den.aspects.igloo.includes = [ # Static: applied unconditionally { nixos.programs.vim.enable = true; }
# Parametric: applied when context matches argument shape ({ host, ... }: { nixos.time.timeZone = "UTC"; })
# Reference to another aspect den.aspects.tools];Provides
Section titled “Provides”Named sub-aspects scoped to this aspect, accessible via den.aspects.igloo._.name
or den.aspects.igloo.provides.name:
den.aspects.igloo.provides.gpu = { host, ... }: lib.optionalAttrs (host ? gpu) { nixos.hardware.nvidia.enable = true; };Resolution
Section titled “Resolution”Aspects are resolved for a specific class using the den.lib.aspects.resolve API.
module = den.lib.aspects.resolve "nixos" den.aspects.igloo;Resolution collects all nixos attrs from owned configs, walks includes
recursively, applies parametric dispatch, deduplicates, and produces a
single deferredModule containing all NixOS configuration.
See also
Section titled “See also”- Configure Aspects — practical guide to owned configs, includes, provides
- Parametric Aspects — context-aware dispatch via argument introspection
- Resolution Pipeline — how aspects feed into the full pipeline
- den.aspects reference — full option documentation