llakala / nixos

My NixOS config
3 stars 1 forks source link

See if hostVars can be enforced to have all the same variables #13

Closed llakala closed 1 week ago

llakala commented 3 months ago

Currently, hostVars are declared in multiple places with the same contents. This isn't the best way of doing things, since it can be easily broken by inconsistent application. Ideally, hostVars would be enforced somehow to be all the same.

This could possibly by done by importing specific variables FROM each hostVars, so that they're each expected to provide all of them, and any missing will hopefully provide errors.

llakala commented 2 weeks ago

Found the true solution to this: just use the module system. We can declare a module that declares stuff like this (pseudocode, this isn't how you write an option but it gets the idea across):

options.vars.scalingPercent = mkOption 
{
    type = int;
    default = 100;
};
options.vars.username = mkOption 
{
    type = string;
    default = null;
};

And then each host could define values within vars like this:

vars.scalingPercent = 200;
vars.username = "emanresu";

Then, for accessing the vars values, we do it like this:

{ config, ... }:
gnome.scalingPercent = config.vars.scaling;

We could even do the cursed thing of aliasing config.vars to just vars, just like we do with hm. Something like this:

(lib.mkAliasOptionModule 
    ["vars"] 
    ["config" "vars"]
)