mirror of
https://github.com/LCTT/TranslateProject.git
synced 2024-12-23 21:20:42 +08:00
commit
b961f0bb59
@ -1,152 +0,0 @@
|
|||||||
[#]: 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: "geekpi"
|
|
||||||
[#]: 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
|
|
@ -0,0 +1,145 @@
|
|||||||
|
[#]: 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: "geekpi"
|
||||||
|
[#]: reviewer: " "
|
||||||
|
[#]: publisher: " "
|
||||||
|
[#]: url: " "
|
||||||
|
|
||||||
|
NixOS 系列 #1:你为什么要考虑使用 NixOS?
|
||||||
|
======
|
||||||
|
|
||||||
|
NixOS... 又是一个使用不同软件包管理器的发行版?**🤯**
|
||||||
|
|
||||||
|
好吧,NixOS 是[高级 Linux 发行版][1]中的一个。
|
||||||
|
|
||||||
|
所以如果我写这个,我一定有一个充分的理由,对吗?嗯,有很多
|
||||||
|
|
||||||
|
我已经使用它 3 个月了,它是如此之好,以至于我正在考虑从我一直以来最喜欢的 **Pop!_OS 切换到 NixOS**。
|
||||||
|
|
||||||
|
在本指南中,我将分享 NixOS 在众多 Linux 发行版中脱颖而出的主要特点,。
|
||||||
|
|
||||||
|
别担心,在我们继续之前,让我告诉你什么是NixOS:
|
||||||
|
|
||||||
|
> 它是一个以 Nix 包管理器为核心的 Linux 发行版,为你省去了在不同 Linux 发行版上设置的麻烦,让你充分利用 Nix 的优势。由开发 Nix 的同一个团队构建。
|
||||||
|
|
||||||
|
### 使用 NixOS 的 6 个理由
|
||||||
|
|
||||||
|
NixOS 是一个有趣的从零开始构建的[独立 Linux 发行版][2]。
|
||||||
|
|
||||||
|
每个人都可以通过使用 NixOS 学到很多东西,但**在我看来**,如果你是一个开发人员或计算机科学的学生,NixOS 应该非常合适。
|
||||||
|
|
||||||
|
![nix os screenshot with gnome][3]
|
||||||
|
|
||||||
|
让我告诉你为什么。
|
||||||
|
|
||||||
|
#### 1. 不易损坏/易于恢复
|
||||||
|
|
||||||
|
就其核心而言,NixOS 是为长期使用而构建的。
|
||||||
|
|
||||||
|
这并不意味着它像 Debian 那样用多年前的软件包来保证稳定性,而是遵循一种不同的方法。
|
||||||
|
|
||||||
|
为了理解 NixOS 为何如此稳定,让我们谈谈用户一般是如何破坏他们的系统的,即“_依赖性问题或软件包冲突_”
|
||||||
|
|
||||||
|
在更新系统或安装一个新的软件包时,你一般会面临明显的系统崩溃。主要是因为你的软件包管理器无法满足依赖性,或者安装的软件包与现有系统冲突。
|
||||||
|
|
||||||
|
**而 NixOS 有一个非常聪明的方法来处理这个问题**。
|
||||||
|
|
||||||
|
你看,每当你升级你的系统或安装一个软件包时,**系统的状态就会被重建**,被称为“**新的一代**”,超过当前的。
|
||||||
|
|
||||||
|
![nix os listing generations via terminal][4]
|
||||||
|
|
||||||
|
因此,如果你在使用新的软件包或更新时遇到任何麻烦,你可以随时回滚到旧的一代,在那里你会找到**系统的以前的状态**。
|
||||||
|
|
||||||
|
即使系统无法访问,你也能在启动时找到以前的几代包。
|
||||||
|
|
||||||
|
#### 2. 可重复性
|
||||||
|
|
||||||
|
通过一个配置文件,你可以为其他物理系统创建一个你当前环境的副本。
|
||||||
|
|
||||||
|
为了从这个功能中获益,你可以使用 Nix 配置文件进行安装和配置。
|
||||||
|
|
||||||
|
当你有了适合你的目的的配置文件,将该文件发送到新的安装中,用你的配置文件替换默认的配置文件。就是这么简单!
|
||||||
|
|
||||||
|
**重建配置,升级系统,并通过给定的命令进行切换:**
|
||||||
|
|
||||||
|
```
|
||||||
|
sudo nixos-rebuild switch --upgrade
|
||||||
|
```
|
||||||
|
|
||||||
|
你将在几分钟内拥有与你的主机上完全相同的开发环境,并进行复制。
|
||||||
|
|
||||||
|
#### 3. 轻松回滚
|
||||||
|
|
||||||
|
虽然你可能已经从 NixOS 的 “**Generations**” 特性中得到了灵感。
|
||||||
|
|
||||||
|
这还有更多的内容。**🕵️**
|
||||||
|
|
||||||
|
NixOS 在很大程度上依赖于符号链接。如果这对你来说是一个新概念,请参考下面的指南:
|
||||||
|
|
||||||
|
[如何在Linux中创建符号链接(完整指南)][5]
|
||||||
|
|
||||||
|
一般来说,在其他 Linux 发行版中,当你升级一个软件包时,新的软件包会取代旧的。
|
||||||
|
|
||||||
|
但 NixOS 不是这样的。
|
||||||
|
|
||||||
|
在 NixOS 中,软件包被隔离并存储在一个单独的目录中,这就是使用符号链接的原因。
|
||||||
|
|
||||||
|
每当你升级一个软件包时,**NixOS 会调整符号链接来定位新的软件包,但不会删除旧的**。
|
||||||
|
|
||||||
|
因此,如果你面临与新包的冲突,只需切换到旧的一代,符号链接有助于定位旧版本的包。😌
|
||||||
|
|
||||||
|
#### 4. Nix 包管理器
|
||||||
|
|
||||||
|
Nix 包管理器允许你访问超过 80,000 个软件包! 不仅仅局限于 Linux,它还可以在 **macOS、WSL2、Docker 等平台**上使用。
|
||||||
|
|
||||||
|
而且,软件包的可用性与 AUR 相似,甚至比 AUR 更好,因为你应该在 Nix 包管理器上找到几乎所有的东西(我的认真的)。
|
||||||
|
|
||||||
|
例如,我想安装 Librewolf 浏览器,这在大多数 Linux 发行版的默认仓库中是不可用的。
|
||||||
|
|
||||||
|
但是,Nix 有它! 这意味着你可以依靠 Nix 包管理器来安装几乎所有的软件包。
|
||||||
|
|
||||||
|
如果你有先前的 Linux 经验,它也相对容易理解。总而言之,**Nix 包管理器令人印象深刻**!
|
||||||
|
|
||||||
|
#### 5. 使用同一软件包的多个版本
|
||||||
|
|
||||||
|
这对开发者来说可能是至关重要的,有些应用需要特定依赖的旧版本,而有些则需要最新的版本。
|
||||||
|
|
||||||
|
而且,正如我前面提到的,nix将包安装到一个特定的子目录中,每个包都是隔离的,所以一个包不会干扰另一个包!
|
||||||
|
|
||||||
|
在使用 Nix 之前,我使用虚拟机和容器来满足同一软件包的不同依赖性,尤其是 PHP,但 NixOS 为我的工作流程带来了奇迹。
|
||||||
|
|
||||||
|
#### 6. 无需安装就能测试软件包的能力
|
||||||
|
|
||||||
|
你可以使用 [nix-shell][9],它将临时修改 $PATH 环境变量,用来临时测试一个包。
|
||||||
|
|
||||||
|
而且没有任何限制。你被允许测试每一个可供安装的软件包!
|
||||||
|
|
||||||
|
### NixOS 系列:让我们探索更多!
|
||||||
|
|
||||||
|
这是我们 Nix 系列的第一部分,我介绍了使用 NixOS 的原因。我相信更多的 Linux 用户应该去了解它,如果他们还没有了解的话。
|
||||||
|
|
||||||
|
在下一部分,我将解释如何在你的虚拟机中安装 NixOS。敬请关注我们的社交媒体或 RSS 订阅,以便在我们发布时阅读。
|
||||||
|
|
||||||
|
💬 _欢迎在下面的评论中分享关于 NixOS 的其他内容的建议。_
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
via: https://itsfoss.com/why-use-nixos/
|
||||||
|
|
||||||
|
作者:[Sagar Sharma][a]
|
||||||
|
选题:[lkxed][b]
|
||||||
|
译者:[geekpi](https://github.com/geekpi)
|
||||||
|
校对:[校对者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/symbolic-link-linux/
|
||||||
|
[9]: https://nixos.org/manual/nix/stable/command-ref/nix-shell.html
|
Loading…
Reference in New Issue
Block a user