Library vs Framework
Den as a Library
Section titled “Den as a Library”Den’s core (/default.nix) is domain-agnostic. It provides:
| Function | Purpose |
|---|---|
parametric | (deprecated) Context dispatch now happens automatically |
parametric.atLeast | (deprecated) Use bare functions — dispatch is automatic |
parametric.exactly | (deprecated) Use bare functions — dispatch is automatic |
parametric.fixedTo | Apply an aspect with a fixed context |
parametric.expands | Extend context before dispatch |
canTake | Check if a function accepts given arguments |
take.atLeast / take.exactly | (deprecated) Dispatch is now handled by the pipeline |
owned | Extract only owned configs (no includes, no functor) |
__findFile | Angle bracket resolution for deep aspect paths |
aspects | Den aspects API (resolve, types) |
These primitives compose into context transformation pipelines for any domain.
Using Den for Non-OS Domains
Section titled “Using Den for Non-OS Domains”Nothing about den.lib assumes NixOS, Darwin, or Home Manager. You can build
context pipelines for any Nix module system:
# see den-as-lib.nix CI test for working example
# Define aspects for a custom domain# den.lib.parametric is deprecated — bare attrsets work directly:den.aspects = { web-server = { terranix.resource.aws_instance.web = { ami = "..."; }; includes = [ # configures using the terranix Nix class ({ env, ... }: { terranix.resource.aws_instance.web.tags.Env = env; }) ]; };};
# Resolve for your custom classaspect = den.aspects.web-server { env = "production"; };module = den.lib.aspects.resolve "terranix" [] aspect;Den as a Framework
Section titled “Den as a Framework”On top of the library, Den provides modules/ which implement:
- Schema types (
den.hosts,den.homes) for declaring NixOS/Darwin/HM entities - Aspects & Policies (
den.aspects,den.policies) for the resolution pipeline - Batteries (
den.provides.*) for common OS configuration patterns - Output generation (
modules/config.nix) instantiating configurations into flake outputs
The framework is entirely optional. You can use den.lib directly without
any of the den.hosts/den.aspects machinery.
flowchart TD
subgraph "Den Library (domain-agnostic)"
parametric["parametric dispatch"]
canTake["canTake / take"]
aspects["aspects API"]
end
subgraph "Den Framework (OS-specific)"
schema["den.hosts / den.homes"]
ctx["den.schema + den.policies"]
batteries["den.provides"]
output["flake output generation"]
end
parametric --> ctx
canTake --> parametric
aspects --> parametric
schema --> ctx
batteries --> ctx
ctx --> output
When to Use What
Section titled “When to Use What”- Library only: You have a custom Nix module system (Terranix, NixVim, system-manager) and want parametric aspect dispatch without Den’s host/user/home framework.
- Framework: You configure NixOS/Darwin/Home Manager hosts and want the full pipeline with batteries, schema types, and automatic output generation.
- Both: Use the framework for OS configs and the library for additional domains within the same flake.