Chapter 3 - Home Manager
Home Manager (often abbrevieted to HM) is a project similar to NixOS, but for a specific user’s home folder. You use NixOS to manage system programs, configuration, etc. But Home Manager is programs and configuration for a specific user.
In this chapter we will…
- Add Home Manager as an input to our flake
- Learn how to add home manager modules
- Configure our
.face
file with home manager as an example
Adding Home Manager as an Input
First we need to add Home Manager as an input to our flake.
- In
flake.nix
, add a new attr set to theinputs
attr set calledhome-manager
(this can technically be called whatever you like, some people shorten this tohm
). This tells Nix two things:- We have an input named
home-manager
that should be fetched from thenix-community/home-manager
GitHub repo. - The Home Manager flake itself depends on
nixpkgs
as an input. To keep thing consistent, we tell Nix that input should follow ournixpkgs
input.
- We have an input named
- Now, we add
home-manager
as an argument to ouroutputs
function.
We now have access to home manager in our flake!
Telling NixOS About Home Manager
Now we need NixOS to access home manager.
In our modules
list we’ll add home-manager.nixosModules.home-manager
.
This will load additional options into NixOS to let us use home manager.
Configuring Home Manager
Now we’re ready to start using Home Manager within our NixOS config.
In config.nix
(or a separate module if you feel like it). Create a new attr set called home-manager
.
We’re going to fill this with our home config, replace YOURUSER
with your username below.
Here you can see we’re importing another file (../home/home.nix
). This file will hold a home manager module, these are very similar in appearance to NixOS modules so I recommend placing them in a different folder from modules
to differentiate them.
Create home/home.nix
and fill it with boilerplate for now.
- flake.nix
- flake.lock
Directorymodules/
- config.nix
- …
Directoryhome/
- home.nix Root HM Module
- …
Using Home Manager
First things first we’ll add these options, replace YOURNAME
with your username.
This will tell home manager your username and where your home folder is.
Example: Adding .face
To go into a quick use case for HM, we’ll add a file to the root of our home folder, .face
.
This file is used by some programs to know what profile picture to display on various UI components.
-
Place the image file in your config’s repo (I like to place any non-nix files in a folder called
res
, for resources).- flake.nix
- flake.lock
Directorymodules/
- …
Directoryhome/
- …
Directoryres/
- YOURIMAGE.png
-
Can’t forget to
git add
of course. -
In an HM module set up a link, replace
YOURIMAGE.png
with the name of your image file.
Run the VM again and check your home folder, you’ll notice a .face
symlink!
Directory/home/user
- …
- .face A symlink to the nix store!