I was discussing ideas on how to differentiate between multiple configs in a modular nix- or NixOS-configuration with @fricklerhandwerk the other day and since we didn’t seem to have found a really good parameter to differentiate between them, I wanted to let the community participate.
I’ve seen configs, were the differentiating factor was the $hostname. I currently do something like that myself, in that I have set up a fish-abbreviation, that runs nixos-rebuild switch -I nixos-config= with the $hostname passed as a parameter.
Making nixos-rebuild switch dependent on a fish-abbreviation doesn’t seem like a clean way. That’s why I wanted to post this thread. There are a few other methods, that I thought about:
The value of /etc/machine-id can be used to identify a particular Linux installation. It’s basically a random hex-number, that is generated by systemd during the installation-procedure or during the first boot after installation. However using this number, I would have to learn a few digits of the hex-number to actually know, which configuration to edit, if I wanted to make changes. It’s not very informative.
Another idea was to use the values of the files in /sys/devices/virtual/dmi/id/. They contain information about the hardware of the system at hand. For example /sys/devices/virtual/dmi/id/product_family contains ThinkPad X1 Carbon 5th in my case. The problem with these files is, that they are apparently too short to be read by builtins.readFile. What does work is to compare the hash of the file, for example using
builtins.hashFile "md5" /sys/devices/virtual/dmi/id/product_family
but then I would have some hash-value that again wouldn’t be very informative.
@rycee suggests linking the config file of the current host to /etc/nixos/configuration.nix (in the case of NixOS), but this would require manually creating the links. I would want to automate the installation-procedure and adding new configs as much as possible.
My personal config is GitHub - tim-hilt/nixos: My configuration-files for NixOS. It’s not very clean by any means and is under heavy construction at the moment. I’m still a “new” NixOS-user atm, so bear that in mind.
I’m happy for every idea and suggestion regarding this topic! Is there maybe some unknown (to me) consensus on modular config-files? Is there simply a cleaner way than the ideas I’ve explained above?