Migration Guide
This chapter provides some guidance on how to incrementally adopt Den for cases where starting from scratch might be not possible.
Your migration path might vary depending on your current tech choices.
My recommendation is to first read all of the documentation. Get familiar with Den concepts and then try some of the templates to play with them. Once you feel comfortable, try integrating the very minimal at a time. start by adding an empty den-managed host to your configs, or using very simple den modules.
For example if you are not using flakes, start by reading our templates/noflake code to get an idea on how to evaluate Den config by yourself.
If you already have adopted flake-parts, see templates/default.
Minimal dependencies
Add the following dependencies to your flake or npins:
inputs = {
den.url = "github:vic/den";
flake-aspects.url = "github:vic/flake-aspects";
import-tree.url = "github:vic/import-tree";
}
Den uses flake-aspects to define and resolve modules, and
if you include inputs.den.flakeModule it depends on import-tree, otherwise you might want to import from den's modules/ by yourself.
Den does not depend on flakes nor flake-parts but can be used with them or any other flake-like convenience library.
Moving from existing flake-parts dendritic setup
The easiest migration path is for people already using flake-parts flake.modules or already using flake-aspects.
A flake-parts dendritic module like:
{
flake.modules.nixos.desktop = ...;
flake.modules.homeManager.games = ...;
}
become
{
den.aspects.desktop.nixos = ...;
den.aspects.games.homeManager = ...;
}
Of course you can also create aspects that import any existing module you have. You do not need to convert all of them into den-aspects for using them.
{ inputs, ... }:
{
den.aspects.desktop.nixos.imports = [
# imports the flake exposed module directly
inputs.self.modules.nixos.desktop
# just like any other nixos module, eg: disko, etc.
];
}
Using den on non dendritic flakes
It is possible to use den and mix it with your existing nixosConfiguration by using the <host>.mainModule nixos module.
Suppose you have a ./modules/igloo.nix host like:
{ den, ... }:
{
den.hosts.x86_64-linux.igloo.users.tux = { };
den.aspects.igloo = {
nixos = ...;
includes = [ den.provides.home-manager ];
};
den.aspects.tux = {
homeManager = ...;
};
}
You can use the igloo nixos module by accessing: config.den.hosts.x86_64-linux.igloo.mainModule, and mix it with any other existing module of yours:
let
denCfg = (lib.evalModules {
modules = [ (import-tree ./modules) ];
specialArgs = { inherit inputs; };
}).config;
in lib.nixosSystem {
modules = [
# all your current modules here
denCfg.den.hosts.x86_64-linux.igloo.mainModule
];
}
Using den resolved configuration instances
Of course you can also access denCfg.flake.nixosConfigurations.igloo and denCfg.flake.homeConfigurations.tux.
These are complete instances and can be exposed directly as part of your current flake outputs.