Use home-manager Instead of nix-env
Contents
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
|
|
See issue#2033 and Nix discourse.
Now add unstable nix channel
|
|
Or latest stable (as of writing this post) 22.05, if you prefer it
|
|
And update
|
|
Install Home Manager
|
|
Home Manager requires your shell to source ~/.nix-profile/etc/profile.d/hm-session-vars.sh
. 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.
|
|
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.
|
|
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
Author Aditya
LastMod 2022-09-02 (eb4c15a)