Declarative deployment powered by Ansible and Nix
I've been working towards a fully declarative userspace setup for some time now. I do a significant amount of development on remote, sometimes short-lived environments and, honestly, I don't want to ever run a install script again if I can help it. Although I'm not fully there yet because of a few hard to tame dependencies (looking at you, neovim plugins!), Nix and Home Manager have all but gotten me to the coveted 100% declarative holy grail.
My end goal was to have a setup I could point at a new SSH-accessible machine and then shortly have everything I care about the most set up comfortably and without any interaction, and it's now a reality.
Previous iterations have been worked on in private, but I've finally cleaned it up enough that I'm comfortable with it now living in a public repository. I've learned a lot from the examples of others so I think it's only right.
Bare minimum CLI-oriented features I always want at hand, powered by Home Manager. The associated configuration used to be a part of this project, but quickly became complex enough that it now lives on its own repository. As a bonus, a static version of the Home Manager configuration can now be quite easily downloaded and used in standalone fashion.
- CLI
- Editors, basic utilities and development tools
- See more here
- Git
- Default user name and email
- Deployment of specified GitHub SSH keys
Those are intended for daily driver machines and include GUI applications and storage management. As of now, they're only applied to hosts in the daily-driver
group.
- Storage setup
- fstab mounts
- Linking of Steam compatdata from existing drives to local drive as per the official recommendation
- GUI applications
- Home Manager managed
- Flatpak installs
- System-level applications for things Flatpaks aren't able to handle well or at all
- Desktop Environments
- KDE Plasma
- Gnome
- Borg backups
The playbook sets up the base features for all hosts, and the extra ones for devices in the daily driver group.
It does so by using Ansible to deploy Nix through the Determinate Nix Installer, installing Home Manager through a custom role and having the latter do the heavy-lifting. Custom nix modules are copied to HM's config folder and imported in the home.nix
file, and home-manager switch
is then run as needed.
Requirements
If you have Nix installed, running the following command should get you into a development shell with all the dependencies you'll need. It also supports direnv for automated nix shell loading.nix-shell
Otherwise, try your hand at manually installing the python dependencies. This was tested with version 3.11
.
pip install -r requirements.txt
For a minimal, single host run (the trailing comma matters!)
ansible-playbook minimal.yml --inventory user@host, --ask-become-pass