Hi! This the equivalent to a dotfiles repository. It contains most (hopefully all) my personal configuration.
It's evolved significantly over the last 10 months since I first adopted NixOS. As with many others, I have overengineered
it to hell and back. If you, like me, are browsing random people's nixOS configurations to see how the hell to make yours,
go ahead! Here's a little overview.
The entry point. The bulk of it is the mkHost function, that helps create
new hosts out of configuration files. It's a little extensive as I make some
adjustments to every host to suit my needs:
- Every host is built on the same instance of
pkgs, with unfree packages enabled and the unstable branch of nixOS packages available aspkgs.unstable. This way I can stay on nixOS stable but still have access to recent packages. It allows for less overhead when updatingflake.lockso it's easier to stay up to date. - Top-level data, such as the flake's version, the local path (explained later) and flake packages
are passed to the modules through configuration. I don't use
specialArgsbecause it adds an unnecessary new parameter, and if one day I want to expose my modules to other flakes it wouldn't work.
I define most configuration through module options. I try to not make redundancies, i.e if a new option only enables a single NixOS system option, it's better to just use that directly. A lot of them just enable and configure programs to my preferred defaults. However, I do have a good system (in my honest opinion) to manage configuration files.
Home manager, is, well... home manager. I don't really like it that much. However, I like declaring my configuration from nix and symlinking it to my home directory. It's all I want to use it for.
The critical flaw with it is that it requires a rebuild every single
time you want to change your dotfiles, which is not instant, especially if it's tied to the system configuration.
A default configuration.nix as generated by a clean NixOS install takes about 15 seconds to switch to.
However, as soon as you add new packages, or god forbid a flake overlay, that can jump to 30 seconds
for just changing a single config file. That's unacceptable in my eyes, especially
if I'm configuring a new tool for the first time.
For that reason, I've chosen to symlink my configuration files directly to the local version
of this repository. For that, I need to get an environment variable that contains the path to
the local configuration. And as such, every time you want to work with this flake
you'll need to pass --impure. In my opinion, it doesn't matter. But, it might
introduce some funkyness later on. An option would be to define where the configuration
should always be located (e.g /etc/nixos).
Anyway, the relevant code that helps me do that is in modules/home.nix.
For my convenience, I have put my secrets in the repository via a (private) submodule. While the secrets are encrypted on the repo, it still isn't a good idea to put them publically. Also, some nix configuration (such as networks) can't be encrypted so that goes there too. I've tried to write the config there such that the repository should work without it without many changes.
I didn't need to complicate things. I don't even have multiple hosts yet! If you're new to NixOS, looking for inspiration, finding all of these super large configs with library functions and dynamic loading of files and whatnot, and feeling intimidated, just remember there's NO need to make it complicated. I did it out of a desire to learn a new language and create my own tooling, not to make a convenient or easy to mantain configuration system (although it is one my goals for this). My advice would be to write the least amount of configuration that suits your needs. If your needs outgrow your configuration, you can make it ONLY as big as you need. And well, of course, if you find it fun to write Nix or make a cool config, go ahead. It'd be hypocritical of me to say otherwise :p
A shoutout to the Nix community and all the wonderful people who post their configs
online. Without them, this repository would just be a configuration.nix and hardware-configuration.nix.
Here's a couple of repositories that I used for inspiration and copy-pasting, in no particular order.
sioodmy/dotfiles (link)
One of the very first configs I checked out. It's completely rewritten now, to be much simpler. Would recommend checking it out, as it proves overcomplicating things is not necessary.
hlissner/dotfiles (link)
A lot of this project's structure is entirely copied from them. It's a good repo!
BirdeeHub/nixCats-nvim (link)
A great nvim package manager for Nix. Exactly what I wanted in an nvim config, as nixvim and nvf are just not the way I want to configure it. I'm still new to neovim and vim in general, so it's been extra hard to get it working but I like it a lot so far.