Migrate to Den
Strategy
Section titled “Strategy”Migration to Den is incremental. You do not need to rewrite everything at once.
-
Add Den as Input
Add Den to your flake and import the flake module:
{inputs.den.url = "github:vic/den";inputs.import-tree.url = "github:vic/import-tree";outputs = inputs: inputs.flake-parts.lib.mkFlake { inherit inputs; }(inputs.import-tree ./modules);}modules/den.nix { inputs, ... }: {imports = [ inputs.den.flakeModule ];} -
Declare Hosts
Move your host declarations into
den.hosts:{den.hosts.x86_64-linux.laptop.users.alice = { };} -
Import Existing Modules
Use
den.provides.import-treeto load your existing non-dendritic modules:modules/legacy.nix { den, ... }: {den.ctx.host.includes = [(den.provides.import-tree._.host ./hosts)];den.ctx.user.includes = [(den.provides.import-tree._.user ./users)];}With this directory structure:
hosts/laptop/_nixos/hardware.nixnetworking.nix_homeManager/shell.nixusers/alice/_homeManager/git.nix_nixos/groups.nixFiles under
_nixos/are imported as NixOS modules,_homeManager/as Home Manager modules, etc. This requiresinputs.import-tree. -
Extract Aspects
Gradually extract features from your legacy modules into Den aspects:
modules/dev-tools.nix {den.aspects.dev-tools = {nixos = { pkgs, ... }: {environment.systemPackages = with pkgs; [ git vim tmux ];};homeManager.programs.git.enable = true;};}modules/laptop.nix { den, ... }: {den.aspects.laptop.includes = [ den.aspects.dev-tools ];} -
Remove Legacy
As aspects replace legacy modules, remove the corresponding files from
hosts/andusers/. Eventually removeden.provides.import-treeusage.
- Start with one host. Migrate a single machine first to learn the pattern.
- Keep legacy working.
import-treeloads your existing files alongside Den aspects — they coexist without conflicts. - Use batteries. Replace manual user/shell/HM setup with
den.provides.*. - Test with VM. Use
nix run .#vmto validate changes before applying to hardware.