Installation
Enable flake(optional)
It's recommended to use home-manager together with flake enabled. If you haven't enabled flake yet, do the following for single user:
echo 'experimental-features = nix-command flakes' >> ~/.config/nix/nix.confor the following for multi-users:
sudo sh -c 'echo "experimental-features = nix-command flakes" >> /etc/nix/nix.conf'NOTE
This documentation only uses home-manager with flakes.
Installation
Add channel for home-manager
- Unstable
nix-channel --add https://github.com/nix-community/home-manager/archive/master.tar.gz home-manager && nix-channel --update- Stable(24.05)
nix-channel --add https://github.com/nix-community/home-manager/archive/release-24.05.tar.gz home-manager && nix-channel --updateTIP
For version number, see: Nix Channels
Install
nix-shell '<home-manager>' -A installINFO
<home-manager> is the channel alias you set in previous step. Replace it with yours if necessary.
After this command, home-manager should be available.
Initialize home-manager
Initialize home-manager config by:
home-manager initThis command generates flake.nix, home.nix under ~/.config/home-manager/
flake.nix: metadata used for home-manager.home.nix: entry point of home-manager. Uses attribute set fromflake.nix.
Apply home-manager profile
By default, home-manager init{:sh} generates by current username.
# generated in home.nix
home.username = "sharpchen";2
So it should be valid to switch to the profile with following:
home-manager switch --flake ~/.config/home-manager#$USERThis is how you restore a home-manager profile for a user. And this also implies home-manager can handle multiple users' profiles.
TIP
Set an command alias for home-manager switch!