!wfudwzqQUiJYJnqfSY:nixos.org

NixOS Module System

147 Members
30 Servers

Load older messages


SenderMessageTime
7 Jul 2024
@dminca:matrix.orgdminca joined the room.09:38:54
8 Jul 2024
@nbp:mozilla.orgnbp zrsk: By default, no, you can extend some option types such as enum and submodules, but you cannot substitute the type by another one. However, you can disable the module (using disabledModules = [ <path-of-imported-module> ]) and re-implement the same interface as the disabled module. 10:48:59
@nbp:mozilla.orgnbp disabledModules was introduced as a way to develop non-backward compatible changes without having the fork NixOS. 10:49:44
@aciceri:nixos.devzrsk nbp: Yeah I know about disabledModules, it would be nice if there was a way to disable single options and then re-implement them.
Anyway at the end I solved my problem (which was unrelated, my question here was due to a possible workaround I was considering). To be exact what I wanted to do was changing the default value for an option and I don't mean using mkDefault, I mean changing the value in options.foo.default without having direct access to where it was declared (I'm generating docs starting from imported modules but the default value for that option was a package that required an overlay I didn't want to apply, otherwise it gave an evaluation error)
12:27:43
@nbp:mozilla.orgnbp We do not have a way apart from disabledModules for replacing the default value for the documentation :/ 12:35:53
@aciceri:nixos.devzrsk
In reply to @nbp:mozilla.org
We do not have a way apart from disabledModules for replacing the default value for the documentation :/
That's not the end of world
12:41:53
@aciceri:nixos.devzrsk While I'm at it I've another question about the module system: why it isn't possible to set an option config.foo to a function of config.foo? 12:44:57
@aciceri:nixos.devzrskIn general it shouldn't lead to an infinite recursion12:45:23
@aciceri:nixos.devzrsk Or maybe yes, I'm not sure anymore...I remember thinking about this time ago. The example I was giving to myself was something like foo = f config.foo where f is the usual recursive factorial. But thinking about it now I can't see how I could express the recursion base case. 12:48:22
@aciceri:nixos.devzrsk But still I believe that even foo = g config.foo with g: _: 42 as the constant function would lead to an infinite recursion error (perhaps I'm wrong, haven't tried) 12:49:16
@aciceri:nixos.devzrsk * But still I believe that even foo = g config.foo with g = _: 42 as the constant function would lead to an infinite recursion error (perhaps I'm wrong, haven't tried) 12:50:03
@nbp:mozilla.orgnbp You are interested in making a fix-point within the module system. I never thought of it before.
It is possible to make a fix-point within the apply function of an option, which how submodules are implemented, but using the option it-self …
I doubt g = _: 42 would yield to an infinite recursion as config.foo would be evaluated lazify if the argument is used.
12:59:48
@aciceri:nixos.devzrsk

I doubt g = _: 42 would yield to an infinite recursion as config.foo would be evaluated lazify if the argument is used.

You are right, just tried

I guess I have to check how submodules are implemented

13:25:18
@ktemkin:katesiria.org[K]ate Temkin left the room.17:25:34
9 Jul 2024
@sbc64:matrix.orgsbc64 joined the room.16:49:13
14 Jul 2024
@tsomipa_ts:matrix.orgTsomipa_ts joined the room.18:55:59
15 Jul 2024
@dminca:matrix.orgdminca changed their display name from dminca to nixpkgs.17:29:06
@dminca:matrix.orgdminca changed their display name from nixpkgs to dminca.17:42:43
23 Jul 2024
@ezzobirbezziou:matrix.orgEzzobir Bezziou joined the room.08:21:01
26 Jul 2024
@glepage:matrix.orgGaétan Lepage joined the room.15:30:55
@mattsturg:matrix.orgMatt Sturgeon joined the room.16:39:44
27 Jul 2024
@brian:bmcgee.ieBMG joined the room.11:20:49
28 Jul 2024
@mattsturg:matrix.orgMatt Sturgeon

Question:
In a submodule with a freeformType, how can one access the freeform definition (and option metadata) separately from any sub-options?

I.e. get definitions, metadata and final merged value for the freeform definitions separately from option definitions.

Alternative:
Is it possible to configure a submodule evaluation to only merge "defined" options into the final config value?

Motivation:
In nixvim, we have several freeform "settings" submodules, and we directly pass the resulting config to a toLua generator.

Currently any sub-options defined will always show up in the resulting config, and we work-around this by having them default to null.

This has two main downsides:

  1. When filtering out nulls, we also filter out any explicitly defined nulls.
  2. When we have options at nested attr paths, we have to filter out the empty attr after we filter the null

Instead, I would like to have sub-options without a default and have them not show up in the final config if they are not defined.

I don't mind doing this manually, by merging the freeform value with any options.*.value where options.*.isDefined, but idk how to access the freeform value separately.

Follow up:
If I have to do this within the submodule, idk the best way to access the result from outside the submodule? I could declare an internal option definedConfig, but I'm not sure if I could avoid infinite recursion when merging the other option values into it?

Apologies for the long-form question!

20:01:34
@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

Show newer messages


Back to Room ListRoom Version: 10