!wfudwzqQUiJYJnqfSY:nixos.org

NixOS Module System

81 Members
20 Servers

Load older messages


SenderMessageTime
28 Jul 2024
@mattsturg:matrix.orgMatt Sturgeon

Maybe the correct implementation is to define any "optional" options outside the freeform submodule, and then copy them in if defined?

# Set settings.foo to foo, if defined
optionalAttrs options.something.foo.isDefined {
  # Use mkDerivedConfig to also copy definition priority
  something.settings.foo = lib.mkDerivedConfig options.something.foo (v: v);
}

Perhaps submodule sub-options are only intended to be used when the value should always be in the generated value?

20:41:12
@mattsturg:matrix.orgMatt Sturgeon *

Maybe the correct implementation is to define any "optional" options outside the freeform submodule, and then copy them in if defined?

# Set settings.foo to foo, if defined
lib.optionalAttrs options.something.foo.isDefined {
  # Use mkDerivedConfig to also copy definition priority
  something.settings.foo = lib.mkDerivedConfig options.something.foo (v: v);
}

Perhaps submodule sub-options are only intended to be used when the value should always be in the generated value?

20:41:39
29 Jul 2024
@infinisil:matrix.orginfinisilRelated: https://github.com/NixOS/nixpkgs/pull/6355323:08:02
@infinisil:matrix.orginfinisilAnd https://github.com/NixOS/nixpkgs/issues/15859423:09:27
30 Jul 2024
@mattsturg:matrix.orgMatt Sturgeon

Thanks, those links are insightful!

I think 158598 is also related, but 158594 sounds like exactly what I want:

We could add a mkOption argument that has the effect of producing no default value and no config attribute when no definitions are present for the option.

But it looks like the latest comment is backtracking or downscaling that idea...

Playing around in the repl, I can get _module.freeformType and I can get any _freeformOptions for freeform submodules (freeformType = attrsOf submodule), but I can't seem to find the freeform value or definitions anywhere separate from the fully merged option value/defs. Can you confirm I'm not missing anything here?

I guess to do this I would have to write my own types.submodule equivalent (e.g. submoduleWithoutUndefs)? With a custom type I should be able to merge using evalModules but filter out any undefined options 🤔

Seems similar in principle to the types.record proposal in #257511, although I'd need optional and nested fields which I think is out of scope for that one.

00:34:08
@mattsturg:matrix.orgMatt Sturgeon *

Thanks, those links are insightful!

158594 sounds like exactly what I want:

We could add a mkOption argument that has the effect of producing no default value and no config attribute when no definitions are present for the option.

But it looks like the latest comment is backtracking or downscaling that idea...

Playing around in the repl, I can get _module.freeformType and I can get any _freeformOptions for freeform submodules (freeformType = attrsOf submodule), but I can't seem to find the freeform value or definitions anywhere separate from the fully merged option value/defs. Can you confirm I'm not missing anything here?

I guess to do this I would have to write my own types.submodule equivalent (e.g. submoduleWithoutUndefs)? With a custom type I should be able to merge using evalModules but filter out any undefined options 🤔

Seems similar in principle to the types.record proposal in #257511, although I'd need optional and nested fields which I think is out of scope for that one.

00:34:48
@mattsturg:matrix.orgMatt Sturgeon

I guess to do this I would have to write my own types.submodule equivalent (e.g. submoduleWithoutUndefs)? With a custom type I should be able to merge using evalModules but filter out any undefined options 🤔

Or maybe this wouldn't work, if evalModules itself is what merges the option+freeform defs together

00:43:33
@mattsturg:matrix.orgMatt Sturgeon

Seems it is: freeformConfig is evaluated here, but isn't exposed separately from config.

Would a PR be welcome to have evalModules include declaredConfig, freeformConfig and config separately in the evaluated result?

01:20:44
@mattsturg:matrix.orgMatt Sturgeon Or maybe returning both config and definedConfig, the latter having filtered out declared options that aren't defined 01:30:41
@purepani:matrix.orgpurepani joined the room.04:11:12
31 Jul 2024
@infinisil:matrix.orginfinisil

@mattsturg:matrix.org Immediate thoughts are that it might be a bit of a leaky abstraction, but maybe also not. Feel free to make a PR, but I can't promise to get to review it myself soon, but perhaps @roberthensing:matrix.org can :)

09:53:38
1 Aug 2024
@cleverca22:matrix.orgcleverca22 joined the room.12:53:32
4 Aug 2024
@traxys:familleboyer.netTraxys joined the room.13:40:51
@tacticaltaco:matrix.orgtacticaltaco joined the room.22:09:55
9 Aug 2024
@mattsturg:matrix.orgMatt Sturgeon

I've been playing around with this in this branch (current commit), but what I have now is infinitely recursive, because configs shape is changing based on options._module.definedOptionsOnly, but options itself depends on config.

Is this approach fundamentally flawed? Do you have any suggestions for working around the inf-recursion?

The immediate alternative that springs to mind is to pass both a config and a definedConfig to the modules and include definedConfig in the result, alongside config. This is more inline with my original proposal, but feels like a worse abstraction than having a _module.definedOptionsOnly option.

I definedOptionsOnly could also be an evalModules argument instead of an option, but that isn't really ideal either.

13:30:14
@mattsturg:matrix.orgMatt Sturgeon *

I've been playing around with this in this branch (current commit), but what I have now is infinitely recursive, because configs shape is changing based on options._module.definedOptionsOnly, but options itself recursively depends on config.

Is this approach fundamentally flawed? Do you have any suggestions for working around the inf-recursion?

The immediate alternative that springs to mind is to pass both a config and a definedConfig to the modules and include definedConfig in the result, alongside config. This is more inline with my original proposal, but feels like a worse abstraction than having a _module.definedOptionsOnly option.

I definedOptionsOnly could also be an evalModules argument instead of an option, but that isn't really ideal either.

13:30:54
@mattsturg:matrix.orgMatt Sturgeon *

I've been playing around with this in this branch (current commit), but what I have now is infinitely recursive, because configs shape is changing based on options._module.definedOptionsOnly, but options itself recursively depends on config.

Is this approach fundamentally flawed? Do you have any suggestions for working around the inf-recursion?

The immediate alternative that springs to mind is to pass both a config and a definedConfig to the modules and include definedConfig in the result, alongside config. This is more inline with my original proposal, but feels like a worse abstraction than having a _module.definedOptionsOnly option.

definedOptionsOnly could also be an evalModules argument instead of an option, but that isn't really ideal either.

13:31:39
@mattsturg:matrix.orgMatt Sturgeon *

infinisil Robert Hensing (roberth) Thanks for your support so far!

I've been playing around with the concept in this branch (current commit), but my current implementation is infinitely recursive, because configs shape is changing based on options._module.definedOptionsOnly, but options itself recursively depends on config.

Is this approach fundamentally flawed? Do you have any suggestions for working around the inf-recursion?

The immediate alternative that springs to mind is to pass both a config and a definedConfig to the modules and include definedConfig in the result, alongside config. This is more inline with my original proposal, but feels like a worse abstraction than having a _module.definedOptionsOnly option.

definedOptionsOnly could also be an evalModules argument instead of an option, but that isn't really ideal either.

15:12:07
10 Aug 2024
@mattsturg:matrix.orgMatt Sturgeon

I've opened a draft PR that does it as an evalModules arg, so it actually works without inf-recursion. I detailed this limitation in the PR description. Any feedback would be greatly appreciated!

https://github.com/NixOS/nixpkgs/pull/333799

23:30:29
13 Aug 2024
@khaneliman:matrix.orgAustin Horstman joined the room.22:45:20
14 Aug 2024
@roberthensing:matrix.orgRobert Hensing (roberth) Matt Sturgeon: would you (or anyone I guess?) be interested in completing types.record from https://github.com/NixOS/nixpkgs/pull/257511? I don't have much time for this kind of thing due to other responsibilities recently 14:41:16
@mattsturg:matrix.orgMatt Sturgeon

I also don't know how much time I can dedicate to it. I had looked at it before when exploring solutions to https://matrix.to/#/!wfudwzqQUiJYJnqfSY:nixos.org/$mVuETvj4dPJNF6ZUdVEVvWmp07L5G3X-6y0bk-NmCP4?via=nixos.org&via=matrix.org&via=nixos.dev, however I came to the conclusion it is an interesting (and useful looking) type, but not a viable solution to the problem we have in nixvim.

I'll attempt to clarify a little in my response to your (very helpful) feedback in #333799.

14:45:44
@roberthensing:matrix.orgRobert Hensing (roberth)ohh saw the OP but glossed over the matrix thread - well good to have the context in github as well I guess14:50:44
@mattsturg:matrix.orgMatt SturgeonDon't blame you, it ended up being a long thread (as usual!)14:51:11
@mattsturg:matrix.orgMatt Sturgeon

Thanks again Robert Hensing (roberth) for your feedback and for reminding me of your existing proposals!

I've posted my initial thoughts on github. And further;

Reading through your simple/minimal module eval proposal, I think that's a great solution provided defining config from outside the simple-module type looks the same as defining config for a submodule type; i.e. many of the features you mention arent supported (mkIf for instance) still work, but are handled in the "host" module system before evaluating the resulting configured modules.

Enforcing one module/option per attr level (i.e. no nested options) sounds like a reasonable simplification too.

My main concern is that "perfection" here may be acting as the enemy of "good"; i.e. your proposal is great, but will be much more effort to actually get merged into nixpkgs.

From a different perspective, there's also some simplicity in not reinventing the wheel here, just to support one small feature (config without undefined opts). While we could see this as an opportunity to design a better/faster system, we could also just use the small change for now and consider in the future how it can be improved/replaced. 🤔

15:19:50
@mattsturg:matrix.orgMatt Sturgeon

Hm, I'm not sure why I was under the impression that the record type was restricted to being flat (and can't contain sub-options or sub-records, I guess). I assume the wildcard type could also be set to something like attrsOf anything to allow recursive merging?

If we can define nested optionalFields and recursively merged wildcards I think it fits nixvim's needs.

15:29:31
@mattsturg:matrix.orgMatt Sturgeon *

Hm, I'm not sure why I was under the impression that the record type was restricted to being flat (and couldn't contain sub-options, sub-records, sub-fields?). I assume the wildcard type could also be set to something like attrsOf anything to allow recursive merging?

If we can define nested optionalFields and recursively merged wildcards I think it fits nixvim's needs.

15:30:22
@roberthensing:matrix.orgRobert Hensing (roberth)Yeah records can have any type in their fields, including other records. It's simpler, lazier and more efficient that way.16:28:23
@nbp:mozilla.orgnbpI have no time this week, I might give it a look next week if needed.16:39:28
@mattsturg:matrix.orgMatt Sturgeon I'll play around with adding optionalFields to types.record, won't have anything "finished" today though. I believe after that it's just adding docs and getting reviews? 16:42:06

Show newer messages


Back to Room ListRoom Version: 10