NixOS + Home Manager configuration built on the den framework using the Dendritic pattern. The same aspects build full NixOS hosts and standalone Home Manager setups for non-NixOS machines.
Every .nix file under modules/ is auto-imported as a flake-parts
module (outputs = import-tree ./modules in flake.nix). There is
no central import list — drop a file in the right directory and it is picked up.
import-tree only imports .nix files and
skips any path containing a /_ segment, so prefixing a file or directory with
_ archives/disables a module without deleting it.
flake.nixis auto-generated byflake-file. Do not edit it by hand. Inputs are declared inline in the module that uses them (viaflake-file.inputs) and regenerated withnix run .#write-flake.
New
.nixfiles must be tracked by git before Nix will see them — flakes only read files known to the working tree. After adding a module, rungit add <path>beforenix run .#write-flake/nixos-rebuildor the new module (and anyflake-file.inputsit declares) will be silently ignored.
| Term | What it is |
|---|---|
| aspect | A composable unit of config: den.aspects.<name>, bundling nixos / homeManager modules + includes + provides. The core building block. |
| battery | A reusable aspect provider shipped by den under den.batteries.* (e.g. define-user, hostname, user-shell). |
| class | A module evaluation domain: nixos, homeManager, darwin, ... |
| includes | List of aspect refs / inline modules an aspect depends on (forms a DAG). |
| provides | Named sub-aspects for host↔user mutual config (to-users, to-hosts). |
| host / user | Entities registered in den.hosts.<system>.<name>.users.<user>. |
| home | A standalone Home Manager entity (no NixOS), registered in den.homes.<system>."<user>@<host>". |
An aspect can be split across many files — every file that writes
den.aspects.zephyrus.* merges into the same zephyrus aspect.
modules/
├── default.nix # den root: defaults, schemas, host registry
├── flake/ # flake-parts plumbing (dendritic, devshell, formatter, nixpkgs, templates)
├── profiles/ # layered bundles of features (base ⊂ headless ⊂ desktop)
├── features/ # one aspect per concern (git, mango, zsh, sops, ...)
│ └── hardware/ # driver/boot aspects (nvidia, grub, kvm-amd, ...)
├── configurations/ # per-host / per-home config (zephyrus/, zephyrus-wsl/, QIN-120868/)
├── users/ # per-user aspects (haru02w.nix, joaomillane.nix)
├── packages/ # flake packages built per-system (nixvim neovim)
└── tools/ # extra flake packages/apps (nh host builders, vm runner)
templates/ # `nix flake init -t` project scaffolds (c, cpp, go, rust, python, ...)
Defaults, entity schemas and the host registry live in
modules/default.nix:
den = {
default.includes = [ den.batteries.define-user den.batteries.hostname den.batteries.inputs' den.batteries.self' ];
schema.user = { classes = lib.mkDefault [ "homeManager" ]; includes = [ den.batteries.mutual-provider ]; };
hosts = {
x86_64-linux.zephyrus.users.haru02w = { };
x86_64-linux."zephyrus-wsl".users.haru02w = { };
};
homes.x86_64-linux."joaomillane@QIN-120868" = { };
};The inputs' and self' batteries pass system-specialised inputs'.<input> and
self'.packages.<pkg> into every nixos / homeManager module.
-
Create
modules/configurations/<host>/configuration.nixdeclaring an aspect named after the host:{ den, ... }: { den.aspects.<host> = { includes = [ den.aspects.desktop # pick a profile ]; nixos = { }; provides.to-users.homeManager = _: { }; }; }
-
Add hardware / disk files in the same directory — they all merge into the same host aspect (see
zephyrus/):hardware-configuration.nix,disko.nix,<host>-hardware.nix. Each writesden.aspects.<host>.nixosand/orden.aspects.<host>.includes. -
Register the host + its user(s) in
modules/default.nix:den.hosts.x86_64-linux.<host>.users.<user> = { };
The host name binds to the aspect of the same name automatically.
class(nixos/darwin) is auto-detected from<system>.
Build it: nix run .#<host> -- switch (see Build & test).
For a NixOS-WSL host, skip the disko / boot-loader / display-server pieces and
build on headless instead of desktop (see
zephyrus-wsl/ for a working example):
{ inputs, den, lib, ... }:
{
flake-file.inputs.nixos-wsl = {
url = "github:nix-community/NixOS-WSL";
inputs.nixpkgs.follows = "nixpkgs";
};
den.aspects."<host>" = {
includes = [ den.aspects.headless ];
nixos = _: {
imports = [ inputs.nixos-wsl.nixosModules.default ];
wsl = { enable = true; defaultUser = "<user>"; };
# WSL manages networking / no sshd needed
networking.networkmanager.enable = lib.mkForce false;
services.openssh.enable = lib.mkForce false;
};
provides.to-users.homeManager = _: { };
};
}Switch via sudo nixos-rebuild switch --flake .#<host> — nh currently trips
over nix config show under sudo in this repo.
-
Create
modules/users/<user>.nix:{ den, ... }: { den.aspects.<user> = { includes = [ den.batteries.primary-user # wheel + networkmanager groups den.batteries.host-aspects # inherit host's homeManager config (den.batteries.user-shell "zsh") # login shell at OS + HM level ]; homeManager = { pkgs, ... }: { home.packages = with pkgs; [ neovim ]; }; provides.to-hosts.nixos = _: { }; }; }
-
Attach the user to a host in
modules/default.nix:den.hosts.<system>.<host>.users.<user> = { };
Users default to classes = [ "homeManager" ] (set in den.schema.user).
For a machine that runs Home Manager on top of another distro (see
QIN-120868/ for a working example):
-
Create a user aspect in
modules/users/<user>.nix. It only needshomeManagerconfig, and it pulls in a profile directly since there is no host aspect to inherit from:{ den, ... }: { den.aspects.<user> = { includes = [ den.aspects.headless ]; homeManager = { }; }; }
-
Put machine-specific bits in an aspect named
"<user>@<host>", inmodules/configurations/<host>/home.nix:{ den.aspects."<user>@<host>".homeManager = { config, pkgs, ... }: { targets.genericLinux.enable = true; nix.package = pkgs.nix; nix.settings.trusted-users = [ config.home.username ]; }; }
-
Register it in
modules/default.nix:den.homes.x86_64-linux."<user>@<host>" = { };
Only the homeManager half of each included aspect applies; nixos blocks are
ignored. Build it with nix run .#<user>-<host> -- switch (the @ becomes -
in the package name) or home-manager switch --flake .#<user>@<host>.
Profiles are just aspects that bundle features via includes. They live in
modules/profiles/ and layer on each other
(base ⊂ headless ⊂ desktop).
# modules/profiles/<profile>.nix
{ den, ... }:
{
den.aspects.<profile> = {
includes = [
den.aspects.headless # build on a lower layer
den.aspects.<feature> # pull in features
];
nixos = { pkgs, ... }: { /* profile-wide system config */ };
homeManager = { pkgs, ... }: { /* profile-wide user config */ };
};
}Use a profile by including it from a host (or another profile).
A feature is one aspect for one concern, in modules/features/.
Put it in hardware/ if it is a driver/boot concern.
# modules/features/<feature>.nix
{ den, ... }:
{
den.aspects.<feature> = {
nixos = { pkgs, ... }: { /* system-level config */ };
homeManager = { pkgs, ... }: { /* user-level config */ };
};
}If the feature needs a new flake input, declare it inline so flake-file
can pick it up (don't touch flake.nix):
{ inputs, ... }:
{
flake-file.inputs.<input> = {
url = "github:owner/repo";
inputs.nixpkgs.follows = "nixpkgs";
};
den.aspects.<feature>.nixos = {
imports = [ inputs.<input>.nixosModules.default ];
# ...
};
}Then add den.aspects.<feature> to a profile's (or host's) includes.
After editing inputs, run nix run .#write-flake to regenerate flake.nix.
Just write into home.packages or environment.systemPackages from any aspect:
den.aspects.<name>.homeManager = { pkgs, ... }: {
home.packages = with pkgs; [ btop ripgrep ];
};
# or system-wide:
den.aspects.<name>.nixos = { pkgs, ... }: {
environment.systemPackages = with pkgs; [ git ];
};allowUnfree = true is already set globally in
modules/flake/nixpkgs.nix, so unfree packages
(discord, vesktop, ...) just go straight in the package list — see
desktop.nix. For insecure packages, or
if you later tighten allowUnfree, reach for the batteries:
includes = [
(den.batteries.unfree [ "discord" ])
(den.batteries.insecure [ "openssl-1.1.1w" ])
];Packages built per-system go in modules/packages/ or
modules/tools/ via perSystem.packages:
# modules/tools/<name>.nix
{
perSystem = { pkgs, ... }: {
packages.<name> = pkgs.writeShellApplication {
name = "<name>";
text = "echo hello";
};
};
}The nixvim Neovim package shows the modular pattern: a
perSystem option (nixvim.module) is merged across every plugin file, then fed
to makeNixvimWithModule in default.nix.
Add a plugin by dropping a file in modules/packages/nixvim/plugins/ that writes
perSystem.nixvim.module.<...> (e.g. plugins.<name>, keymaps).
The nixvim feature installs that package and exposes a nixvim.package option
on both the NixOS and Home Manager sides, so a host can install a variant built
with .extend. Under NixOS, Home Manager follows the host's choice.
Current flake packages: nixvim, vm, zephyrus / zephyrus-wsl /
joaomillane-QIN-120868 (nh builders, one per host or home),
write-flake / write-inputs / write-lock (flake-file generators).
modules/flake/templates.nix auto-discovers
every directory under templates/ and exposes it as a flake
template. Scaffold a new project in the current directory with:
nix flake init -t github:haru02w/dotfiles#rust # or c, cpp, cpp-xmake, devshell, go, pythonEach template ships a flake.nix devshell + .envrc (direnv). Add a template
by dropping a directory under templates/ — it is picked up automatically;
give it a friendlier blurb via the descriptions map in templates.nix.
Secrets are managed with sops-nix (age key
at ~/.config/sops/age/keys.txt). The sops feature
(modules/features/sops.nix) wires
secrets/secrets.yaml into both NixOS and Home Manager.
Before a new machine can decrypt secrets, it needs an age key derived from an
SSH key that is already authorized in .sops.yaml. The SSH key
lives in Bitwarden (as an SSH Key item type) and is pulled with
rbw — it never needs to touch ~/.ssh.
-
Configure
rbw(the config isn't applied yet on a fresh machine), log in, sync, and derive the age key straight from the private key in Bitwarden — no file on disk:mkdir -p ~/.config/sops/age nix-shell -p rbw ssh-to-age pinentry-curses --run ' rbw config set base_url https://bw.haru02w.eu.org rbw config set email joaovictormillane@gmail.com rbw config set pinentry pinentry-curses rbw login && rbw sync && rbw get --field private_key "haru02w ssh key" | ssh-to-age -private-key > ~/.config/sops/age/keys.txt'
-
Verify decryption works by opening the secrets file:
nix-shell -p sops --run "sops secrets/secrets.yaml" -
Before the first
switch, seed the key at the target user's home so sops-nix can decrypt secrets (neededForUsers = true) during activation — the target home directory won't exist yet, so create it as root:sudo mkdir -p /home/<user>/.config/sops/age sudo cp ~/.config/sops/age/keys.txt /home/<user>/.config/sops/age/keys.txt
After the first switch creates the user, fix ownership:
sudo chown -R <user>:users /home/<user>/.config. If home-manager tries to activate while another user still holds the same UID (common on WSL where you start asnixosUID 1000), restart the user manager once so it reloads as the new user:sudo systemctl restart user@1000.service.
Once the config is applied, the same SSH key is served for ssh/git by
rbw's built-in SSH agent (SSH_AUTH_SOCK →
$XDG_RUNTIME_DIR/rbw/ssh-agent-socket) — verify with rbw unlock && ssh-add -l.
See the sops-nix repository for more.
Once bootstrapped, edit secrets from the dev shell:
nix develop # provides sops, age, ssh-to-age
sops secrets/secrets.yaml# build / switch a host (uses nh under the hood)
nix run .#zephyrus # default action: build
nix run .#zephyrus -- switch # apply
# build / switch a standalone home (nh home under the hood)
nix run .#joaomillane-QIN-120868 -- switch
# spin up a throwaway VM of the host to test changes without rebooting
nix run .#vm
# regenerate flake.nix / flake.lock after changing inputs
nix run .#write-flake
nix flake update den # bump the den framework
# format
nix fmt # nixfmt via treefmt-nixA dev shell with sops, age, ssh-to-age, claude-code, opencode,
nodejs, nh is available via nix develop (auto-loaded by
direnv). It also points nh at the repo root (NH_OS_FLAKE /
NH_HOME_FLAKE) so nh os switch / nh home switch work without --flake.
CI (.github/workflows/test.yml) runs
nix flake check on every push and pull request.
made with ❤️ by Haru02w