Unified Modules For Your Nixfiles

7 points by knl


wantguns

I ended up following the same pattern an year ago :) https://github.com/wantguns/dotfiles

i was able to expose an interface/attrset for each of my host to opt in to my wireguard mesh based on the common nix state, which was fun

ThinkChaos

I've also been putting HM and OS modules in the same file and am really pleased with it. Haven't had a reason to change in 5+ years, and happy to see others discovering the same!
I think in the open source world I've first seen it implemented by flake-aspects & den.

Inspired by languages with opinionated module systems, I'm enforcing each module's file path in the repo is the same as in the config (actually it's automated via lib.setAttrByPath). So modules/a/b.nix is always config.a.b.*.
That's a small constraint that's both freeing and allows automating more boilerplate setup: I can automatically get the classic cfg set to the current module's option values!
Simplifying a bit, the module exposing options.x.y is has an extra cfg arg that's automatically set to config.x.y.

Know When To Stop

Over time I've started to actually default to shared modules, just without options.
It feels a bit weird to commit code in a reusable module that actually has host specific values hardcoded, but doing it means that when I actually need to reuse I'm a step closer already and the path of least resistance is just to add a couple options, not copy-pasting, avoiding future headaches. Updating the host already using the module to use a couple new options is trivial.