mirror of
https://github.com/LCTT/TranslateProject.git
synced 2025-01-19 22:51:41 +08:00
152 lines
7.4 KiB
Plaintext
152 lines
7.4 KiB
Plaintext
[#]: subject: "NixOS Series #1: Why Should You Consider Using NixOS?"
|
||
[#]: via: "https://itsfoss.com/why-use-nixos/"
|
||
[#]: author: "Sagar Sharma https://itsfoss.com/author/sagar/"
|
||
[#]: collector: "lkxed"
|
||
[#]: translator: " "
|
||
[#]: reviewer: " "
|
||
[#]: publisher: " "
|
||
[#]: url: " "
|
||
|
||
NixOS Series #1: Why Should You Consider Using NixOS?
|
||
======
|
||
|
||
NixOS... Yet another distro that uses a different package manager? **🤯**
|
||
|
||
Well, NixOS is one of the [advanced Linux distros][1].
|
||
|
||
So if I'm writing this, I must have a rock-solid reason, right? Well, there are plenty!
|
||
|
||
I've been using it for 3 months, and it is so good that I'm considering switching from my all-time favorite **Pop!_OS to NixOS**.
|
||
|
||
And in this guide, I will share the key features of NixOS, making it stand out from the stack of Linux distros.
|
||
|
||
Fret not; before we move on, let me tell you what NixOS is:
|
||
|
||
> It is a Linux distribution that uses the Nix package manager at its core to save you the trouble from setting it up on a different Linux distribution and letting you make the most out of Nix. Built by the same team that developed Nix.
|
||
|
||
### 6 Reasons to Use NixOS
|
||
|
||
NixOS is an interesting [independent Linux distro][2] built from scratch.
|
||
|
||
Everyone can learn a lot by using NixOS, but **in my opinion**, if you are a developer or a computer science student, NixOS should fit perfectly.
|
||
|
||
![nix os screenshot with gnome][3]
|
||
|
||
Let me tell you why.
|
||
|
||
#### 1. Does Not Break Easily / Easy to Recover
|
||
|
||
By its core, NixOS is built to last long.
|
||
|
||
This does not mean that it ships with years-old packages like Debian does for stability but it follows a different approach.
|
||
|
||
To understand how NixOS is so stable, let's talk about how users generally break their system, i.e, "_dependency issues or package conflicts_"
|
||
|
||
You will generally face a significant system crash when updating your system or installing a new package. Mainly because your package manager could not satisfy the dependency or the installed package conflicts with the existing system.
|
||
|
||
**And NixOS has a very smart way of handling this issue.**
|
||
|
||
See, whenever you upgrade your system or install a package, the **system state is rebuilt**, termed as a "**new generation**" over the current.
|
||
|
||
![nix os listing generations via terminal][4]
|
||
|
||
So if you face any trouble using the new package or update, you can always roll back to the old generation, where you will find the **previous state of the system.**
|
||
|
||
Even if the system is inaccessible, you will find the previous generations available at boot time.
|
||
|
||
#### 2. Reproducibility
|
||
|
||
With one config file, you can create a replica of your current environment for other physical systems.
|
||
|
||
To benefit from this feature, you can use the Nix config file for installation and configuration purposes.
|
||
|
||
Once you have the config file that fits your purpose, send that file to the fresh install and replace the default config file with yours. It is that easy!
|
||
|
||
**Rebuild the config, upgrade the system, and make a switch by the given command:**
|
||
|
||
```
|
||
sudo nixos-rebuild switch --upgrade
|
||
```
|
||
|
||
And you will have the exact development environment that you had on your main machine replicated in a few minutes.
|
||
|
||
#### 3. Easy Rollbacks
|
||
|
||
While you already may have got the idea from NixOS's feature of "**Generations**".
|
||
|
||
There's more to it. **🕵️**
|
||
|
||
NixOS heavily relies on symlinks (for good). If it is a new concept to you, refer to the guide below:
|
||
|
||
How to Create Symbolic Links in Linux [Complete Guide]This detailed tutorial tells you what are symbolic links, how to create a symbolic links and other important things associated with symlinks.![][5]Linux HandbookAbhishek Prakash![][6]
|
||
|
||
Typically, with other Linux distros, when you upgrade a package, the new package replaces the old one.
|
||
|
||
But that's not the case with NixOS.
|
||
|
||
In NixOS, packages are isolated and stored inside a unique directory, and that is where the use of symbolic links comes in.
|
||
|
||
Whenever you upgrade a package, the **NixOS will tune the symbolic link to locate the new package but won't remove the old one**.
|
||
|
||
So if you face conflicts with the new package, just switch to the old generations, and symbolic links help locate the old version of a package. 😌
|
||
|
||
#### 4. Nix package manager
|
||
|
||
The Nix package manager allows you to access more than 80,000 packages! Not just limited to Linux; it also works on **macOS, WSL2, Docker, and more platforms.**
|
||
|
||
And the availability of packages is similar to or even better than AUR as you should find almost everything (I mean it) on the Nix package manager.
|
||
|
||
For instance, I wanted to install the Librewolf browser, which is not available in the default repository of most Linux distros.
|
||
|
||
But Nix had it! This means you can rely on the Nix package manager for almost every package.
|
||
|
||
It is also relatively easy to understand if you have prior Linux experience. In a nutshell, **the Nix package manager is impressive!**
|
||
|
||
#### 5. Use multiple versions of the same package
|
||
|
||
This can be crucial for developers, where some applications demand the old version of a specific dependency, whereas some require the latest one.
|
||
|
||
And as I mentioned earlier, nix installs packages to a specific sub-directory, and every package is isolated so one won't interfere with another!
|
||
|
||
Before using Nix, I used VMs and containers to meet different dependencies for the same package, especially with PHP, but NixOS did wonders for my workflow.
|
||
|
||
**Suggested Read 📖**
|
||
|
||
Downgrading a Package via apt-get in Ubuntu and DebianYes! That’s totally possible. You can downgrade a recently updated package using the apt command in Ubuntu and Debian based distros. Here’s how to do that.![][7]It's FOSSAbhishek Prakash![][8]
|
||
|
||
#### 6. Ability to test packages without installation
|
||
|
||
You can use the [nix-shell][9], which will temporarily modify the $PATH environment variable and be used to test a package temporarily.
|
||
|
||
And there is no limitation. You are allowed to test every package that is available for installation!
|
||
|
||
### NixOS Series: Let's Explore More!
|
||
|
||
This was the first part of our Nix series, where I covered the reasons to use NixOS. I believe more Linux users should get to learn about it if they do not already.
|
||
|
||
In the next part, I will explain how to install NixOS in your VM. Stay tuned to our social media or RSS feed to read when we publish that.
|
||
|
||
💬 _Feel free to share suggestions on what else we should cover about NixOS in the comments below._
|
||
|
||
--------------------------------------------------------------------------------
|
||
|
||
via: https://itsfoss.com/why-use-nixos/
|
||
|
||
作者:[Sagar Sharma][a]
|
||
选题:[lkxed][b]
|
||
译者:[译者ID](https://github.com/译者ID)
|
||
校对:[校对者ID](https://github.com/校对者ID)
|
||
|
||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||
|
||
[a]: https://itsfoss.com/author/sagar/
|
||
[b]: https://github.com/lkxed/
|
||
[1]: https://itsfoss.com/advanced-linux-distros/
|
||
[2]: https://itsfoss.com/independent-linux-distros/
|
||
[3]: https://itsfoss.com/content/images/2023/02/nix-os-gnome.png
|
||
[4]: https://itsfoss.com/content/images/2023/02/nix-os-generations.png
|
||
[5]: https://linuxhandbook.com/content/images/size/w256h256/2021/08/Linux-Handbook-New-Logo.png
|
||
[6]: https://linuxhandbook.com/content/images/2020/06/Symbolic-Links-Linux.jpg
|
||
[7]: https://itsfoss.com/content/images/size/w256h256/2022/12/android-chrome-192x192.png
|
||
[8]: https://itsfoss.com/content/images/2023/02/downgrade-packages-via-apt-get.png
|
||
[9]: https://nixos.org/manual/nix/stable/command-ref/nix-shell.html |