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

rename den.base to den.schema to clarify intention (#234)

authored by oeiuwq.com and committed by

GitHub 6c205612 0a84eba5

+53 -51
+1 -1
README.md
··· 113 113 114 114 ```nix 115 115 # extensible base modules for common, typed schemas 116 - den.base.user = { user, lib, ... }: { 116 + den.schema.user = { user, lib, ... }: { 117 117 config.classes = 118 118 if user.userName == "vic" then [ "hjem" "maid" ] 119 119 else lib.mkDefault [ "homeManager" ];
+1 -1
docs/astro.config.mjs
··· 73 73 { 74 74 label: 'Reference', 75 75 items: [ 76 - { label: 'den.base', slug: 'reference/schema' }, 76 + { label: 'den.schema', slug: 'reference/schema' }, 77 77 { label: 'den.aspects', slug: 'reference/aspects' }, 78 78 { label: 'den.provides', slug: 'reference/batteries' }, 79 79 { label: 'den.ctx', slug: 'reference/ctx' },
+8 -8
docs/src/content/docs/guides/declare-hosts.mdx
··· 33 33 ## Host Schema 34 34 35 35 <Aside title="Important" icon="nix"> 36 - Be sure to read about the entity [Schemas](/reference/schema/), each of `host`/`user`/`home` has a corresponding `den.base.*` module for meta-configuration. Which can later be used in aspects that read from `host`. These schemas are the meta-data equivalent of what Dendritic flake-parts users do with flake-level options. 36 + Be sure to read about the entity [Schemas](/reference/schema/), each of `host`/`user`/`home` has a corresponding `den.schema.*` module for meta-configuration. Which can later be used in aspects that read from `host`. These schemas are the meta-data equivalent of what Dendritic flake-parts users do with flake-level options. 37 37 </Aside> 38 38 39 39 Hosts have these options (all with sensible defaults): ··· 48 48 | `instantiate` | class-dependent | `lib.nixosSystem`, `darwinSystem`, etc. | 49 49 | `intoAttr` | class-dependent | Flake output path | 50 50 | `users` | `{}` | User account definitions | 51 - | `*` | from `den.base.host` | Any option defined by base module | 51 + | `*` | from `den.schema.host` | Any option defined by base module | 52 52 | `*` | | Any other free-form attribute | 53 53 54 54 ## User Declaration ··· 70 70 | `userName` | `name` | System account name | 71 71 | `aspect` | `name` | Primary aspect name | 72 72 | `classes` | `[ "homeManager" ]` | Nix classes this user participates in | 73 - | `*` | from `den.base.user` | Any option defined by base module | 73 + | `*` | from `den.schema.user` | Any option defined by base module | 74 74 | `*` | | Any other free-form attribute | 75 75 76 76 ## Standalone Homes ··· 97 97 | `aspect` | `name` | Primary aspect name | 98 98 | `pkgs` | `inputs.nixpkgs.legacyPackages.${system}` | nixpkgs instance | 99 99 | `instantiate` | `inputs.home-manager.lib.homeManagerConfiguration` | Builder function | 100 - | `*` | from `den.base.host` | Any option defined by base module | 100 + | `*` | from `den.schema.host` | Any option defined by base module | 101 101 | `*` | | Any other free-form attribute | 102 102 103 103 ## Base Modules 104 104 105 - `den.base.{host,user,home,conf}` provides shared configuration applied to all entities of each kind. 105 + `den.schema.{host,user,home,conf}` provides shared configuration applied to all entities of each kind. 106 106 107 107 Some batteries also extend base modules [see `hjem-os.nix`](https://github.com/vic/den/blob/main/modules/aspects/provides/hjem/hjem-os.nix#L50) which defines `hjem.module` option. 108 108 109 109 ```nix 110 110 { 111 111 # Can be used to config each host 112 - den.base.host.home-manager.enable = true; 112 + den.schema.host.home-manager.enable = true; 113 113 114 114 # Can be used to add schema options with defaults 115 - den.base.user = { user, lib, ... }: { 115 + den.schema.user = { user, lib, ... }: { 116 116 options.groupName = lib.mkOption { default = user.userName; }; 117 117 }; 118 118 119 119 # Applied to every host and user and home. 120 - den.base.conf = { 120 + den.schema.conf = { 121 121 options.copyright = lib.mkOption { default = "Copy-Left"; }; 122 122 }; 123 123 }
+2 -2
docs/src/content/docs/guides/home-manager.mdx
··· 26 26 den.hosts.x86_64-linux.igloo.users.tux.classes = [ "homeManager" "hjem" ]; 27 27 28 28 # As default for all users, unless they specify other classes. 29 - den.base.user.classes = lib.mkDefault [ "homeManager" ]; 29 + den.schema.user.classes = lib.mkDefault [ "homeManager" ]; 30 30 ``` 31 31 32 32 Home integration contexts, like `den.ctx.hm-host` only activate when ··· 105 105 }; 106 106 107 107 # On all hosts 108 - den.base.host.hjem.enable = true; 108 + den.schema.host.hjem.enable = true; 109 109 ``` 110 110 111 111 ### Requirements
+1 -1
docs/src/content/docs/index.mdx
··· 154 154 ``` 155 155 156 156 <Steps> 157 - 1. **Schema** -- `den.hosts` and `den.homes` declare machines, users, and their properties with `den.base` modules and extensible freeform types. 157 + 1. **Schema** -- `den.hosts` and `den.homes` declare machines, users, and their properties with `den.schema` modules and extensible freeform types. 158 158 2. **Aspects** -- `den.aspects.*` bundles per-class configs (`nixos`, `darwin`, `homeManager`, or any custom class) with `.includes` and `.provides` forming a DAG. 159 159 3. **Context pipeline** -- `den.ctx` transforms schema entries into context pairs (`{host}`, `{host, user}`, `{home}`), walking `into.*` transitions for derived contexts like `hm-host`, `hm-user`, `wsl-host` or any other custom context stage. 160 160 4. **Resolution** -- Parametric dispatch via `__functor` argument introspection. Functions receive only contexts whose shape matches their parameters.
+1 -1
docs/src/content/docs/motivation.mdx
··· 77 77 78 78 - How to define common [schemas](/guides/declare-hosts#base-modules) (options) for these entities. 79 79 80 - `den.base.host.options.vpn-group = lib.mkOption` 80 + `den.schema.host.options.vpn-group = lib.mkOption` 81 81 82 82 - How to [include features](/guides/batteries) that affect all entities 83 83
+1 -1
docs/src/content/docs/overview.mdx
··· 56 56 <LinkCard title="den.ctx" href="/reference/ctx/" description="Context types, into transformations, provides." /> 57 57 <LinkCard title="den.lib" href="/reference/lib/" description="parametric, canTake, take, statics, owned, __findFile." /> 58 58 <LinkCard title="den.aspects" href="/reference/aspects/" description="Aspect type, resolution, class configs." /> 59 - <LinkCard title="den.base" href="/reference/schema/" description="Host, user, home schema options." /> 59 + <LinkCard title="den.schema" href="/reference/schema/" description="Host, user, home schema options." /> 60 60 <LinkCard title="den.provides" href="/reference/batteries/" description="Built-in batteries reference." /> 61 61 <LinkCard title="flake.*" href="/reference/output/" description="Output generation and instantiation." /> 62 62 </CardGrid>
+13 -13
docs/src/content/docs/reference/schema.mdx
··· 18 18 However, at times you might want to have shared meta-data between all hosts 19 19 or all users. 20 20 21 - The base modules, `den.base.*` serve for this purpose. 21 + The base modules, `den.schema.*` serve for this purpose. 22 22 They are **not aspects**, they are meta-data (the attributes of host) that aspects 23 23 can later read for providing configuration. 24 24 ··· 38 38 39 39 ```nix 40 40 # This is not an aspect, it is a meta-configuration of the host capabilities. 41 - den.base.host = { host, lib, ... }: { 41 + den.schema.host = { host, lib, ... }: { 42 42 options.hardened = lib.mkEnableOption "Is it secure"; 43 43 config.hardened = lib.mkDefault true; 44 44 }; 45 45 46 46 # The meta-configuration module for all users 47 - den.base.user = { user, lib, ... }: { 47 + den.schema.user = { user, lib, ... }: { 48 48 config.classes = lib.mkDefault [ "homeManager" ]; 49 49 }; 50 50 ``` ··· 52 52 All hosts you create will be `hardened = true` by default. And aspects will 53 53 be able to read `host.hardened` value. 54 54 55 - ## `den.base` 55 + ## `den.schema` 56 56 57 57 Base modules merged into all hosts, users, or homes. 58 58 59 59 | Option | Type | Description | 60 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`) | 61 + | `den.schema.conf` | `deferredModule` | Applied to host, user, and home | 62 + | `den.schema.host` | `deferredModule` | Applied to all hosts (imports `conf`) | 63 + | `den.schema.user` | `deferredModule` | Applied to all users (imports `conf`) | 64 + | `den.schema.home` | `deferredModule` | Applied to all homes (imports `conf`) | 65 65 66 66 ```nix 67 - den.base.conf = { lib, ... }: { 67 + den.schema.conf = { lib, ... }: { 68 68 # shared across all host/user/home declarations 69 69 }; 70 - den.base.host = { ... }: { 70 + den.schema.host = { ... }: { 71 71 # host-specific base config 72 72 }; 73 73 ``` ··· 99 99 | `users` | `attrsOf userType` | `{}` | User accounts on this host | 100 100 | `instantiate` | `raw` | auto | OS builder function | 101 101 | `intoAttr` | `listOf str` | auto | Flake output path | 102 - | `*` | `den.base.host` options | | Options from base module | 102 + | `*` | `den.schema.host` options | | Options from base module | 103 103 | `*` | | | free-form attributes | 104 104 105 105 ### `instantiate` defaults ··· 130 130 | `userName` | `str` | `name` | System account name | 131 131 | `classes` | `listOf str` | `[ "homeManager" ]` | Home management classes | 132 132 | `aspect` | `str` | `name` | Main aspect name | 133 - | `*` | `den.base.user` options | | Options from base module | 133 + | `*` | `den.schema.user` options | | Options from base module | 134 134 | `*` | | | free-form attributes | 135 135 136 136 Freeform: additional attributes pass through to the user module. ··· 158 158 | `pkgs` | `raw` | `inputs.nixpkgs.legacyPackages.$sys` | Nixpkgs instance | 159 159 | `instantiate` | `raw` | `inputs.home-manager.lib.homeManagerConfiguration` | Builder | 160 160 | `intoAttr` | `listOf str` | `[ "homeConfigurations" name ]` | Output path | 161 - | `*` | `den.base.home` options | | Options from base module | 161 + | `*` | `den.schema.home` options | | Options from base module | 162 162 | `*` | | | free-form attributes | 163 163
+2 -2
docs/src/content/docs/tutorials/ci.md
··· 24 24 namespaces.nix # namespace define/merge/export 25 25 os-user-class.nix # user class forwarding 26 26 parametric.nix # parametric functors 27 - schema-base-modules.nix # den.base modules 27 + schema-base-modules.nix # den.schema modules 28 28 special-args-custom-instantiate.nix # custom instantiation 29 29 top-level-parametric.nix # top-level context aspects 30 30 user-host-bidirectional-config.nix # bidirectional providers ··· 104 104 | [namespaces.nix](https://github.com/vic/den/blob/main/templates/ci/modules/features/namespaces.nix) | Local, remote, merged namespaces | 105 105 | [forward-from-custom-class.nix](https://github.com/vic/den/blob/main/templates/ci/modules/features/forward-from-custom-class.nix) | Custom class forwarding | 106 106 | [homes.nix](https://github.com/vic/den/blob/main/templates/ci/modules/features/homes.nix) | Standalone Home-Manager configs | 107 - | [schema-base-modules.nix](https://github.com/vic/den/blob/main/templates/ci/modules/features/schema-base-modules.nix) | `den.base.{host,user,home,conf}` | 107 + | [schema-base-modules.nix](https://github.com/vic/den/blob/main/templates/ci/modules/features/schema-base-modules.nix) | `den.schema.{host,user,home,conf}` | 108 108 109 109 ### Bug Regressions 110 110
+1 -1
modules/aspects/provides/hjem/hjem-os.nix
··· 37 37 in 38 38 { 39 39 den.ctx = ctx; 40 - den.base.host.imports = [ hostConf ]; 40 + den.schema.host.imports = [ hostConf ]; 41 41 }
+1 -1
modules/aspects/provides/home-manager/hm-integration.nix
··· 23 23 24 24 For all users unless they set a value: 25 25 26 - den.base.user.classes = lib.mkDefault [ "homeManager" ]; 26 + den.schema.user.classes = lib.mkDefault [ "homeManager" ]; 27 27 28 28 On specific users: 29 29
+1 -1
modules/aspects/provides/home-manager/hm-os.nix
··· 38 38 in 39 39 { 40 40 den.ctx = ctx; 41 - den.base.host.imports = [ hostConf ]; 41 + den.schema.host.imports = [ hostConf ]; 42 42 }
+1 -1
modules/aspects/provides/maid/maid-os.nix
··· 35 35 in 36 36 { 37 37 den.ctx = ctx; 38 - den.base.host.imports = [ hostConf ]; 38 + den.schema.host.imports = [ hostConf ]; 39 39 }
+2 -2
modules/aspects/provides/wsl.nix
··· 21 21 22 22 On ALL hosts (works only on nixos class hosts): 23 23 24 - den.base.host.wsl.enable = true; 24 + den.schema.host.wsl.enable = true; 25 25 ''; 26 26 27 27 ctx.host.into.wsl-host = ··· 59 59 in 60 60 { 61 61 den.ctx = ctx; 62 - den.base.host.imports = [ hostConf ]; 62 + den.schema.host.imports = [ hostConf ]; 63 63 }
+5 -5
modules/options.nix
··· 15 15 { 16 16 options.den.hosts = types.hostsOption; 17 17 options.den.homes = types.homesOption; 18 - options.den.base = { 18 + options.den.schema = { 19 19 conf = baseMod; 20 20 host = baseMod; 21 21 user = baseMod; 22 22 home = baseMod; 23 23 }; 24 - config.den.base = { 25 - host.imports = [ den.base.conf ]; 26 - user.imports = [ den.base.conf ]; 27 - home.imports = [ den.base.conf ]; 24 + config.den.schema = { 25 + host.imports = [ den.schema.conf ]; 26 + user.imports = [ den.schema.conf ]; 27 + home.imports = [ den.schema.conf ]; 28 28 }; 29 29 }
+3 -3
nix/types.nix
··· 24 24 { name, config, ... }: 25 25 { 26 26 freeformType = lib.types.attrsOf lib.types.anything; 27 - imports = [ den.base.host ]; 27 + imports = [ den.schema.host ]; 28 28 config._module.args.host = config; 29 29 options = { 30 30 name = strOpt "host configuration name" name; ··· 108 108 { name, config, ... }: 109 109 { 110 110 freeformType = lib.types.attrsOf lib.types.anything; 111 - imports = [ den.base.user ]; 111 + imports = [ den.schema.user ]; 112 112 config._module.args.user = config; 113 113 options = { 114 114 name = strOpt "user configuration name" name; ··· 149 149 { name, config, ... }: 150 150 { 151 151 freeformType = lib.types.attrsOf lib.types.anything; 152 - imports = [ den.base.home ]; 152 + imports = [ den.schema.home ]; 153 153 config._module.args.home = config; 154 154 options = { 155 155 name = strOpt "home configuration name" name;
+1 -1
templates/bogus/modules/test-base.nix
··· 34 34 boot.loader.grub.enable = lib.mkForce false; 35 35 fileSystems."/".device = lib.mkForce "/dev/fake"; 36 36 }; 37 - den.base.user.classes = lib.mkDefault [ "homeManager " ]; 37 + den.schema.user.classes = lib.mkDefault [ "homeManager " ]; 38 38 }; 39 39 40 40 testModule = {
+3 -1
templates/ci/modules/features/den-as-lib.nix
··· 56 56 names = [ 57 57 "hosts" 58 58 "homes" 59 - "base" 59 + "schema" 60 60 "default" 61 + "provides" 62 + "ful" 61 63 ]; 62 64 ev = lib.evalModules { modules = [ denModule ]; }; 63 65 expr = builtins.all (name: !ev.config.den ? ${name}) names;
+4 -4
templates/ci/modules/features/schema-base-modules.nix
··· 6 6 test-host-base = denTest ( 7 7 { den, lib, ... }: 8 8 { 9 - den.base.host = 9 + den.schema.host = 10 10 { host, ... }: 11 11 { 12 12 options.vpn-alias = lib.mkOption { default = host.name; }; ··· 22 22 test-user-base = denTest ( 23 23 { den, lib, ... }: 24 24 { 25 - den.base.user = 25 + den.schema.user = 26 26 { user, ... }: 27 27 { 28 28 options.main-group = lib.mkOption { default = user.name; }; ··· 38 38 test-home-base = denTest ( 39 39 { den, lib, ... }: 40 40 { 41 - den.base.home = 41 + den.schema.home = 42 42 { home, ... }: 43 43 { 44 44 options.main-group = lib.mkOption { default = home.name; }; ··· 54 54 test-conf-base = denTest ( 55 55 { den, lib, ... }: 56 56 { 57 - den.base.conf = 57 + den.schema.conf = 58 58 { ... }: 59 59 { 60 60 options.foo = lib.mkOption { default = "foo"; };
+1 -1
templates/ci/modules/test-support/eval-den.nix
··· 32 32 options.flake.packages = lib.mkOption { }; 33 33 options.expr = lib.mkOption { }; 34 34 options.expected = lib.mkOption { }; 35 - config.den.base.user.classes = lib.mkDefault [ "homeManager" ]; 35 + config.den.schema.user.classes = lib.mkDefault [ "homeManager" ]; 36 36 }; 37 37 38 38 helpersModule =