I’m relatively new to NixOS and am diving into the world of its powerful configuration management. After exploring the basics, I’m eager to deepen my understanding and adopt best practices for managing configurations effectively.
I have a few specific areas where I’d appreciate some guidance:
Configuration Structure: What is the recommended approach for structuring a NixOS configuration file? I’m particularly interested in understanding how to organize multiple services and configurations to maintain clarity and ease of management.
Modular Configurations: How do you handle modular configurations in NixOS? I’ve read about using multiple Nix files and imports, but I’m unsure about the best practices for managing dependencies and ensuring that changes in one module don’t inadvertently affect others.
Version Control: How do you integrate NixOS configurations with version control systems like Git? What are some strategies for tracking changes and rolling back configurations if needed?
Testing Configurations: What methods do you use to test configurations before applying them to a production environment? Are there any tools or techniques within NixOS that can help with testing and validation?
I’m excited to learn more and appreciate any insights or resources you can share.
There does not seem to be a “standard” approach, so here is my folder structure - feel free to take what works for you. My personal aims are to minimise the number of places a config is set and make it fairly obvious which file to look into for a config. It is not perfect!
common - apps, packages set by programs= and a file for anti-virus
desktops - files common to my desktops such as kde config, apps, nfs shares
servers - same as desktops for common aspects on servers (usually non-GUI machines rather than server)
hosts - sub folders for each host containing host-specific apps etc.
users - config files for each user available
hardware - folders for AMD, Intel, Raspberry Pi. Contains common aspects of hardware such as openGL/CL for amd-gpu and intel-gpu. Machine specific hardware aspects are under hosts
Individual files that may end up in perhaps a desktops or hosts folder include services.nix for services and networking.nix for NIC configuration. This is the awkward aspect. It means that a package of config element can occur in multiple places. I have wondered about an “if-then” style to have all networking in one file, but that just moves the complexity.
The biggest challenge I have found as a less experienced user is ensuring that files are called - it can be quite easy to miss one out. I order my includes in a common way to try and minimise this issue.
Hope this gives you some ideas - let us know what you choose!
For a structural template, Ryan Lim suggests Mysterio’s structure. I hesitate to post my structure, because it is lame, but just do something simple and logical and don’t get too hung up on it if you are new to Nixos. I learn by cloning other people’s configs, and Yazi-ing through them, which allows you easily to see the structure and levels. Gaditone/Nixos_Dotfiles - Codeberg.org
There is an app called NH (Vimjoyer does a video on it)
The flake rebuild command is:
“nh os switch .”
But if you add in the ask flag, it asks you if you want to rebuild.
“nh os switch --ask .”
(The standard flag is ‘test’ → nixos-rebuild test)
For configs & version control.
Libre Phoenix has a video on rollbacks.
I’ve done a couple of git rollbacks.
e.g. “git checkout HEAD^” to return to the previous version.
Of course git can get quite knotty, so best to understand exactly what you are doing there.
Chris McDonough has a video on system configurations. I think this is it…