···124124125125```
126126127127-<Aside title="Potential duplicates by igloo.includes Functions" type="caution">
127127+<Aside title="Potential Duplicates by Host Aspect" type="caution">
128128+**Under Bidirectionality**, the igloo aspect is activated more than once!
129129+128130Notice that `den.aspects.igloo.includes` functions are called **with** `{ host }` and **later with** `{ host, user }` **per-user**.
129131130132Because the list of functions at `igloo.includes` get invoked more than once, with different contexts,
···136138137139# avoid being called with `{host}`
138140den.lib.perUser ({ host, user }: ...)
141141+```
142142+143143+Static aspects (plain-attrsets) or host-owned classes at a Host-aspect
144144+have **no way** to distinguish when the calling context is
145145+`{host}` or `{host,user}`, **only functions** are context-aware.
146146+147147+```
148148+# Lists, packages, options at host-level would cause duplicates
149149+# den.aspects.igloo.nixos.options.foo = lib.mkOption {};
150150+151151+# Instead, use perHost to define unique values:
152152+den.aspects.igloo.includes = [
153153+ (perHost { nixos.options.foo = lib.mkOption {}; })
154154+];
139155```
140156141157Read the documentation at [`context/user.nix`](https://github.com/vic/den/blob/main/modules/context/user.nix) for all the details.
+22-22
modules/context/user.nix
···3333 Enable for all users:
3434 den.ctx.user.includes = [ den._.bidirectional ];
35353636- IMPORTANT: Enabling bidirectionality means that the following piepline is enabled:
3636+ IMPORTANT: Enabling bidirectionality means that the following pipeline is enabled:
37373838 host-aspect{host} => user-aspect{host,user} => host-aspect{host,user}
39394040- This means that any function at host-aspect.includes can be called:
4040+ Notice that the host-aspect is being activated more than once!
4141+4242+ This means that host configurations are obtained
4143 - once when the host is obtaining its own configuration with context {host}
4244 - once PER user that has bidirectionality enabled with context {host,user}
43454444- Because of this, parametric aspects at host-aspect must be careful
4545-4646- Instead of -in Nix both of these have the same functionArgs-
4747-4848- ({host}: ...)
4949-5050- or
4646+ Due to Nix `lib.functionArgs` not distinguishing between `{host}` and `{host, ...}`,
4747+ Den provides these utilities built upon `den.lib.take.exactly`:
51485252- ({host, ...}: ...)
5353-5454- Do this to prevent the function being invoked with `{host,user}`
5555-4949+ # Do this to prevent being invoked with `{host,user}`
5650 den.lib.perHost ({host}: ...)
57515858- Or this to avoid it being invoked with `{host}`
5959-5252+ # Do this to prevent being invoked with `{host}`
6053 den.lib.perUser ({host,user}: ...)
61546262- Static aspects, -functions like `{class,aspect-chain}: ...`- at host-aspect.includes
6363- have **no way** to distinguish when the calling context is `{host}` or `{host,user}` if
6464- bidirectionality is enabled.
5555+ Static aspects (plain-attrsets) or host-owned classes at a Host-aspect
5656+ have **no way** to distinguish when the calling context is
5757+ `{host}` or `{host,user}`, only functions are context-aware.
65586666- Because of this, if you have such functions, they might produce duplicate values on list or
6767- conflicting values on package types. A work around is to wrap them in a context-aware function:
5959+ Because of this, a host-aspect might produce duplicate values on list,
6060+ package types, or unique values like options:
68616969- den.lib.perHost ({host}: {class, aspect-chain}: ...)
6262+ # lists, packages and options need to be unique.
6363+ # this line would produce duplicate errors IF bidirectional enabled
6464+ den.aspects.igloo.nixos.options.foo = lib.mkOption {};
70656666+ # Instead, wrap in perHost things that must be unique
6767+ den.aspects.igloo.includes = [
6868+ (den.lib.perHost { nixos.options.foo = lib.mkOption {}; })
6969+ ]
7170 '';
72717372 ctx.user.into.default = lib.singleton;
···7574 ctx.user.provides.bidirectional = take.exactly from-host;
76757776 from-user = { host, user }: fixedTo { inherit host user; } den.aspects.${user.aspect};
7878- from-host = { host, user }: atLeast den.aspects.${host.aspect} { inherit host user; };
7777+7878+ from-host = { host, user }: fixedTo { inherit host user; } den.aspects.${host.aspect};
79798080in
8181{