Reusable variables?

I have set up a flake-based config which imports files similarly to GitHub - Misterio77/nix-starter-configs: Simple and documented config templates to help you get started with NixOS + home-manager + flakes. All the boilerplate you need!
I have split the configuration in many files which are imported in combinations, depending on what host they are supposed to be applied on
But sometimes I want in the individual files reuse variables that I only define once. For example, I may want to set my email address multiple times in the config for various services that should notify me if something fails. What I would like to do is define it once and somehow refer to it or pass it along.
How would I best do that? Is there an example somewhere that I can look at?

You can create your own option, then access the value through config, or you can set = "data"; and then put foo in the argument list at the top of whatever modules use that piece of data.

Thanks! I think the second choice, using _module.args , suits me well. I googled around a little and did not find it authoritatively documented. Is this an internal mechanism that is not intended for public use. Or what does the underscore mean?

Indeed the underscore is often used as an indicator for hidden/internal API.

Still, _module.args has been a long time the suggested replacement for the deprecated and now removed extraArgs. This was only findable by reading the nixosSystems source code, as it is so often for the nix world, sadly.

1 Like