Stop Scripting Your Setup: Why You Should Try Nix Home Manager
We have all been there. You get a fresh laptop, or maybe you finally decide to wipe your current machine to start over. The first hour feels great, but then the reality sets in: you have to configure everything again.
Even if you are organized, it is a pain. You might have a repository of dotfiles and a few shell scripts you wrote three years ago to bootstrap your environment. You run them, and they mostly work. But then you start noticing the cracks. It doesn’t feel exactly like your other machine.
Maybe you start working and realize you are missing a specific config file for a tool you rarely touch but desperately need. Or perhaps you spent hours months ago researching an obscure flag to make a CLI utility behave a certain way, and now that setting is gone. Your muscle memory betrays you because your keyboard shortcuts aren’t quite right.
Then there is the issue of secrets. You can’t exactly check your SSH keys or API tokens into a public GitHub repository. So you end up manually copying files from a USB drive breaking any hope of full automation.
The problem gets worse if you juggle multiple machines, like a corporate MacBook for work and a Linux desktop at home. Keeping them in sync is a full-time job. Even if you manage to copy the config files, the underlying software might be different. You might have ripgrep version 13 on one machine and version 11 on the other, and you don’t realize the syntax has changed until your scripts fail.
There is a better way
This is usually where people talk about Nix and NixOS. If you haven’t heard of Nix, it’s a package manager and language that focuses on reproducibility. NixOS is a Linux distribution built entirely around this concept.
But here is the thing: you don’t need to switch your operating system to NixOS to solve these problems.
If you are on a company-issued MacBook, you obviously can’t install a new OS. If you are on Ubuntu and don’t want to reinstall everything, that’s fine too. You can install the Nix package manager on any Linux distro or macOS.
Once you have Nix, you can use Home Manager.
Home Manager allows you to manage your user environment using the Nix language. Instead of running imperative commands (like apt install, brew install, or manually edit text files), you describe the state you want your machine to be in.
You write a single configuration file that says “I want these programs installed,” “I want Git configured with this email and these aliases,” and “I want my shell to look like this.”
Why it solves the headache
When you use Home Manager, your environment becomes portable code. You can apply that configuration to a new machine, and it will pull down exactly what you specified.
Syncing is automatic. Because the configuration is text, you can version control it. When you make a change to your vim configuration on your personal machine, you push it to your repo. When you get to work, you pull the repo, run the Home Manager switch command, and your work machine is instantly updated to match.
No more version mismatches. Nix allows you to pin packages to specific commits. If you need a specific version of Node.js or Python to make your workflow function, you declare it. Home Manager ensures that exact version is installed, regardless of what the underlying operating system thinks is “current.”
Safe experimentation One of the best features is the ability to roll back. Let’s say you decide to try out a totally different shell configuration or a new terminal emulator. You change your config and switch. If you hate it, you don’t have to spend hours undoing your mess. You just switch into the previous status and your system is exactly how it was five minutes ago.
{ config, pkgs, ... }:
{
# User Metadata
home.username = "lorenzo";
# Package Installation
# This list installs software into your user profile.
home.packages = with pkgs; [
# CLI Utilities
ripgrep # Better grep
jq # JSON processor
fzf # Fuzzy finder
bat # Better cat
btop # System monitor
# Development
nodejs_20 # Pinning a specific version of Node
python3
# Fonts
fira-code
nerdfonts
];
# Program Configuration
# Instead of editing ~/.gitconfig manually, you declare it here.
programs.git = {
enable = true;
userName = "Lorenzo";
userEmail = "lorenzo@dvision.lab";
aliases = {
co = "checkout";
ci = "commit";
st = "status";
};
extraConfig = {
init.defaultBranch = "main";
pull.rebase = true;
};
};
# Configuring the shell
programs.zsh = {
enable = true;
enableAutosuggestions = true;
syntaxHighlighting.enable = true;
shellAliases = {
ll = "ls -l";
".." = "cd ..";
hm = "home-manager switch"; # Quick alias to update config
};
};
# Managing Raw Config Files
# For programs that don't have a Nix module or you don't want to use home manager, you can write the config file directly.
# This creates ~/.config/npm/npmrc
home.file.".config/npm/npmrc".text = ''
prefix=~/.npm-global
init-author-name=Lorenzo
'';
# Env variables
home.sessionVariables = {
EDITOR = "vim";
};
home.stateVersion = "25.05";
}
Now you can simply run
home-manager switchand it will set up this configuration for you.Handling the complex stuff
You might be wondering about the secrets mentioned earlier. The Nix ecosystem has tools like agenix. This lets you encrypt your secrets (like SSH keys or tokens) within your Git repository. They are safe to push to GitHub, but when Home Manager builds your environment, it decrypts them and places them exactly where they need to go on your machine.
It also goes deeper than just placing config files. There are modules like nixvim that let you configure complex software like Neovim directly through Nix. Instead of managing a fragile Lua setup that breaks when plugins update, you define your plugins and settings in Nix. It handles the dependencies and ensures the setup is coherent before you even launch the editor.
You can start small
The best part about Home Manager is that it doesn’t have to be all or nothing. You don’t need to declare bankruptcy on your current setup to try it.
You can install Nix and Home Manager today and just use it to manage one or two things, like your terminal prompt or a few CLI tools. It will happily coexist with your current imperative setup. You can keep installing things via Homebrew or
aptwhile you get the hang of it.
Over time, as you get comfortable, you can slowly migrate more of your configuration into Nix. Eventually, you reach a point where your entire digital life is defined in a single repository.
If you have been frustrated by the fragility of shell scripts and the drift between your computers, you have nothing to lose by trying this out. It turns the chore of system configuration into a solved problem.
