!wfudwzqQUiJYJnqfSY:nixos.org

NixOS Module System

141 Members
28 Servers

Load older messages


SenderMessageTime
31 May 2025
@bew:matrix.orgbew *

Hello!

I am making a custom module system, and I have set _module.args.foobar = mkOverride 1000 "something".
I'm trying to use eval.extendModules and override the _module.args.foobar with a value with higher priority (by 1).
In my case I cannot just hardcode 999 here because the extendModules might be called multiple times, thus I need to override foobar multiple times with priority 998 then 997, etc...
Currently I do this by keeping track of the previous priority manually out of band (I re-implemented a kind of extendModules myself before discovering that it exists 👀), but I recently discovered highestPrio which would allow me to find the previous prio directly on the last module eval.

I tried finding the highestPrio field of _module.args.foobar using eval.options._module.args.foobar.highestPrio but it's saying that foobar doesn't exist here.
It kind of make sense to me because foobar is not an option, it's really part of the config at this point, but then is there still a way to access the priority from module eval?

What am I missing? 🤔

14:00:51
@mattsturg:matrix.orgMatt Sturgeon

Options have highestPrio (and other) attributes, however in this case _module.args is the option, not _module.args.foobar.

foobar is an attribute of _module.args' value.

You may find it helpful to inspect this in nix repl.

In this case you can use lib.modules.mergeAttrDefinitionsWithPrio to get the priorities of each attr of _module.args; there's an example of this in the nixos/modules/misc/nixpkgs.nix module.

19:03:54
1 Jun 2025
@bew:matrix.orgbewI see, thanks a lot for the answer! In the end I went with a custom option to store some state about the current eval, which allows me to directly be able to access highestPrio on those options 👍10:11:25
@bew:matrix.orgbew* I see, thanks a lot for the answer! In the end I went with a custom options to store some state about the current eval, which allows me to directly be able to access highestPrio on those options 👍10:11:35
@mattsturg:matrix.orgMatt Sturgeon

Awesome. That sounds more idiomatic!

Just a general design titbit: extendModules is more efficient when you don't read anything from the extended configuration.

Due to laziness, extended module evals don't actually need to be fully evaluated, so if you only read from the "final" extended configuration, then you don't need to also spend time evaluating the other ones.

10:18:21
@bew:matrix.orgbew* I see, thanks a lot for the answer! In the end I'm going with a custom options to store some state about the current eval, which allows me to directly be able to access highestPrio on those options 👍11:39:28
@seanthw:matrix.orgSean Thawe joined the room.23:48:32
2 Jun 2025
@bew:matrix.orgbew

Yes, I'm quite happy with what I managed to do ✨
Basically I made a system where I can easily eval an initial config, then call theconfig.lib.extendWith somemodule that returns a new config with the somemodule applied on top.
This module can access the previous config if it needs it, and the extendWith can be done on any config 'instance' ❤️
https://github.com/bew/dotfiles/blob/main/nix/kit-system/tests.nix if you want to take a look

I use this in my dotfiles to make mini module systems to configure nvim/zsh/tmux, and incrementally enable various flags for different flake outputs..

00:33:01
@bew:matrix.orgbew *

Yes, I'm quite happy with what I managed to do ✨
Basically I made a system where I can easily eval an initial config, then call theconfig.lib.extendWith somemodule that returns a new config with the somemodule applied on top.
This module can access the previous config if it needs it, and the extendWith can be done on any config 'instance' ❤️
https://github.com/bew/dotfiles/blob/main/nix/kit-system/tests.nix if you want to take a look

I use this in my dotfiles to make small independent module systems to configure nvim/zsh/tmux, and incrementally enable various flags for different flake outputs..

00:34:14
4 Jun 2025
@rob.sliwi:matrix.orgrobsliwi changed their display name from Robert Sliwinski to robsliwi.18:30:25
6 Jun 2025
@creepinson:matrix.orgTheo Paris left the room.00:18:42
@sportshead:matrix.orgsportshead joined the room.18:45:00
7 Jun 2025
@deeok:matrix.orgmatrixrooms.info mod bot (does NOT read/send messages and/or invites; used for checking reported rooms) left the room.22:32:07
@deeok:matrix.orgmatrixrooms.info mod bot (does NOT read/send messages and/or invites; used for checking reported rooms) joined the room.23:25:32
9 Jun 2025
@sigmasquadron:matrix.orgSigmaSquadron joined the room.13:06:30
@spaenny:tchncs.deSpaenny changed their display name from Spaenny to Philipp.20:46:30
16 Jun 2025
@brisingr05:matrix.orgBrisingrRedacted or Malformed Event07:00:33
@ygt:matrix.orgnadir left the room.21:50:42
17 Jun 2025
@jopejoe1:matrix.orgjopejoe1 (4094@39c3) changed their display name from jopejoe1 (4094@eh22) to jopejoe1 (4094@GPN23).12:06:51
22 Jun 2025
@ss:someonex.netSomeoneSerge (back on matrix) changed their display name from SomeoneSerge (UTC+U[-12,12]) to SomeoneSerge (Ever OOMed by Element).12:14:58
23 Jun 2025
@isabel:isabelroses.comisabel changed their profile picture.15:36:50
27 Jun 2025
@nbp:mozilla.orgnbp changed their display name from nbp to nbp — PTO.17:25:55
30 Jun 2025
@atagen:imagisphe.reatagen joined the room.03:04:43
2 Jul 2025
@mtheil:scs.ems.hostMarkus Theil joined the room.13:30:44
4 Jul 2025
@majiir:matrix.orgMajiir Paktu joined the room.21:28:45
7 Jul 2025
@nbp:mozilla.orgnbp changed their display name from nbp — PTO to nbp.13:12:04
8 Jul 2025
@djsushi123:matrix.orgMartin Gaens joined the room.09:11:18
@djsushi123:matrix.orgMartin GaensHey guys, I am trying to modularize my system, but there's one thing that I can't grasp. When you see everyone using Nix modules to split their configs, they almost always have their home manager configuration separate from their system configuration. I mean, it makes sense 95% of time, however, for some programs, like for example Hyprland, if you want to use Home Manager to manage Hyprland, you need the system module enabled as well. Basically everyone I've seen simply has a hyprland.nix config file both in the home-manager config as well as the system config. However, this means they're decoupled. If I am choosing which modules to enable inside my host, I have to think about enabling both my user hyprland module as well as my system hyprland module (which are in different parts of my dotfiles, since one of them is inside the home-manager configuration directory and the other one is inside the system configuration directory). How do I properly manage this sort of thing?09:17:03
@nbp:mozilla.orgnbp

Martin Gaens: I have a home-manager config which is either managed on its own or within NixOS, which I use across 2 different computer. I am using the extraSpecialArgs in flake.nix or home-manager.users.nicolas._module.args when embedded in a NixOS configuration, to set some configuration managed externally.

Note, there is nothing about special args, I might have as well set an option by adding an extra module in homeManager's flake.nix and done the same within the configuration embedded in NixOS.

09:25:23
@djsushi123:matrix.orgMartin GaensThanks for your reply. I am quite new to this; I'm not sure I understand. Do you mean you have some externally-managed configuration, which you pass both to your home-manager config as well as to your system config, and then, make decisions in those configs based on the global configuration?09:43:25

Show newer messages


Back to Room ListRoom Version: 10