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
8
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat(lib): add den.lib.perHome and add documentation for context shortcuts (#303)

Noticed these missing from #288, so decided to add it

authored by

Heitor Augusto and committed by
GitHub
cd3e9ff1 586dd03f

+71 -3
+2 -2
docs/src/content/docs/explanation/parametric.mdx
··· 22 22 # Matches: {host, user} only 23 23 (den.lib.perUser ({ host, user }: { nixos.x = user.userName; })) 24 24 25 - # Matches: {home} **or** {home, foo} 26 - ({ home }: { homeManager.x = home.userName; }) 25 + # Matches: {home} only 26 + (den.lib.perHome ({ home }: { homeManager.x = home.userName; })) 27 27 ``` 28 28 29 29 ## The `canTake` Function
+17
docs/src/content/docs/reference/lib.mdx
··· 87 87 `_unused: used: used` -- ignores first argument, returns second. Used for 88 88 discarding `aspect-chain` in `import-tree`. 89 89 90 + ## Context Shortcuts 91 + 92 + These helpers are shortcuts built with `den.lib.take.exactly` and 93 + `den.lib.parametric.fixedTo`: 94 + 95 + ### `den.lib.perHost aspect` 96 + 97 + Run `aspect` only in `{ host }` contexts. 98 + 99 + ### `den.lib.perUser aspect` 100 + 101 + Run `aspect` only in `{ host, user }` contexts. 102 + 103 + ### `den.lib.perHome aspect` 104 + 105 + Run `aspect` only in `{ home }` contexts. 106 + 90 107 ## `den.lib.statics` 91 108 92 109 Extracts only static includes from an aspect (non-function includes):
+2 -1
modules/context/perHost-perUser.nix
··· 9 9 fixed = ctx: aspect: parametric.fixedTo ctx { includes = [ aspect ]; }; 10 10 perHost = aspect: take.exactly ({ host }@ctx: fixed ctx aspect); 11 11 perUser = aspect: take.exactly ({ host, user }@ctx: fixed ctx aspect); 12 + perHome = aspect: take.exactly ({ home }@ctx: fixed ctx aspect); 12 13 in 13 14 { 14 - den.lib = { inherit perUser perHost; }; 15 + den.lib = { inherit perHome perUser perHost; }; 15 16 }
+48
templates/ci/modules/features/perUser-perHost.nix
··· 135 135 } 136 136 ); 137 137 138 + test-perHome-on-standalone-home = denTest ( 139 + { 140 + den, 141 + config, 142 + lib, 143 + ... 144 + }: 145 + { 146 + den.homes.x86_64-linux.tux = { }; 147 + den.default.includes = [ den._.define-user ]; 148 + 149 + den.aspects.tux.homeManager.options.funny = lib.mkOption { 150 + default = [ ]; 151 + type = lib.types.listOf lib.types.str; 152 + }; 153 + 154 + den.aspects.tux.includes = [ 155 + (den.lib.perHost { homeManager.funny = [ "atHome IGNORED perHost static" ]; }) 156 + (den.lib.perHost ( 157 + { host }: 158 + { 159 + homeManager.funny = [ "atHome IGNORED perHost ${host.name} fun" ]; 160 + } 161 + )) 162 + (den.lib.perUser { homeManager.funny = [ "atHome IGNORED perUser static" ]; }) 163 + (den.lib.perUser ( 164 + { user, host }: 165 + { 166 + homeManager.funny = [ "atHome IGNORED perUser ${user.name}@${host.name} fun" ]; 167 + } 168 + )) 169 + (den.lib.perHome { homeManager.funny = [ "atHome perHome static" ]; }) 170 + (den.lib.perHome ( 171 + { home }: 172 + { 173 + homeManager.funny = [ "atHome perHome ${home.name} fun" ]; 174 + } 175 + )) 176 + ]; 177 + 178 + expr = lib.sort (a: b: a < b) config.flake.homeConfigurations.tux.config.funny; 179 + expected = [ 180 + "atHome perHome static" 181 + "atHome perHome tux fun" 182 + ]; 183 + } 184 + ); 185 + 138 186 }; 139 187 }
+2
templates/example/modules/aspects/defaults.nix
··· 39 39 # den.lib.perHost ({ host }: { nixos.foo = [ 42 ]; }) 40 40 # # Or for { host, user } ONLY: 41 41 # den.lib.perUser ({ host, user }: { nixos.foo = [ 42 ]; }) 42 + # # Or for standalone homes ({ home }) ONLY: 43 + # den.lib.perHome ({ home }: { homeManager.foo = [ 42 ]; }) 42 44 ]; 43 45 }