`error: infinite recursion encountered` when trying to make a `vars.nix` to set and read variables for systems

That’s because you are setting config.vars.mainUser = config.vars.mainUser in your vars.nix.

You dont need to provide access to the resolved values either. They are already accessible when defined in options. I do a similar thing for my config by passing vars to specialArgs in my flake.nix with my user details (e.g. userDetails), and then importing that arg into my module.

So I would suggest refactoring by incorporating vars.nix into your flake.nix. I get what you are trying to do, but it makes a lot more sense to incorporate those options into the specific modules that use that option unless you want to use specialArgs. Then, you can set the values for that option in something like a default.nix file.

Here is my configuration if you want to reference it: nixos (I use the special args in this file)

1 Like