When developing a new system I regularly find myself struggling with details that differ between a deployment in a VM (e.g. through the awesome nixos-shell or a nixops virtualbox deployment) and a real productive deployment.
Usually it’s just a string or a simple boolean that needs to be replaced or altered to fit the environment:
That means I’d have to additionally create an option with every possible variable I’d use, so everytime I find a new value that differs, I’d have an additional point where I have to change it, instead of just the point where I use it and the actual machine definitions.
Well you can also have a single option of type attribute set that contains all variables. Then you would not have default values or type-checking but a little less to type.
So I’d basically just declare a module variables = mkOption {type = types.attributes} and then just set and use variables.baseDomain = “whatever” and access them that way as well.
That sounds good. Thanks!
If I had to do it myself, I would make the import unconditional, and add the condition in the module itself, like most modules do. It would be easier if you had a minimal (non) working example
It’s impossible to make imports depend on anything from config, because everything in config depends on imports itself (since any module can change any other option). This is where the infinite recursion comes from.
You can think of the module system working like this:
First all modules are resolved by recursively looking at imports
Then all options are determined by looking at options of all the collected modules
Finally the resulting config is evaluated by combining all the config definitions according to the options that were defined
And generally these have to happen sequentially. Especially step 1 has to happen before 2 and 3.