···33description: How Den builds flake outputs from host and home declarations.
44---
5566-import { Aside } from '@astrojs/starlight/components';
66+import { Aside, Steps } from '@astrojs/starlight/components';
7788<Aside title="Source" icon="github">
99-[`modules/config.nix`](https://github.com/vic/den/blob/main/modules/config.nix) --
1010-[`modules/output.nix`](https://github.com/vic/den/blob/main/modules/output.nix)
99+[`modules/outputs/*.nix`](https://github.com/vic/den/blob/main/modules/outputs) --
1010+[`modules/outputs.nix`](https://github.com/vic/den/blob/main/modules/outputs.nix) --
1111+[`per system tests`](https://github.com/vic/den/blob/main/templates/ci/modules/features/forward-flake-level.nix)
1112</Aside>
12131314## Build pipeline
···55565657The result lands at `flake.homeConfigurations.<name>` by default.
57585858-## `output.nix` -- flake-parts compatibility
5959+## `outputs.nix` -- flake-parts compatibility
59606061When `inputs.flake-parts` is absent, Den defines its own `options.flake`
6161-option (adapted from flake-parts, MIT licensed) so that output generation
6262-works identically with or without flake-parts.
6262+option so that output generation works identically with or without flake-parts.
63636464This means Den can produce `nixosConfigurations`, `darwinConfigurations`,
6565`homeConfigurations`, and any custom output attribute regardless of
···7575};
7676```
77777878+Use `intoAttr = [ ]` to skip placing the configuration.
7979+7880## Custom instantiation
79818082Override `instantiate` to use a different builder or add `specialArgs`:
···8486 instantiate = inputs.nixos-unstable.lib.nixosSystem;
8587};
8688```
8989+9090+## Flake outputs like `packages`, `checks`, etc.
9191+9292+Den aspects can directly contribute to `packages` and similar flake outputs.
9393+9494+The following example are for `packages` but same applies for `checks`, `devShells`,
9595+`legacyPackages` and other per system outputs.
9696+9797+<Steps>
9898+9999+1. Define `flake.packages` output.
100100+101101+ This is only needed if you don't use flake-parts and will have more than one package,
102102+ because the Nix module system needs to know how to merge both output definitions:
103103+104104+ ```nix
105105+ # modules/outputs.nix
106106+ { inputs, ... }:
107107+ {
108108+ imports = [ inputs.den.flakeOutputs.packages ];
109109+ }
110110+ ```
111111+112112+2. Allow aspects to produce `packages`.
113113+114114+ ```nix
115115+ # ANY Host or User aspect can produce outputs:
116116+ den.ctx.flake-system.into.host = { system }:
117117+ map (host: { inherit host; })
118118+ (lib.attrValues den.hosts.${system});
119119+120120+ # ONLY foo aspect can produce packages:
121121+ den.ctx.flake-packages.includes = [ den.aspects.foo ];
122122+ ```
123123+124124+3. Use the `packages` class on your aspects:
125125+126126+ ```nix
127127+ den.aspects.foo = {
128128+ packages = { pkgs, ... }: { inherit (pkgs) hello; };
129129+ };
130130+ ```
131131+132132+</Steps>
133133+134134+See [`forward-flake-level.nix`](https://github.com/vic/den/blob/main/templates/ci/modules/features/forward-flake-level.nix) for all examples.