HomeLinuxNixOS Collection #3: Add and Take away Packages

NixOS Collection #3: Add and Take away Packages


The packaging system in NixOS is its strongest level. The Nix bundle supervisor makes use of a vastly completely different syntax than apt, dnf and different bundle managers.

On this information, I’ll share two methods to put in and take away packages on NixOS:

  • Utilizing the Nix bundle supervisor
  • Utilizing configuration.nix config file

⚠️

Utilizing the Nix bundle supervisor, you may solely set up packages however not providers like SSH or Plex server. For the set up of providers, you’d have to make use of a Nix configuration file.

To put in any bundle, it’s essential to know its actual title and for that goal, I’ll begin with how one can seek for packages in NixOS.

Search packages

To search for packages, you need to use its internet search utilizing your most popular browser.

You’ll be able to make the most of its internet search utilizing the given steps:

  1. Enter the title of the bundle within the search bar
  2. Choose the suitable bundle (determine from the given description)
  3. Click on on nix-env choice
  4. And duplicate the command for NixOS (first one)

For instance, if I need librewolf bundle, I’ll carry out the next:

searching for package using nix package manager web search
Looking for the required bundle (Click on to broaden the picture)

You are able to do the identical by means of the terminal.

To go looking packages utilizing the terminal, you may comply with the given command syntax:

nix-env -qaP --description [package_name]

For instance, right here, I looked for the librewolf:

search packages in nixos using terminal

You’ll have to copy the primary line of the output as that’s the title for the bundle you’ll want to set up.

For me, it was nixos.librewolf.

Sure, it could not sound as handy because the bundle names when utilizing APT or DNF. However, it isn’t too unhealthy, I believe.

Some compromises for some advantages, I assume?

Steered Learn 📖

How you can Set up RPM Recordsdata on Fedora Linux [Beginner’s Tutorial]

This newbie article explains learn how to set up RPM packages on Fedora and Pink Hat Linux. It additionally reveals you learn how to take away these RPM packages afterwards. If you begin utilizing Fedora Linux within the Pink Hat area, ultimately, you’ll come throughout .rpm recordsdata. Like .exe recordsdata in

Set up a bundle in NixOS

To put in a bundle, all it’s a must to do is use the next command syntax:

nix-env -iA [package_name]

And should you use the online search to search for the bundle, you’ll have already got the precise command you want for the set up.

So as an example I wish to set up librewolf, so I will likely be utilizing the next command:

nix-env -iA nixos.librewolf

And if you wish to carry out a system-wide set up (make this bundle out there for each consumer), execute the set up command with sudo:

sudo nix-env -iA nixos.librewolf

That is it! You should have your favourite bundle put in very quickly.

Uninstall a Package deal in NixOS

To take away a bundle, you may seek advice from the given command syntax:

nix-env --uninstall [package_name]

So if I’ve to take away the librewolf bundle, I’ve to make use of the next command:

nix-env --uninstall librewolf

For those who discover carefully, I’ve used librewolf as a substitute of nixos.librewolf what I used for the set up.

This implies you’ll have to skip the nixos half throughout removing of the bundle, which makes issues straightforward and fast.

Set up providers in NixOS

As I discussed earlier, you cannot use the nix bundle supervisor to put in providers like OpenSSH, Plex server, Flatpak, and so forth.

From looking for the service to the set up course of, it differs from what you noticed above.

So let me begin with how one can seek for a service:

  1. To seek for the service, head over to the online web page for the Nix bundle search.
  2. Choose NixOS choices (third choice within the top-menu row of the web page).
  3. Enter the title of the service you’re searching for.
  4. Copy the title of the service.

For instance, right here, I am looking for OpenSSH service:

search for openssh service in NixOS
Looking for a service (Click on to enlarge the picture)

Upon getting the title, open the configuration.nix file utilizing the next command:

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

And add the title of the service on the finish of the road (earlier than }) within the following method:

[service_name] = true;

As I wish to allow OpenSSH, I will likely be including the next:

providers.openssh.allow = true;
enable openssh on NixOS

As soon as you’re carried out including the service to the config file, save the adjustments and exit from the nano textual content editor.

To allow the service, rebuild the config file and swap to the adjustments utilizing the next command:

sudo nixos-rebuild swap

That is it! You will have the service enabled.

Uninstall providers from NixOS

To uninstall a service, all it’s a must to do is take away or remark out the road for that service from configuration.nix file.

So first, open the config file utilizing the next command:

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

Search for the service and take away the road or remark it out with #:

remove service from NixOS

With the added remark #, I’m ignoring the OpenSSH service to load up as I not need it on my system.

As soon as carried out, save the change and exit from the textual content editor.

And eventually, rebuild the config file and make the swap:

sudo nixos-rebuild swap

Set up packages utilizing Nix config file

The configuration file allows you to simply handle packages in a single go.

To put in a bundle utilizing the Nix config file, it’s a must to enter the bundle’s title within the config file, rebuild, and swap to the config file, and that is it.

First, open the configuration.nix file:

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

If you wish to set up a bundle for a selected logged-in consumer, add the bundle’s title to the consumer’s profile.

The consumer profile seems like this:

customers.customers.sagar = {
    isNormalUser = true;
    description = "Sagar";
    extraGroups = [ "networkmanager" "wheel" ];
    packages = with pkgs; [
      firefox
    ];
  };

Certain, it would present your username as a substitute of sagar.

And you’re supposed so as to add the title of the bundle utilizing the syntax  packages = with pkgs; [package_name];

So let’s suppose I wish to set up Thunderbird as properly, then I’ll add its title as proven under:

install a package in NixOS using the Nix config file

You need to add all of the bundle names contained in the sq. bracket with out commas. It needs to be on a brand new line because the screenshot describes.

However if you wish to set up this bundle system-wide, then you’ll have to add the bundle title below atmosphere.systemPackages like:

atmosphere.systemPackages = with pkgs; [package_name];

install package systemwide in NixOS using Nix configuration file

As soon as you’re carried out including the title of the required bundle within the system profile or consumer profile, and even each, you’ll have to comply with the identical command to finish the set up:

sudo nixos-rebuild swap

And you’ve got it!

Take away packages utilizing the Nix config file

To take away the bundle, all it’s a must to do is comply with the given easy steps:

  1. Open the Nix config file
  2. Take away or remark out the title of the bundle
  3. Rebuild the config and make a swap

So let’s begin with step one (opening the config file):

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

Subsequent, remark out the title of the packet from the consumer profile or system profile:

remove package using nix config file on NixOS

Save adjustments and exit from the config file.

And eventually, rebuild the config and make a swap to take away the bundle:

sudo nixos-rebuild swap

That is it!

📋

Presently, there are not any official GUI instruments that will help you with putting in/eradicating packages. You would possibly discover some tasks like nix-gui and nix42b developed by the group, however they’re not maintained or just of their early levels of improvement.

Subsequent Up…

I hope you take pleasure in studying the NixOS sequence as a lot as I do writing it.

Within the subsequent half, I’ll spotlight some vital issues you’ll want to do proper after putting in NixOS.

💬 For those who suppose I am lacking out on one thing or have some other options, please let me know within the feedback.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments