!wfudwzqQUiJYJnqfSY:nixos.org

NixOS Module System

176 Members
39 Servers

You have reached the beginning of time (for this room).


SenderMessageTime
21 May 2025
@oddlama:matrix.orgoddlama changed their display name from Malte to oddlama.17:42:04
@ss:someonex.netSomeoneSerge (utc+3) I see that nixos/lib and nixos/modules use normal path values in _file (except for modulesPath = toString ./eval-config.nix), but somehow in man configuration.nix we get relative paths without hashes? How does that happen 17:48:12
@mattsturg:matrix.orgMatt Sturgeon

path values only get copied to the store when used with string interpolation (e.g. "${./some/path}"). If you instead stringify them with toString, then they are not copied.

E.g.

"${./foo}"
=> "/nix/store/r1l6z113nnzx44iiqp728f50lpczp577-foo"

toString ./foo
=> "/home/matt/foo"

./foo
=> /home/matt/foo
17:53:58
@ss:someonex.netSomeoneSerge (utc+3) Ohhh so nixos/modules actually does pass strings around and not paths? 18:00:37
@ss:someonex.netSomeoneSerge (utc+3)
nixos/lib/eval-config.nix
71-  pkgsModule = rec {
72:    _file = ./eval-config.nix;
73:    key = _file;
18:02:08
@ss:someonex.netSomeoneSerge (utc+3)This is 100% a "path"18:02:19
@ss:someonex.netSomeoneSerge (utc+3)
$ man configuration.nix
...
       nixpkgs.pkgs
...
           Declared by:
               <nixpkgs/nixos/modules/misc/nixpkgs.nix>
18:03:29
@ss:someonex.netSomeoneSerge (utc+3) So there is some magic happening that makes this ./eval-config.nix into a string that is relative to.... hmmm parent of the checkout 18:03:57
@mattsturg:matrix.orgMatt Sturgeon IIRC specialArgs.modulesPath is removed if it is a prefix of the stringified _file. 18:05:42
@mattsturg:matrix.orgMatt Sturgeon

actually does pass strings around

No, but when rendering files in errors, docs, etc they are stringified using toString

18:06:40
@spaenny:tchncs.deSpaenny joined the room.18:21:49
23 May 2025
@ss:someonex.netSomeoneSerge (utc+3) Btw that magic was in pkgs/ in nixosOptionsDoc 22:32:42
@ss:someonex.netSomeoneSerge (utc+3) Next one! Given (evalModules {...}).options and a path in options, is there a ready tool to tell which definition (with location) won the priority? I see I can access definitionsWithLocations which is an unfiltered list, and, to further complicate things, in case of an attrsOf option there's just the top-level list, which doesn't directly relate paths under the option to definitions or locations. 22:36:26
@mattsturg:matrix.orgMatt Sturgeon

For simple/flat options, all the definition listed in the option are the ones that "won" the priority.

Specifically, all of opt.definitions and opt.definitionsWithLocations have opt.highestPrio.

That's because most wrappers like mkIf, mkMerge, mkOverride, and mkOrder are resolved before creating the option's definitions list.

However, this is only done for the option's definitions (i.e. the top-level). Wrappers on nested attrs are applied by the option's type when it merges the option's definitions.

I don't know of an "easy" way to filter for definitions of a specific attr on an attrsOf type.

There are some functions like lib.modules.mergeAttrDefinitionsWithPrio, so maybe something similar exists or could be written that exposes definition location for attrsOf sub-attrs?

If you were dealing with a submodule, and had an explicit suboption declared, then you could access the suboption's definitions within the submodule eval. E.g., you could expose them to the wider module eval by defining an internal option in the submodule.

22:48:40

Show newer messages


Back to Room ListRoom Version: 10