Recently I've been doing a lot of OS swapping for a whole bunch of reasons that started with Pop OS! constantly messing up Grub's settings on updates. So I jumped from Pop OS! to EndeavorOS, NixOS in a WSL virtual machine & macOS. Trying to find an OS that suited my needs.
One thing that would seem obvious once you've jumped OS' a couple of times is that having to reinstall the programs, language compilers & servers and then configuring it all becomes a bit of a pain.
Previously I was just using a git repo for my .dotfiles, and a bash script that created a bunch of symlinks to configure the app and tools I installed. This worked wonders as I'd rarely if ever change OS.
I wanted to find another way where I could have a consistent package management experience and could run a single command and have everything up and running within a few minutes.
After doing some digging around I came across Home Manager. Home Manager is a user environment manager that uses the Nix package management system. It provides a way of declaring our local user environments with a single config file with reproducible results.
To get started we first need to install Home Manager. First, we'll need Nix
curl -L https://nixos.org/nix/install | sh
Check that Nix is installed with
nix
If it's installed we can then update the Nix package manager channels with the home manager channel. This will give us access to the unstable version of Home Manager. If you require a stable one head to the home manager site and check for the latest version.
nix-channel --add https://github.com/nix-community/home-manager/archive/master.tar.gz home-manager
nix-channel --update
Now we can install Home Manager itself.
nix-shell '<home-manager>' -A install
Again you can test it has been installed by running
home-manager
Home Manager will setup a new configuration in ~/.config/home-manager/home.nix and it will look something similar to the example below.
{ config, pkgs, ... }:
{
# Let Home Manager install and manage itself.
programs.home-manager.enable = true;
# Home Manager needs a bit of information about you and the
# paths it should manage.
home.username = "cubixle";
home.homeDirectory = "/home/cubixle";
# This value determines the Home Manager release that your configuration is
# compatible with. This helps avoid breakage when a new Home Manager release
# introduces backwards incompatible changes.
#
# You should not change this value, even if you update Home Manager. If you do
# want to update the value, then make sure to first check the Home Manager
# release notes.
home.stateVersion = "23.11";
}
Let's add a package
{ config, pkgs, ... }:
{
# The home.packages option allows you to install Nix packages into your
# environment.
home.packages = [
pkgs.git
];
programs.git = {
enable = true;
userName = "cubixle";
userEmail = "contact@cubixle.me";
delta = {
enable = true;
options = {
navigate = true;
line-numbers = true;
};
};
extraConfig = {
gpg = {
format = "ssh";
};
url = {
"git@github.com:" = {
insteadOf = "https://github.com/";
};
};
url = {
"git@gitlab.com:" = {
insteadOf = "https://gitlab.com/";
};
};
};
};
}
Now run
home-manager switch
and now try running git
git version
Now you have a simple setup you can expand on it by installing more programs and even services.
You can find more packages by looking in the home-manager git repo on github