mirror of
https://github.com/ryan4yin/nixos-and-flakes-book.git
synced 2024-12-12 09:50:42 +01:00
3.7 KiB
3.7 KiB
Advantages & Disadvantages of NixOS
Advantages
- Declarative configuration, Environment as Code, can be managed with Git
- Nix Flakes lock dependencies' version through a lock file named
flake.lock
, to ensure that the system is reproducible. This idea actually borrows from some package managers such as npm, cargo, etc. - Compared with Docker, Nix Flakes provides a much stronger guarantee for the reproducibility of build results, because Dockerfile is actually an imperative configuration and there is no such thing as
flake.lock
in Docker, Docker's reproducibility relies on sharing the build result(which is MUCH MORE LARGER than Dockerfile itself) through image registry(e.g. Docker Hub).
- Nix Flakes lock dependencies' version through a lock file named
- Highly convenient system customization capability
- By changing a few lines of configuration, various components of NixOS can be easily customized. This is because Nix encapsulates all the underlying complex operations in Nix packages and only exports concise and necessary declarative parameters.
- Moreover, this modification is very safe. For example, switching between different desktop environments on NixOS is very simple and clean, you just need to change several lines of the configuration.
- Rollback: The system can be restored to any historical state at any time(except the state that is NOT managed by NixOS, such as docker containers, postgresql data, etc...), and NixOS even adds all old versions to the boot options by default to ensure that the system can be rolled back at any time even though it crashes. Therefore, NixOS is also considered one of the most stable Linux Systems.
- No dependency conflicts: Because each software package in Nix has a unique hash, its installation path also includes this hash value, so multiple versions can coexist.
- The community is very active, and there are quite a few third-party projects. The official package repository, nixpkgs, has many contributors, and many people share their Nix configuration on Github/Gitlab. After browsing through it, the entire ecosystem gives me a sense of excitement in discovering a new continent.
Disadvantages
- High learning curve:: If you want the system to be completely reproducible and avoid pitfalls caused by improper use, you need to learn about the entire design of Nix and manage the system in a declarative manner. You cannot blindly use
nix-env -i
(which is similar toapt-get install
). - Chaotic documentation: Flakes is still an experimental feature, and there are currently few documents introducing it, Most of the Nix community's documentation only introduces the old cli such as
nix-env
/nix-channel
. If you want to start learning Nix directly from Flakes, you need to refer to a large number of old documents and extract what you need from them. In addition, some of Nix's current core functions are not well-documented (such asimports
and Nix Module System), to figure out what it does, it is best to look at the source code... - Relatively high disk space usage: To ensure that the system can be rolled back at any time, Nix preserves all historical environments by default, which can take up a lot of disk space. It can be a problem, especially on some resource-constrained Virtual Machines.
- Error messages may be obscure: Sometimes you may come across some strange error messages and don't understand what's going on.
--show- Trace
may throw you a stack of errors that are of little help.
Summary
Generally speaking, I think NixOS is suitable for developers who have some experience in using Linux and programming and want to have more control over their systems.
I don't recommend you get started with NixOS if you are new to Linux, it can be a very painful journey.