use home manager

Aditya 3 months ago
parent 394d72f487
commit eb4c15a527
  1. 99

@ -0,0 +1,99 @@
title: "Use home-manager Instead of nix-env"
date: 2022-09-01T12:47:47+05:30
lastmod: 2022-09-01T12:47:47+05:30
draft: false
keywords: [nix home-manager nix-env]
description: ""
tags: []
categories: []
author: ""
# You can also close(false) or open(true) something for this content.
# P.S. comment can only be closed
comment: false
toc: true
autoCollapseToc: false
postMetaInFooter: true
hiddenFromHomePage: false
# You can also define another contentCopyright. e.g. contentCopyright: "This is another copyright."
contentCopyright: false
reward: false
mathjax: false
mathjaxEnableSingleDollar: false
mathjaxEnableAutoNumber: false
# You unlisted posts you might want not want the header or footer to show
hideHeaderAndFooter: false
# You can enable or disable out-of-date content warning for individual post.
# Comment this out to use the global config.
#enableOutdatedInfoWarning: false
enable: false
options: ""
enable: false
options: ""
`home-manager` allows reprodicuble builds compared to `nix-env`. You can port your configuration to any machine and expect it to work the same.
This post assumes you are on a non-NixOS Linux system.
# Getting nix
Nix can be installed via a simple shell script provided on [their website]( Just use your judgement and follow the prompts.
# Installing `home-manager`
The configuration is stored in `~/.config/nixpkgs/home.nix`. Run `home-manager switch` to have changes take effect.
Export `NIX_PATH` to your shell
export NIX_PATH=$HOME/.nix-defexpr/channels:/nix/var/nix/profiles/per-user/root/channels${NIX_PATH:+:$NIX_PATH}
See [issue#2033]( and [Nix discourse](
Now add unstable nix channel
nix-channel --add home-manager
Or latest stable (as of writing this post) 22.05, if you prefer it
nix-channel --add home-manager
And update
nix-channel --update
Install Home Manager
nix-shell '<home-manager>' -A install
Home Manager requires your shell to source `~/.nix-profile/etc/profile.d/`. It can be easily done by setting `programs.bash.enable = true;` (of course, here bash is just an example). This way, Home Manager will manage your shell configuration. However, you will need to migrate your bashrc configurations over to Home Manager, which might take some time. An easier way out would be to move your existing bashrc and have Home Manager use that.
{ pkgs, ...}: {
programs.bash = {
enable = true;
bashrcExtra = ''
. ~/oldbashrc
Since we are on a non-NixOS Linux system, Home Manager can automatically set some environment variables that will ease the usage of software installed with nix.
{pkgs, ...}: {
targets.genericLinux.enable = true;
Now Home Manager is ready to use. There are many ways to install and configure packages using nix. Putting them here will make this post quite exhaustive. Check the links in the references as they go deeper and have up-to-date docs and examples.
# References
[NixOS Wiki - Home Manager](
[Home Manager Manual](