Modular, context-aware and aspect-oriented dendritic Nix configurations. Discussions: https://oeiuwq.zulipchat.com/join/nqp26cd4kngon6mo3ncgnuap/ den.oeiuwq.com
configurations den dendritic nix aspect oriented

clarify schema base modules and batteries

thanks @drupol

+86 -61
+23 -42
docs/src/content/docs/reference/batteries.mdx
··· 18 ### `den._.define-user` 19 20 Creates OS-level user accounts (`users.users.<name>`) with `isNormalUser`, 21 - `home`, and group. Sets `home-manager.users.<name>` when home-manager 22 - integration is active. 23 24 ### `den._.os-user` 25 26 - Assigns a user into the host by setting group membership and ensuring 27 - the user account exists at the OS level. 28 29 ### `den._.primary-user` 30 31 - Marks a user as the primary user of a host. Sets `nix.settings.trusted-users` 32 - and can configure auto-login or default shell based on other batteries. 33 34 ### `den._.user-shell` 35 36 - Sets the user's login shell. Reads `user.shell` and configures both 37 - `users.users.<name>.shell` and the home-manager `programs.<shell>.enable`. 38 39 ### `den._.tty-autologin` 40 ··· 43 44 ### `den._.wsl` 45 46 - WSL-specific configuration. Enables `wsl.enable`, sets the default user, 47 - and adjusts networking for WSL2 environments. 48 49 ### `den._.forward` 50 51 - Forwards aspect configuration from one aspect to another. Used to chain 52 - aspects without duplicating declarations. 53 54 ### `den._.import-tree` 55 56 - Uses `inputs.import-tree` to recursively import a directory tree as 57 - aspect modules. Enables file-system-driven aspect organization. 58 59 ## Flake-parts batteries 60 61 ### `den._.inputs'` 62 ··· 70 71 ## Home-manager batteries 72 73 - ### `den._.hm-integration` 74 75 - Integrates home-manager into NixOS/Darwin hosts. Imports the appropriate 76 - home-manager module (`nixos` or `darwin`), enables 77 - `home-manager.useGlobalPkgs` and `useUserPackages`. 78 79 - ### `den._.hm-os` 80 81 - Merges home-manager configuration into the host OS module system. Bridges 82 - `home-manager.users.<name>` with the user's aspect. 83 84 ## Hjem batteries 85 86 - ### `den._.hjem-integration` 87 - 88 Integrates [hjem](https://github.com/feel-co/hjem) as an alternative to 89 - home-manager. Imports hjem's NixOS module. 90 - 91 - ### `den._.hjem-os` 92 93 Merges hjem user configuration into the host. Sets `hjem.users.<name>` 94 - from the user's aspect. 95 96 ## Maid batteries 97 98 - ### `den._.maid-integration` 99 - 100 Integrates [maid](https://github.com/maid-nix/maid) as an alternative 101 home management system. 102 103 - ### `den._.maid-os` 104 - 105 - Merges maid configuration into the host OS for each user. 106 - 107 - ## Unfree batteries 108 109 ### `den._.unfree` 110 111 - Allows unfree packages globally via 112 - `nixpkgs.config.allowUnfree = true`. 113 - 114 - ### `den._.unfree-predicate` 115 - 116 - Allows unfree packages selectively using a predicate builder. Accepts 117 - a list of package names and builds 118 - `nixpkgs.config.allowUnfreePredicate`.
··· 18 ### `den._.define-user` 19 20 Creates OS-level user accounts (`users.users.<name>`) with `isNormalUser`, 21 + and `home` directory. Works on NixOS/Darwin/WSL/HomeManager. 22 23 ### `den._.os-user` 24 25 + A `user` class automatically enabled by Den to forward settings into the host's 26 + `users.users.<userName>`. Forwards work into NixOS/Darwin classes. 27 28 ### `den._.primary-user` 29 30 + Marks a user as the primary user (admin level) of a host. Works in NixOS/Darwin/WSL. 31 32 ### `den._.user-shell` 33 34 + Sets the user's login shell. 35 + `users.users.<name>.shell` enabling the shell at host, and the home-manager `programs.<shell>.enable`. 36 37 ### `den._.tty-autologin` 38 ··· 41 42 ### `den._.wsl` 43 44 + WSL-specific activation. Enables `den.ctx.wsl-host` when the `host.wsl.enable = true` 45 + and includes NixOS-WSL module. 46 47 ### `den._.forward` 48 49 + Forwards aspect configuration from one aspect to another. 50 + Used for separation of conncerns. See Custom Classes section. 51 52 ### `den._.import-tree` 53 54 + Provides `inputs.import-tree` helpers to import trees of non-dendritic 55 + legacy modules, like a directory containing only nixos modules. 56 57 ## Flake-parts batteries 58 + 59 + These only work when the module system is flake-parts'. 60 61 ### `den._.inputs'` 62 ··· 70 71 ## Home-manager batteries 72 73 + Defines `den.ctx.hm-host` which activates when at least one user has `homeManager` classes. 74 + The `hm-host` context can be used to set `home-manager.useGlobalPkgs` and `useUserPackages`. 75 76 + Merges home-manager configuration into the host OS module system. Bridges 77 + `home-manager.users.<name>` with the user's `homeManager` class. 78 79 + Imports the appropriate home-manager module (`nixos` or `darwin`). 80 81 82 ## Hjem batteries 83 84 Integrates [hjem](https://github.com/feel-co/hjem) as an alternative to 85 + home-manager. Imports hjem's NixOS/Darwin module. 86 87 Merges hjem user configuration into the host. Sets `hjem.users.<name>` 88 + from the user's `hjem` class. 89 90 ## Maid batteries 91 92 Integrates [maid](https://github.com/maid-nix/maid) as an alternative 93 home management system. 94 95 + Merges maid configuration into the host OS `users.users.<name>.maid` for each user `maid` class. 96 97 ### `den._.unfree` 98 99 + Allows unfree packages by name via `nixpkgs.config.allowUnfreePredicate`.
+63 -19
docs/src/content/docs/reference/schema.mdx
··· 10 [`modules/_types.nix`](https://github.com/vic/den/blob/main/modules/_types.nix) 11 </Aside> 12 13 ## `den.hosts` 14 15 Type: `attrsOf systemType` ··· 98 | `*` | `den.base.home` options | | Options from base module | 99 | `*` | | | free-form attributes | 100 101 - ## `den.base` 102 - 103 - Base modules merged into all hosts, users, or homes. 104 - 105 - | Option | Type | Description | 106 - |--------|------|-------------| 107 - | `den.base.conf` | `deferredModule` | Applied to host, user, and home | 108 - | `den.base.host` | `deferredModule` | Applied to all hosts (imports `conf`) | 109 - | `den.base.user` | `deferredModule` | Applied to all users (imports `conf`) | 110 - | `den.base.home` | `deferredModule` | Applied to all homes (imports `conf`) | 111 - 112 - ```nix 113 - den.base.conf = { lib, ... }: { 114 - # shared across all host/user/home declarations 115 - }; 116 - den.base.host = { ... }: { 117 - # host-specific base config 118 - }; 119 - ```
··· 10 [`modules/_types.nix`](https://github.com/vic/den/blob/main/modules/_types.nix) 11 </Aside> 12 13 + ## Schema Base Modules 14 + 15 + Each of `host`, `user`, `home` configuration objects have freeform-types, 16 + meaning you can assign any attribute into them as meta-data. 17 + 18 + However, at times you might want to have shared meta-data between all hosts 19 + or all users. 20 + 21 + The base modules, `den.base.*` serve for this purpose. 22 + They are **not aspects**, they are meta-data (the attributes of host) that aspects 23 + can later read for providing configuration. 24 + 25 + For example, instead of: 26 + 27 + ```nix 28 + den.hosts.x86_64-linux.igloo = { 29 + hardedned = true; # custom free-form metadata 30 + 31 + # repetitive 32 + users.alice.classes = [ "homeManager" ]; 33 + users.bob.classes = [ "homeManager" ]; 34 + }; 35 + ``` 36 + 37 + You can do: 38 + 39 + ```nix 40 + # This is not an aspect, it is a meta-configuration of the host capabilities. 41 + den.base.host = { host, lib, ... }: { 42 + options.hardened = lib.mkEnableOption "Is it secure"; 43 + config.hardened = lib.mkDefault true; 44 + }; 45 + 46 + # The meta-configuration module for all users 47 + den.base.user = { user, lib, ... }: { 48 + config.classes = lib.mkDefault [ "homeManager" ]; 49 + }; 50 + ``` 51 + 52 + All hosts you create will be `hardened = true` by default. And aspects will 53 + be able to read `host.hardened` value. 54 + 55 + ## `den.base` 56 + 57 + Base modules merged into all hosts, users, or homes. 58 + 59 + | Option | Type | Description | 60 + |--------|------|-------------| 61 + | `den.base.conf` | `deferredModule` | Applied to host, user, and home | 62 + | `den.base.host` | `deferredModule` | Applied to all hosts (imports `conf`) | 63 + | `den.base.user` | `deferredModule` | Applied to all users (imports `conf`) | 64 + | `den.base.home` | `deferredModule` | Applied to all homes (imports `conf`) | 65 + 66 + ```nix 67 + den.base.conf = { lib, ... }: { 68 + # shared across all host/user/home declarations 69 + }; 70 + den.base.host = { ... }: { 71 + # host-specific base config 72 + }; 73 + ``` 74 + 75 + 76 ## `den.hosts` 77 78 Type: `attrsOf systemType` ··· 161 | `*` | `den.base.home` options | | Options from base module | 162 | `*` | | | free-form attributes | 163