Background
My journey towards using Home Manager (HA) started years ago when I wanted an easy way to set up all my programs and configuratoin when I got reset my laptop. This started out as bash script, since that is what you use when you want to automate commands. But this became unwieldly. I ported the script to ansible and added a vagrant box to test it with. This worked well for a while. I had it setup my shell, installed programming languages, and general applications like firefox. But this too was annoying, especially when a task depends on changes to the shell that the previous task made. Finally I came across Home Manager.
I had used nix briefly at a previous job. The team responsible for the cloud infrastructure used Nix to make sure everyone had the same version of everything. I kind of knew what Nix did in a hand wavy sort of way. Declerative environments with only the dependencies you need. At the time I found it cumbersome. But after trying to write a setup script for my laptop, the thought of if it works once it will work always was appealing.
How I use Home Manager
At the time of writing I am running EndeavourOS with Nix and HA to manage my setup.
My HA config lives in a git repository that I clone to the default HA location of ~/.config/home-manager/
. Because HA manages my shell, I need to change the default shell of my user.
# /etc/shells
/bin/sh
/bin/bash
/bin/rbash
/usr/bin/sh
/usr/bin/bash
/usr/bin/rbash
/usr/bin/git-shell
/home/<user>/.nix-profile/bin/zsh # <-- Add this
After adding nix’ zsh as a valid system shell you change it with the chsh
command.
chsh -s /home/user/.nix-profile/bin/zsh
Now log out and log back in and I’m all set! The last time I did this install it took me around 15 minutes to get all my programs installed and up and running with my configs.
Now because I still don’t know how Nix works, and have yet too look into flakes, the main home.nix
will propbably look messy to someone who knows better. But this has been working for me. I\ve removed all examples and default configuration and just left the interesting parts.
|
|
I’ve only run into one issue when using this setup. I wanted to update the packages so I updated the channel and ran home-manager switch
and got an error. The channels were out of sync and refused to build. After much fiddling the fix turned out to be locking the version to 23.05
, you can see this on line 2. I will at some point put update it to a later version, and feel confident in doing so because I was able to recover from an error like this without having to start from scratch. The ability to rollback really saved me here!
Next there are some one off configurations allowing for non-free programs, allowing HA to manage fonts, and adding the applications it installs to the launcher. Then the list of packages. I put all the packages that don’t have a HA config here.
Finally all the programs that come with HA. I have split these up into their own directories to bundle the nix file with related dotfiles. For example here is the config for starship.
|
|
All of this configuration is written without really knowing Nix. I just follow what Appendix A. says. The language is not that complicated if you just use if for configuration.
Future plans
I am getting a new laptop once frame.work decides to ship my framework 16 preorder. I think I will stay on EndeavourOS for a little while, but I do want to try out nixos at some point. Maybe I will migrate my vps once I make the time to move it to Hetzner.
I also want to figure out what flakes are and rewrite my HA config to be one.