How to create user defined names/keys in NixOS modules?

i’ve been moving my nixos config/flake to using modules to define my own config options for easier use. however there is one thing i cannot seem to figure out how to do. how can i recreate how options like fileSystems.<name> (and by extension all options that are available under a key like this) work? what i mean by that is, how can i define an option, that does not have a predefined name, but can be named in the file my module is imported in? also what are these user defined keys actually called in this context?
once this is working i would also like to know how i can use the user defined key as a value for options nested inside. i mean the same way that the fileSystems options use the <name> as the mount point, when fileSystems.<name>.mountPoint is left null.

it should be possible, since nixos itself uses this a lot, i just don’t know what it is called and how to search for it on the internet. any help on this is appreciated.

thanks in advance : )

1 Like

Welcome to the forum! This is a great question, because the answer is unfortunately not documented in the Nixpkgs manual.

What you want can be done with lib.types.attrsOf <type>.

For an in-depth foray into the module system I recommend the monumental module system tutorial by @infinisil @proofconstruction and @asymmetric. Linked here: the section on nested submodules.

https://nix.dev/tutorials/module-system/module-system#nested-submodules

thank you very much for the hint! nix.dev in general seems like a very useful learning resource. unfortunately i’m not gonna be able to test it out for a bit, but i will come back to this topic if i have anything else.
thanks again :slight_smile: