···2727 readFromAspects = lib.getAttrFromPath path config.den.aspects;
28282929 headIsDenful = lib.hasAttrByPath [ "ful" head ] config.den;
3030- readFromDenful = lib.getAttrFromPath tail config.den.ful;
3030+ denfulTail = if lib.head tail == "provides" then lib.tail tail else tail;
3131+ readFromDenful = lib.getAttrFromPath ([ head ] ++ denfulTail) config.den.ful;
31323233 found =
3334 if headIsDen then
+35
templates/default/README.md
···11+# Getting Started Guide
22+33+Steps you can follow after cloning this template:
44+55+- Be sure to read the [den documentation](https://vic.github.io/den)
66+77+- Update den input.
88+99+```console
1010+nix flake update den
1111+```
1212+1313+- Run checks to test everything works.
1414+1515+```console
1616+nix flake check
1717+```
1818+1919+- Read [modules/den.nix](modules/den.nix) where hosts and homes definitions are for this example.
2020+2121+- Read [modules/namespace.nix](modules/namespace.nix) where a new `eg` (an example) aspects namespace is created.
2222+2323+- Read [modules/aspects/igloo.nix](modules/aspects/igloo.nix) where the `igloo` host is configured.
2424+2525+- Read [modules/aspects/alice.nix](modules/aspects/alice.nix) where the `alice` user is configured.
2626+2727+- Run the VM.
2828+2929+```console
3030+nix run .#vm
3131+```
3232+3333+- Edit and run VM loop.
3434+3535+Feel free to add more aspects, organize things to your liking.
+29
templates/default/modules/aspects/alice.nix
···11+{ den, eg, ... }:
22+{
33+ den.aspects.alice = {
44+ # You can include other aspects, in this case some
55+ # den included batteries that provide common configs.
66+ includes = [
77+ eg.autologin
88+ den.provides.primary-user # alice is admin always.
99+ (den.provides.user-shell "fish") # default user shell
1010+ ];
1111+1212+ # Alice configures NixOS hosts it lives on.
1313+ nixos =
1414+ { pkgs, ... }:
1515+ {
1616+ users.users.alice = {
1717+ description = "Alice Cooper";
1818+ packages = [ pkgs.vim ];
1919+ };
2020+ };
2121+2222+ # Alice home-manager.
2323+ homeManager =
2424+ { pkgs, ... }:
2525+ {
2626+ home.packages = [ pkgs.htop ];
2727+ };
2828+ };
2929+}
+44
templates/default/modules/aspects/defaults.nix
···11+{
22+ config,
33+ # deadnix: skip # enable <den/brackets> syntax for demo.
44+ __findFile ? __findFile,
55+ den,
66+ ...
77+}:
88+{
99+ # Lets also configure some defaults using aspects.
1010+ # These are global static settings.
1111+ den.default = {
1212+ darwin.system.stateVersion = 6;
1313+ nixos.system.stateVersion = "25.05";
1414+ homeManager.home.stateVersion = "25.05";
1515+ };
1616+1717+ # These are functions that produce configs
1818+ den.default.includes = [
1919+ # Enable home-manager on all hosts.
2020+ <den/home-manager>
2121+2222+ # Automatically create the user on host.
2323+ <den/define-user>
2424+2525+ # Disable booting when running on CI on all NixOS hosts.
2626+ (if config ? _module.args.CI then <eg/ci-no-boot> else { })
2727+2828+ # NOTE: be cautious when adding fully parametric functions to defaults.
2929+ # defaults are included on EVERY host/user/home, and IF you are not careful
3030+ # you could be duplicating config values. For example:
3131+ #
3232+ # # This will append 42 into foo option for the {host} and for EVERY {host,user}
3333+ # ({ host, ... }: { nixos.foo = [ 42 ]; }) # DO-NOT-DO-THIS.
3434+ #
3535+ # # Instead try to be explicit if a function is intended for ONLY { host }.
3636+ (den.lib.take.exactly (
3737+ { host }:
3838+ {
3939+ nixos.networking.hostName = host.hostName;
4040+ }
4141+ ))
4242+4343+ ];
4444+}
···11+{
22+ # autologin is context-aware, parametric aspect.
33+ # it applies only if the context has at least { user }
44+ # meaning that has access to user data
55+ eg.autologin =
66+ { user, ... }:
77+ {
88+ nixos =
99+ { config, lib, ... }:
1010+ lib.mkIf config.services.displayManager.enable {
1111+ services.displayManager.autoLogin.enable = true;
1212+ services.displayManager.autoLogin.user = user.userName;
1313+ };
1414+ };
1515+}
···11+{ eg, ... }:
22+{
33+ den.aspects.igloo = {
44+ # igloo host provides some home-manager defaults to its users.
55+ homeManager.programs.direnv.enable = true;
66+77+ # NixOS configuration for igloo.
88+ nixos =
99+ { pkgs, ... }:
1010+ {
1111+ environment.systemPackages = [ pkgs.hello ];
1212+ };
1313+1414+ # Include aspects from the eg namespace
1515+ includes = [
1616+ eg.vm-bootable
1717+ eg.xfce-desktop
1818+ ];
1919+ };
2020+}
+1-158
templates/default/modules/den.nix
···11-# The best practice is to split this file into several modules,
22-# creating a directory structure inside `modules/` that makes sense to you.
33-# See: https://vic.github.io/dendrix/Dendritic.html#no-file-organization-restrictions
44-{ den, config, ... }:
51{
66-77- # First, lets define a NixOS, a nix-darwin and standalone home-manager.
88- # Feel free to remove, rename or add any other definition.
99- # NOTE: for nix-darwin/home-manager to work we added dependencies at dendritic.nix.
1010-1111- # both hosts `igloo` and `apple` have a single user in this setup.
1212- # since user aspect `alice` is the same, they share home configurations.
132 den.hosts.x86_64-linux.igloo.users.alice = { };
143 den.hosts.aarch64-darwin.apple.users.alice = { };
1515-1616- # an standalone home-manager configuration sharing `alice` aspect.
1717- # den.homes.aarch64-darwin.alice = { };
1818-1919- # Now, lets create some aspects and later include them in our host and user aspects.
2020- #
2121- # Aspects can be defined on let-bindings, or be part of `den.aspects` tree.
2222- # Use let bindings for SMALL one-shot aspects, and an aspect tree for more
2323- # complex and re-usable ones.
2424-2525- # We define this one inside the `common.provides` aspect tree.
2626- # Please organize your aspects with names that make sense to you
2727- # and on their own directories and modules.
2828- den.aspects.common.provides = {
2929-3030- # xfce-desktop is a non-parametric aspect. it does not uses context
3131- # for how to behave, it must be included explicitly on a host.
3232- xfce-desktop.nixos =
3333- { lib, ... }:
3434- {
3535- # https://gist.github.com/nat-418/1101881371c9a7b419ba5f944a7118b0
3636- services.xserver = {
3737- enable = true;
3838- desktopManager = {
3939- xterm.enable = false;
4040- xfce.enable = true;
4141- };
4242- };
4343-4444- services.displayManager = {
4545- defaultSession = lib.mkDefault "xfce";
4646- enable = true;
4747- };
4848- };
4949-5050- # autologin is context-aware, parametric aspect.
5151- # it applies only if the context has at least { user }
5252- # meaning that has access to user data
5353- autologin =
5454- { user, ... }:
5555- {
5656- nixos =
5757- { config, lib, ... }:
5858- lib.mkIf config.services.displayManager.enable {
5959- services.displayManager.autoLogin.enable = true;
6060- services.displayManager.autoLogin.user = user.userName;
6161- };
6262- };
6363-6464- # This one can be included on a host to make USB/VM installers.
6565- vm-bootable =
6666- { ... }:
6767- {
6868- nixos =
6969- { modulesPath, ... }:
7070- {
7171- imports = [ (modulesPath + "/installer/cd-dvd/installation-cd-graphical-base.nix") ];
7272- };
7373- };
7474- };
7575-7676- den.aspects.igloo.includes = [
7777- den.aspects.common._.vm-bootable
7878- den.aspects.common._.xfce-desktop
7979- ];
8080-8181- # NixOS configuration for igloo.
8282- den.aspects.igloo.nixos =
8383- { pkgs, ... }:
8484- {
8585- environment.systemPackages = [ pkgs.hello ];
8686- };
8787-8888- # igloo host provides some home-manager defaults to its users.
8989- den.aspects.igloo.homeManager.programs.direnv.enable = true;
9090-9191- den.aspects.alice = {
9292- # You can include other aspects, in this case some
9393- # den included batteries that provide common configs.
9494- includes = [
9595- den.aspects.common._.autologin
9696- den.provides.primary-user # alice is admin always.
9797- (den.provides.user-shell "fish") # default user shell
9898- ];
9999-100100- # Alice configures NixOS hosts it lives on.
101101- nixos =
102102- { pkgs, ... }:
103103- {
104104- users.users.alice = {
105105- description = "Alice Cooper";
106106- packages = [ pkgs.vim ];
107107- };
108108- };
109109-110110- # Alice home-manager.
111111- homeManager =
112112- { pkgs, ... }:
113113- {
114114- home.packages = [ pkgs.htop ];
115115- };
116116- };
117117-118118- # Lets also configure some defaults using aspects.
119119- # These are global static settings.
120120- den.default = {
121121- darwin.system.stateVersion = 6;
122122- nixos.system.stateVersion = "25.05";
123123- homeManager.home.stateVersion = "25.05";
124124- };
125125-126126- # These are functions that produce configs
127127- den.default.includes = [
128128- # Enable home-manager on all hosts.
129129- den.provides.home-manager
130130-131131- # Automatically create the user on host.
132132- den.provides.define-user
133133-134134- # Disable booting when running on CI on all NixOS hosts.
135135- (if config ? _module.args.CI then den.aspects.ci-no-boot else { })
136136-137137- # NOTE: be cautious when adding fully parametric functions to defaults.
138138- # defaults are included on EVERY host/user/home, and IF you are not careful
139139- # you could be duplicating config values. For example:
140140- #
141141- # # This will append 42 into foo option for the {host} and for EVERY {host,user}
142142- # ({ host, ... }: { nixos.foo = [ 42 ]; }) # DO-NOT-DO-THIS.
143143- #
144144- # # Instead try to be explicit if a function is intended for ONLY { host }.
145145- (den.lib.take.exactly (
146146- { host }:
147147- {
148148- nixos.networking.hostName = host.hostName;
149149- }
150150- ))
151151-152152- ];
153153-154154- den.aspects.ci-no-boot = {
155155- description = "Disables booting during CI";
156156- nixos = {
157157- boot.loader.grub.enable = false;
158158- fileSystems."/".device = "/dev/null";
159159- };
160160- };
161161-44+ den.homes.x86_64-linux.alice = { };
1625}
+4-42
templates/default/modules/dendritic.nix
···11-# This repo was generated with github:vic/flake-file#dendritic template.
22-# Run `nix run .#write-flake` after changing any input.
33-#
44-# Inputs can be placed in any module, the best practice is to have them
55-# as close as possible to their actual usage.
66-# See: https://vic.github.io/dendrix/Dendritic.html#minimal-and-focused-flakenix
77-#
88-# For our template, we enable home-manager and nix-darwin by default, but
99-# you are free to remove them if not being used by you.
1010-{ inputs, lib, ... }:
11+{ inputs, ... }:
112{
1212-1313- # DO-NOT-REMOVE this line unless you know what you are doing.
1414- imports = [ (inputs.flake-file.flakeModules.dendritic or { }) ];
1515-1616- flake-file.inputs = {
1717-1818- # DO-NOT-REMOVE this line unless you know what you are doing.
1919- flake-file.url = lib.mkDefault "github:vic/flake-file";
2020-2121- home-manager = {
2222- url = "github:nix-community/home-manager";
2323- inputs.nixpkgs.follows = "nixpkgs";
2424- };
2525-2626- darwin = {
2727- url = "github:nix-darwin/nix-darwin";
2828- inputs.nixpkgs.follows = "nixpkgs";
2929- };
3030-3131- ## these stable inputs are for wsl
3232- #nixpkgs-stable.url = "github:nixos/nixpkgs/release-25.05";
3333- #home-manager-stable.url = "github:nix-community/home-manager/release-25.05";
3434- #home-manager-stable.inputs.nixpkgs.follows = "nixpkgs-stable";
3535-3636- #nixos-wsl = {
3737- # url = "github:nix-community/nixos-wsl";
3838- # inputs.nixpkgs.follows = "nixpkgs-stable";
3939- # inputs.flake-compat.follows = "";
4040- #};
4141-4242- };
4343-33+ imports = [
44+ inputs.flake-file.flakeModules.dendritic
55+ ];
446}
+37
templates/default/modules/inputs.nix
···11+# This repo was generated with github:vic/flake-file#dendritic template.
22+# Run `nix run .#write-flake` after changing any input.
33+#
44+# Inputs can be placed in any module, the best practice is to have them
55+# as close as possible to their actual usage.
66+# See: https://vic.github.io/dendrix/Dendritic.html#minimal-and-focused-flakenix
77+#
88+# For our template, we enable home-manager and nix-darwin by default, but
99+# you are free to remove them if not being used by you.
1010+{ inputs, ... }:
1111+{
1212+1313+ flake-file.inputs = {
1414+ home-manager = {
1515+ url = "github:nix-community/home-manager";
1616+ inputs.nixpkgs.follows = "nixpkgs";
1717+ };
1818+1919+ darwin = {
2020+ url = "github:nix-darwin/nix-darwin";
2121+ inputs.nixpkgs.follows = "nixpkgs";
2222+ };
2323+2424+ ## these stable inputs are for wsl
2525+ #nixpkgs-stable.url = "github:nixos/nixpkgs/release-25.05";
2626+ #home-manager-stable.url = "github:nix-community/home-manager/release-25.05";
2727+ #home-manager-stable.inputs.nixpkgs.follows = "nixpkgs-stable";
2828+2929+ #nixos-wsl = {
3030+ # url = "github:nix-community/nixos-wsl";
3131+ # inputs.nixpkgs.follows = "nixpkgs-stable";
3232+ # inputs.flake-compat.follows = "";
3333+ #};
3434+3535+ };
3636+3737+}
+14
templates/default/modules/namespace.nix
···11+{ inputs, den, ... }:
22+{
33+ # create an `eg` (example!) namespace.
44+ imports = [ (inputs.den.namespace "eg" false) ];
55+66+ # you can have more than one namespace, create yours.
77+ # imports = [ (inputs.den.namespace "yours" true) ];
88+99+ # you can also import namespaces from remote flakes.
1010+ # imports = [ (inputs.den.namespace "ours" inputs.theirs) ];
1111+1212+ # this line enables den angle brackets syntax in modules.
1313+ _module.args.__findFile = den.lib.__findFile;
1414+}