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

Update README.md

authored by oeiuwq.com and committed by

GitHub e084f0ed 21a1d36a

+77 -35
+77 -35
README.md
··· 36 36 37 37 uses `den.lib` to provide batteries + `host`/`user`/`home` schemas for NixOS/nix-darwin/home-manager. 38 38 39 + 40 + </div> 41 + </td> 42 + <td> 43 + 44 + 39 45 ### Templates: 40 46 41 47 [default](https://den.oeiuwq.com/tutorials/default/): +flake-file +flake-parts +home-manager ··· 65 71 nix flake init -t github:vic/den && nix run .#vm 66 72 ``` 67 73 68 - </div> 69 74 </td> 70 - <td> 71 75 72 - ### Code example (OS configuration domain) 76 + 77 + </tr> 78 + </table> 79 + 80 + 81 + 82 + ## Code example (OS configuration domain) 73 83 74 84 ```nix 75 - # hosts & homes have extensible schema types. 85 + # Define hosts, users & homes 76 86 den.hosts.x86_64-linux.lap.users.vic = {}; 77 87 den.hosts.aarch64-darwin.mac.users.vic = {}; 78 88 den.homes.aarch64-darwin.vic = {}; 79 89 ``` 80 90 91 + ```console 92 + $ nixos-rebuild switch --flake .#lap 93 + $ darwin-rebuild switch --flake .#mac 94 + $ home-manager switch --flake .#vic 95 + ``` 96 + 97 + ```nix 98 + # extensible base modules for common, typed schemas 99 + den.base.user = { user, lib, ... }: { 100 + config.classes = 101 + if user.userName == "vic" then [ "hjem" "maid" ] 102 + else lib.mkDefault [ "homeManager" ]; 103 + 104 + options.mainGroup = lib.mkOption { default = user.userName; }; 105 + }; 106 + ``` 107 + 81 108 ```nix 82 109 # modules/my-laptop.nix 83 110 { den, inputs, ... }: { 84 111 den.aspects.my-laptop = { 85 - includes = [ 86 - den.aspects.work-vpn 87 - ]; 112 + # re-usable configuration aspects 113 + includes = [ den.aspects.work-vpn ]; 114 + 88 115 # regular nixos/darwin modules or any other Nix class 89 - nixos = { pkgs, ... }: { 90 - imports = [ inputs.disko.nixosModules.disko ]; 91 - }; 92 - darwin = { ... }; 116 + nixos = { pkgs, ... }: { imports = [ inputs.disko.nixosModules.disko ]; }; 117 + darwin = { pkgs, ... }: { environment.packages = [ pkgs.hello ]; }; 118 + 119 + # host can contribute to its users' environment 93 120 homeManager.programs.vim.enable = true; 94 121 }; 95 122 } ··· 99 126 # modules/vic.nix 100 127 { den, ... }: { 101 128 den.aspects.vic = { 102 - homeManager = { pkgs, ... }: ...; 103 - nixos.users.users.vic.description = "oeiuwq"; 104 - includes = [ 105 - den.aspects.tiling-wm 106 - den.provides.primary-user 107 - den.aspects.vic._.conditional 108 - ]; 129 + # supports multiple home environments 130 + homeManager = { pkgs, ... }: { }; 131 + hjem.files.".envrc".text = "use flake ~/hk/home"; 132 + maid.kconfig.settings.kwinrc.Desktops.Number = 3; 109 133 110 - provides = { 111 - conditional = { host, user }: 112 - lib.optionalAttrs (host.hasX && user.hasY) { 113 - nixos.imports = [ 114 - inputs.someX.nixosModules.default 115 - ]; 116 - nixos.someX.foo = user.someY; 117 - }; 118 - }; 134 + # user can contribute configurations to all hosts it lives on 135 + darwin.services.karabiner-elements.enable = true; 136 + 137 + # user class forwards into {nixos/darwin}.users.users.<userName> 138 + user = { pkgs, ... }: { 139 + packages = [ pkgs.helix ]; 140 + description = "oeiuwq"; 119 141 }; 142 + 143 + includes = [ 144 + den.provides.primary-user # re-usable batteries 145 + (den.provides.user-shell "fish") # parametric aspects 146 + den.aspects.tiling-wm # your own aspects 147 + den.aspects.gaming.provides.emulators 148 + ]; 120 149 }; 121 150 } 122 151 ``` 123 152 124 - ```console 125 - $ nixos-rebuild switch --flake .#lap 126 - $ darwin-rebuild switch --flake .#mac 127 - $ home-manager switch --flake .#vic 128 - ``` 153 + ```nix 154 + # custom user-defined Nix classes. 129 155 130 - </td> 131 - </tr> 132 - </table> 156 + # any aspect can use my `persys` class to forward configs into 157 + # nixos.environment.persistance."/nix/persist/system" 158 + # **ONLY** when environment.persistance option is present at host. 159 + persys = { host }: den._.forward { 160 + each = lib.singleton true; 161 + fromClass = _: "persys"; 162 + intoClass = _: host.class; 163 + intoPath = _: [ "environment" "persistance" "/nix/persist/system" ]; 164 + fromAspect = _: den.aspects.${host.aspect}; 165 + guard = { options, ... }: options ? environment.persistance; 166 + }; 167 + 168 + # enable on all hosts 169 + den.ctx.host.includes = [ persys ]; 170 + 171 + # becomes nixos.environment.persistance."/nix/persist/system".hideMounts = true; 172 + # no mkIf, set configs and guard ensures to include only when Impermanence exists 173 + den.aspects.my-laptop.persys.hideMounts = true; 174 + ```