!wfudwzqQUiJYJnqfSY:nixos.org

NixOS Module System

81 Members
20 Servers

Load older messages


SenderMessageTime
28 May 2024
@lehmanator:tchncs.deSam Lehman
In reply to @nbp:mozilla.org
Sam Lehman: Yes, evalModules should capture the whole tree of imports and deduplicated moduled key property.
However, if you are using flakes, and define a nixosModules within the flake.nix file, then the key attribute is not initialized to any value which can safely be deduplicated.

Not sure I follow.

Is key an intermediate attr of the loaded modules that doesn't make it into the resulting config? The default behavior breaks when I try to do what I described.

I'm also using https://github.com/divnix/std and I'd like to reference other profiles using cell.nixosModules.<name> before they reach my flake outputs.

12:34:18
@lehmanator:tchncs.deSam Lehman
In reply to @nbp:mozilla.org

Can a config block contain imports?

No, because imports are resolved in order to know what config definitions are contributing to the final configuration.

That's what I thought
12:34:43
@lehmanator:tchncs.deSam Lehman
In reply to @nbp:mozilla.org

You can create an option, which value is used as part of:

  config = mkIf (config.profile == "profile_42") { … };

I don't think this structure will work for how I'm trying to set my profiles up.

I might be able to create options.profiles and wrap each profile in their own module machinery, so the entire profile gets added to config and creates options.profiles.<name>.enable which controls activation of the profile. My only issue is handling imports.

12:38:48
@nbp:mozilla.orgnbp If you can just import them all, and use mkIf as described above. 12:40:43
@nbp:mozilla.orgnbpI doubt the above would not work, unless you have circular dependencies, as the code above is how NixOS is written, and it work, AFAIK.12:41:31
@nbp:mozilla.orgnbp * I doubt the above would not work, unless you have circular dependencies, as the code above is how NixOS is written, and it works, AFAIK.12:41:37
@lehmanator:tchncs.deSam Lehman My config eval errors for me if I enable two profiles that both import the same nixosModule, and if imports can't be gated by mkIf, I think I'm stuck with that problem. 12:45:32
@nbp:mozilla.orgnbp If they error while importing the same nixosModule, this is because the module system is unable to find a unique identifier to use as a key to deduplicate the 2 imports. 12:48:27
@nbp:mozilla.orgnbpThis happens with flakes which are just providing unnamed modules.12:48:50
@nbp:mozilla.orgnbp Using the key attribute next to config would help resolve that, or by moving the module to a file, and not importing it in the flake. 12:49:37
@lehmanator:tchncs.deSam Lehmanhmmm, is there a way to manually give it a key? I have no idea how this part works?12:49:43
@lehmanator:tchncs.deSam Lehman * hmmm, is there a way to manually give it a key? I have no idea how this part works12:49:50
@nbp:mozilla.orgnbp
nixosModule.profile_option = {lib, ...}: {
  key = "profile_option";
  options.profile = lib.mkOption { ... };
};
12:50:38
@lehmanator:tchncs.deSam Lehman If I collected all nixosModules from my inputs and set a key=<inputName>-<moduleName> attr, would this allow multiple imports of the same nixosModule? 12:51:11
@lehmanator:tchncs.deSam Lehman Is key an attr of modules that gets handled by lib.evalModules? Like I could specify a key attr inside a module definition, then import the same module in two places without error? 12:52:12
@nbp:mozilla.orgnbpI would say that an upstream issue, others would have the same problem as you, so you might as well fix it upstream.12:52:21
@lehmanator:tchncs.deSam LehmanIs there any documentation on this behavior?12:52:23
@nbp:mozilla.orgnbp key has been there since the beginning of the module system. 12:53:21
@lehmanator:tchncs.deSam Lehman What other attrs are used by lib.evalModules? I've seen imports, disabledImports, config, and options, but I didn't know there were others. Is there a place I can read about this behavior or do I just need to do a deep dive on the source of lib.evalModules? 12:54:49
@lehmanator:tchncs.deSam Lehman
In reply to @nbp:mozilla.org
I would say that an upstream issue, others would have the same problem as you, so you might as well fix it upstream.

Definitely something I'd expect others to have problems with, so I'd be down to contribute to a fix.

How would I go about debugging lib.evalModules?

12:57:06
@nbp:mozilla.orgnbpWhen I said upstream, I meant the flake you use as input.15:52:59
3 Jun 2024
@shalokshalom:kde.org@shalokshalom:kde.org left the room.16:23:46
4 Jun 2024
@infinisil:matrix.orginfinisil changed their profile picture.02:43:30
12 Jun 2024
@lorenzleutgeb:matrix.orgLorenz Leutgeb removed their display name Lorenz Leutgeb.00:31:19
@lorenzleutgeb:matrix.orgLorenz Leutgeb set their display name to Lorenz Leutgeb.00:32:52
16 Jun 2024
@h7x4:nani.wtfh7x4 joined the room.01:15:19
18 Jun 2024
@lehmanator:tchncs.deSam Lehman Can you conditionally set imports if the condition isn't based on the config arg? 20:54:51
19 Jun 2024
@djacu:matrix.org@djacu:matrix.orgTry it and report back 😛 But seriously what kind of conditional are you trying to use with imports?02:19:55
@nbp:mozilla.orgnbp No, it is not possible to conditionally import files using imports list, as it is computed ahead of the configuration. 09:40:48
@nbp:mozilla.orgnbp However, you can conditionally configure using mkIf. 09:41:29

Show newer messages


Back to Room ListRoom Version: 10