Foray into NixOS and IaC

I have been working in the IT industry for the past 8 years as a technician with no real experience with programming as a whole. Roughly two months ago my frustrations with windows and imperative Linux systems on my devices hit a breaking point, which greatly motivated me to get into declarative and reproducible systems. What started out as a single configuration.nix file with gnome for just my laptop quickly spiraled into using hyprland with minimal services, flakes, home-manager, and eventually building up a simple modular system for easy deployment of new devices and users. I’m officially hooked and fully believe that systems like this are the future, putting myself in a place where I want to put a heavy focus in transitioning from a technician position towards managing IaC, potentially on the cloud.

At the end of the day I am still new to this, and I have a lot to learn. I am happy to hear any feedback or thoughts on what I have managed to do up until this point. :slight_smile:

5 Likes

Nice and clean! Definitely get used to agenix, I suggest moving to agenix-rekey or clan vars as you start to do crazier things, but agenix is solid. Your configs are honestly a lot more organized than mine right now but I do have one piece of wisdom I can share: make a directories.nix file and have it point to all your important folders:

{
  users = ./users;
  hosts = ./hosts;
  modules = ./modules;
  assets = ./assets;
}

Then provide it in your args:

specialArgs = { dirs = import ./directory.nix; inherit inputs user hostName; };

Now instead of doing the ../ dance. For example here:

{ config, pkgs, inputs, ... }:
{
	imports = [
		./hardware-configuration.nix
		../../modules/nixos
	];

You can use dirs:

{ config, pkgs, dirs, inputs, ... }:
{
	imports = [
		./hardware-configuration.nix
		(dirs.modules + "/nixos")
	];

I also tend to use a map function when importing many modules. And I’m sure there’s a neat way to do this with with by generating dirs.* from a directory lookup, but I’ll leave those as exercises for the reader. The point is, this pattern has saved me a lot of grief I previously experienced refactoring and moving modules around.

1 Like

@ttamttam1 Thank you! This is incredibly helpful and I imagine it will save me a lot of headaches as my modules get adjusted and moved around.