2023-06-30 11:00:03 +02:00
|
|
|
# Advantages & Disadvantages of NixOS
|
2023-06-23 12:05:06 +02:00
|
|
|
|
2023-07-07 19:27:24 +02:00
|
|
|
## Advantages of NixOS
|
2023-06-23 12:05:06 +02:00
|
|
|
|
2023-07-07 18:32:56 +02:00
|
|
|
- **Declarative Configuration, OS as Code**
|
2024-03-16 12:29:05 +01:00
|
|
|
- NixOS uses declarative configuration to manage the entire system environment. These
|
|
|
|
configurations can be managed directly with Git, allowing the system to be restored to
|
|
|
|
any historical state as long as the configuration files are preserved (provided the
|
|
|
|
desired states are declared in the Nix configuration).
|
|
|
|
- Nix Flakes further enhance reproducibility by utilizing a `flake.lock` version lock
|
|
|
|
file, which records the data source addresses, hash values, and other relevant
|
|
|
|
information for all dependencies. This design greatly improves Nix's reproducibility
|
|
|
|
and ensures consistent build results. It draws inspiration from package management
|
|
|
|
designs in programming languages like Cargo and npm.
|
2023-07-07 18:32:56 +02:00
|
|
|
- **Highly Convenient System Customization Capability**
|
2024-03-16 12:29:05 +01:00
|
|
|
- With just a few configuration changes, various components of the system can be easily
|
|
|
|
replaced. Nix encapsulates all the underlying complex operations within Nix packages,
|
|
|
|
providing users with a concise set of declarative parameters.
|
|
|
|
- Modifications are safe and switching between different desktop environments (such as
|
|
|
|
GNOME, KDE, i3, and sway) is straightforward, with minimal pitfalls.
|
2023-07-07 18:32:56 +02:00
|
|
|
- **Rollback Capability**
|
2024-03-16 12:29:05 +01:00
|
|
|
- It is possible to roll back to any previous system state, and NixOS even includes all
|
|
|
|
old versions in the boot options by default, ensuring the ability to easily revert
|
|
|
|
changes. Consequently, Nix is regarded as one of the most stable package management
|
|
|
|
approaches.
|
2023-07-07 18:32:56 +02:00
|
|
|
- **No Dependency Conflict Issues**
|
2024-03-16 12:29:05 +01:00
|
|
|
- Each software package in Nix has a unique hash, which is incorporated into its
|
|
|
|
installation path, allowing multiple versions to coexist.
|
2023-07-08 10:00:22 +02:00
|
|
|
- **The community is active, with a diverse range of third-party projects**
|
2024-03-16 12:29:05 +01:00
|
|
|
- The official package repository, nixpkgs, has numerous contributors, and many people
|
|
|
|
share their Nix configurations. Exploring the NixOS ecosystem is an exciting
|
|
|
|
experience, akin to discovering a new continent.
|
2023-06-23 12:05:06 +02:00
|
|
|
|
2023-07-08 10:00:22 +02:00
|
|
|
<figure>
|
|
|
|
<img src="/nixos-bootloader.avif">
|
|
|
|
<figcaption>
|
|
|
|
<h4 align="center">
|
|
|
|
All historical versions are listed in the boot options of NixOS. <br>
|
|
|
|
Image from
|
|
|
|
<a href="https://discourse.nixos.org/t/how-to-make-uefis-grub2-menu-the-same-as-bioss-one/10074" target="_blank" rel="noopener noreferrer">
|
|
|
|
NixOS Discourse - 10074
|
|
|
|
</a>
|
|
|
|
</h4>
|
|
|
|
</figcaption>
|
|
|
|
</figure>
|
2023-06-23 12:05:06 +02:00
|
|
|
|
2023-07-07 19:27:24 +02:00
|
|
|
## Disadvantages of NixOS
|
2023-06-23 12:05:06 +02:00
|
|
|
|
2023-07-07 18:32:56 +02:00
|
|
|
- **High Learning Curve**:
|
2024-03-16 12:29:05 +01:00
|
|
|
- Achieving complete reproducibility and avoiding pitfalls associated with improper
|
|
|
|
usage requires learning about Nix's entire design and managing the system
|
|
|
|
declaratively, rather than blindly using commands like `nix-env -i` (similar to
|
|
|
|
`apt-get install`).
|
2023-07-07 18:32:56 +02:00
|
|
|
- **Disorganized Documentation**:
|
2024-03-16 12:29:05 +01:00
|
|
|
- Currently, Nix Flakes remains an experimental feature, and there is limited
|
|
|
|
documentation specifically focused on it. Most Nix community documentation primarily
|
|
|
|
covers the classic `/etc/nixos/configuration.nix`. If you want to start learning
|
|
|
|
directly from Nix Flakes(`flake.nix`), you need to refer to a significant amount of
|
|
|
|
outdated documentation and extract the relevant information. Additionally, some core
|
|
|
|
features of Nix, such as `imports` and the Nixpkgs Module System, lack detailed
|
|
|
|
official documentation, requiring resorting to source code analysis.
|
2023-07-07 18:32:56 +02:00
|
|
|
- **Increased Disk Space Usage**:
|
2024-03-16 12:29:05 +01:00
|
|
|
- To ensure the ability to roll back the system at any time, Nix retains all historical
|
|
|
|
environments by default, resulting in increased disk space usage.
|
|
|
|
- While this additional space usage may not be a concern on desktop computers, it can
|
|
|
|
become problematic on resource-constrained cloud servers.
|
2023-07-07 18:32:56 +02:00
|
|
|
- **Obscure Error Messages**:
|
2024-03-16 12:29:05 +01:00
|
|
|
- Due to the
|
|
|
|
[complex merging algorithm](https://discourse.nixos.org/t/best-resources-for-learning-about-the-nixos-module-system/1177/4)
|
|
|
|
of the [Nixpkgs module system](../other-usage-of-flakes/module-system.md), NixOS error
|
|
|
|
messages are quite poor. In many cases, regardless of whether you add `--show-trace`,
|
|
|
|
it will only tell you that there is an error in the code (the most common and
|
|
|
|
confusing error message is
|
|
|
|
[Infinite recursion encountered](https://discourse.nixos.org/t/infinite-recursion-encountered-by-making-module-configurable/23508/2)),
|
|
|
|
but where exactly is the error? The type system says it doesn't know, so you have to
|
|
|
|
find it yourself. In my experience, **the simplest and most effective way to deal with
|
|
|
|
these meaningless error messages is to use a "binary search" to gradually restore the
|
|
|
|
code**.
|
2023-12-26 07:09:02 +01:00
|
|
|
- This problem is probably the biggest pain point of NixOS at the moment.
|
2023-07-07 18:32:56 +02:00
|
|
|
- **More Complex Underlying Implementation**:
|
2024-03-16 12:29:05 +01:00
|
|
|
- Nix's declarative abstraction introduces additional complexity in the underlying code
|
|
|
|
compared to similar code in traditional imperative tools.
|
|
|
|
- This complexity increases implementation difficulty and makes it more challenging to
|
|
|
|
make custom modifications at the lower level. However, this burden primarily falls on
|
|
|
|
Nix package maintainers, as regular users have limited exposure to the underlying
|
|
|
|
complexities, reducing their burden.
|
2023-06-23 12:05:06 +02:00
|
|
|
|
2023-07-07 19:27:24 +02:00
|
|
|
## Summary
|
2023-06-23 12:05:06 +02:00
|
|
|
|
2024-03-16 12:29:05 +01:00
|
|
|
Overall, I believe that NixOS is suitable for developers with a certain level of Linux
|
|
|
|
usage experience and programming knowledge who desire greater control over their systems.
|
2023-07-07 18:32:56 +02:00
|
|
|
|
2024-03-16 12:29:05 +01:00
|
|
|
I do not recommend newcomers without any Linux usage experience to dive directly into
|
|
|
|
NixOS, as it may lead to a frustrating journey.
|
2023-07-07 18:32:56 +02:00
|
|
|
|
2024-03-16 12:29:05 +01:00
|
|
|
> If you have more questions about NixOS, you can refer to the last chapter of this book,
|
|
|
|
> [FAQ](../faq/).
|