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

add base module for user/host/home configs (#119)

Allows users to have a base module for home/host/user definitions:

```nix

den.base.host = {
# applies to all den.hosts.<system>.<name>
# use it to define options all hosts might have.
};

den.base.user = { ... } # included in all den.hosts.<system>.<name>.users.<user>

den.base.home = { ... } # included in all den.homes.<system>.<name>

den.base.conf = { ... } # included in ANY host / user / home config.
```

authored by oeiuwq.com and committed by

GitHub d114d8b8 14c34be3

+97
+6
modules/_types.nix
··· 26 26 { name, config, ... }: 27 27 { 28 28 freeformType = lib.types.attrsOf lib.types.anything; 29 + imports = [ den.base.host ]; 30 + config._module.args.host = config; 29 31 options = { 30 32 name = strOpt "host configuration name" name; 31 33 hostName = strOpt "Network hostname" config.name; ··· 99 101 { name, config, ... }: 100 102 { 101 103 freeformType = lib.types.attrsOf lib.types.anything; 104 + imports = [ den.base.user ]; 105 + config._module.args.user = config; 102 106 options = { 103 107 name = strOpt "user configuration name" name; 104 108 userName = strOpt "user account name" config.name; ··· 134 138 { name, config, ... }: 135 139 { 136 140 freeformType = lib.types.attrsOf lib.types.anything; 141 + imports = [ den.base.home ]; 142 + config._module.args.home = config; 137 143 options = { 138 144 name = strOpt "home configuration name" name; 139 145 userName = strOpt "user account name" config.name;
+15
modules/options.nix
··· 6 6 }: 7 7 let 8 8 types = import ./_types.nix { inherit inputs lib config; }; 9 + baseMod = lib.mkOption { 10 + type = lib.types.deferredModule; 11 + default = { }; 12 + }; 9 13 in 10 14 { 11 15 options.den.hosts = types.hostsOption; 12 16 options.den.homes = types.homesOption; 17 + options.den.base = { 18 + conf = baseMod; 19 + host = baseMod; 20 + user = baseMod; 21 + home = baseMod; 22 + }; 23 + config.den.base = { 24 + host.imports = [ config.den.base.conf ]; 25 + user.imports = [ config.den.base.conf ]; 26 + home.imports = [ config.den.base.conf ]; 27 + }; 13 28 }
+76
templates/examples/modules/_example/ci/base-conf-modules.nix
··· 1 + # tests for extending `den.base.*` modules with capabilities (options). 2 + # these allow you to expend all hosts/users/homes with custom option 3 + # that can later be used by aspects for providing features. 4 + # 5 + { lib, ... }: 6 + { 7 + 8 + # This module is base for all host configs. 9 + den.base.host = 10 + { host, ... }: 11 + { 12 + options.capabilities.ssh-server = lib.mkEnableOption "Does host ${host.name} provides ssh?"; 13 + }; 14 + 15 + # This module is base for all user configs. 16 + den.base.user = 17 + { user, ... }: 18 + { 19 + options.isAdmin = lib.mkOption { 20 + type = lib.types.bool; 21 + default = user.name == "alice"; # only alice is always admin 22 + }; 23 + }; 24 + 25 + # This module is base for all home configs. 26 + # den.base.home = { home, ... }: { }; 27 + 28 + # This one is included on each host/user/home 29 + # it cannot access host/user/home values since this conf is generic. 30 + den.base.conf = { 31 + options.foo = lib.mkOption { 32 + type = lib.types.str; 33 + default = "bar"; 34 + }; 35 + }; 36 + 37 + # Now hosts and users can set any option defined in base modules. 38 + den.hosts.x86_64-linux.rockhopper = { 39 + capabilities.ssh-server = true; 40 + foo = "boo"; 41 + users.alice = { 42 + # isAdmin = true; # alice is admin by default, nothing explicit here. 43 + foo = "moo"; 44 + }; 45 + }; 46 + 47 + den.aspects.rockhopper.includes = 48 + let 49 + # An aspect can make use of these options to provide configuration. 50 + sshCapable = 51 + { host, ... }: 52 + { 53 + nixos.services.sshd.enable = host.capabilities.ssh-server; 54 + homeManager.services.ssh-agent.enable = host.capabilities.ssh-server; 55 + }; 56 + in 57 + [ sshCapable ]; 58 + 59 + # CI checks 60 + perSystem = 61 + { 62 + checkCond, 63 + rockhopper, 64 + alice-at-rockhopper, 65 + ... 66 + }: 67 + { 68 + checks.host-conf-rockhopper-sshd = checkCond "sshd enabled" ( 69 + rockhopper.config.services.sshd.enable == true 70 + ); 71 + checks.host-conf-alice-sshd = checkCond "ssh-agent enabled" ( 72 + alice-at-rockhopper.services.ssh-agent.enable == true 73 + ); 74 + }; 75 + 76 + }