Modular, context-aware and aspect-oriented dendritic Nix configurations. Discussions: https://oeiuwq.zulipchat.com/join/nqp26cd4kngon6mo3ncgnuap/
at main 76 lines 2.0 kB view raw
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}