HomeLinuxHow one can arrange home-manager on NixOS?

How one can arrange home-manager on NixOS?


Earlier than publishing this, I defined methods to set up and take away packages in NixOS for a single-user system.

However if you’re operating a number of customers, there is a wonderful technique to cater wants of each person individually.

And on this information, I’ll stroll you thru how one can arrange a house supervisor on NixOS and the way it may be used to put in packages.

In case you are new right here, some sources mentioned on this sequence embrace:

Setup home-manager on NixOS

On this information, I’ll stroll you thru 2 methods to arrange a house supervisor:

  • Standalone residence supervisor (makes use of separate config file)
  • As a nix module (utilizing it inside configuration.nix file)

So let’s begin with the standalone choice.

Standalone set up of home-manager

In case you are utilizing a steady channel of NixOS, you should use the next command to configure the house supervisor:

nix-channel --add https://github.com/nix-community/home-manager/archive/release-22.11.tar.gz home-manager

Whereas scripting this information, the steady launch is 22.11.

And if you’re on an unstable channel, use the next:

nix-channel --add https://github.com/nix-community/home-manager/archive/grasp.tar.gz home-manager

The next steps will stay the identical whether or not you employ steady or unstable.

As soon as finished, replace the channels:

nix-channel --update

And at last, use the next command to put in the house supervisor:

nix-shell '<home-manager>' -A set up

🛠️ Whereas putting in, it might throw the next error:

building error while installing home manager

Reboot your system and use the set up command once more, and it’ll begin the set up.

As soon as finished, it would present the placement of the standalone set up of the house supervisor:

location of home manager in NixOS

Putting in home-manager as a NixOS module

⚠️

You have to sudo privileges for those who select to make use of the house supervisor as a NixOS module.

In case you are on a steady channel (whereas writing, it’s 22.11), you should use the next command so as to add the steady channel of the house supervisor:

sudo nix-channel --add https://github.com/nix-community/home-manager/archive/release-22.11.tar.gz home-manager

And if you’re utilizing unstable or the grasp channel, use the next:

sudo nix-channel --add https://github.com/nix-community/home-manager/archive/grasp.tar.gz home-manager

As soon as you might be finished including a channel by utilizing any of 1 command proven above, replace the channel utilizing the next:

sudo nix-channel --update

Subsequent, open the configuration.nix file utilizing:

sudo nano /and so forth/nixos/configuration.nix

And add the next line contained in the imports []:

<home-manager/nixos>
install home-manager as NixOS module

Now, bounce to the top of the road and add the next earlier than }:

home-manager.customers.{username} = { pkgs, ... }: {
  residence.packages = [  ];
  };
syantax for home-manager module in NixOS config file

The above line was added to facilitate putting in and eradicating packages I’ll present you subsequent.

Now, save adjustments and exit from the nano textual content editor.

Subsequent, rebuild the config and make a change:

sudo nixos-rebuild change

However if you’re utilizing steady launch and use the above command, it would throw the error saying :

🛠️ error: The choice `home-manager.customers.person.residence.stateVersion’ is used however not outlined:

error: The option `home-manager.users.user.home.stateVersion' is used but not defined.

To unravel this challenge, you’ll have to add the residence.stateVersion in your house supervisor block.

Whereas writing, I am operating 22.11, so the entire residence supervisor block would appear like this:

home-manager.customers.{username} = { pkgs, ... }: {
residence.stateVersion = "22.11";  
residence.packages = [ ];
  };
how to solve The option `home-manager.users.user.home.stateVersion' is used but not defined.

Save adjustments and exit from the nano textual content editor by urgent Ctrl + O, hitting enter and Ctrl + X.

Now, attempt to rebuild the config and make the change once more, and that ought to clear up the problem.

How one can set up packages utilizing home-manager on NixOS

Now that you’ve got home-manager put in, methods to set up packages with it:

Utilizing a standalone set up of House-manager

First, open the configuration file by utilizing the next:

nano /residence/$USER/.config/nixpkgs/residence.nix

Soar to the top of the road and add the next code block earlier than }:

residence.packages = [];

Now, all it’s important to do is write the bundle’s title between these two braces.

For instance, if I need to set up htop, I must enter the next:

residence.packages = [pkgs.htop];

Sure, you’ll have to normally append the title of the bundle with pkgs.

However if you wish to get away with utilizing pkgs. utilizing each time you put in a brand new bundle, change the syntax of the code block as proven:

residence.packages = with pkgs; [];

And now, you might be not required to make use of pkgs. for each set up:

residence.packages = with pkgs; [htop];

For instance, right here, I needed to put in htop, firefox, and LibreOffice so my residence block would appear like this:

install multiple packages using home-manager on NixOS
Putting in a number of packages utilizing home-manager (Click on to enlarge picture)

As soon as you might be finished including your favourite packages, save the config file and use the next command to put in packages:

home-manager change

Utilizing the NixOS module

First, open the configuration.nix file utilizing the next command:

sudo nano /and so forth/nixos/configuration.nix

Within the configuration half, I’ve already added the house supervisor block, so all it’s left is so as to add the title of the bundle inside residence.packages = [  ]; within the proven format:

residence.packages = [ pkgs.package_name ];

💡

I’ve talked about how one can get away with utilizing pkgs. earlier than the bundle title within the above part (putting in packages on the standalone residence supervisor).

For instance, if I need to set up htop, Firefox, and LibreOffice, then I’ll add:

pkgs.htop pkgs.firefox pkgs.libreoffice

And my residence supervisor block would appear like this:

install multiple packages in home-manager as a NixOS module

Now, save adjustments and exit from the textual content editor.

Subsequent, rebuild the config and make a change utilizing the next command:

sudo nixos-rebuild change

That is it! The packages might be put in very quickly.

‘Tis the top

I feel you must go together with the standalone set up, as you aren’t required to make use of the superuser privileges. Additionally, having separate config recordsdata for separate customers is kind of handy for those who run a system with a number of customers.

So except you need one file for each goal, I see no different motive to make use of the module choice.

With this, I conclude the NixOS newbie sequence. I hope it will get you a ok platform to get conversant in this distinctive Linux distribution.

💬 How did you just like the NixOS sequence? Is there one thing else we should always cowl for NixOS learners? Please present your beneficial suggestions.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments