Why I love Nix



2025-02-02

Let’s be real: modern computing is a dependency hellscape. Ever tried compiling a "complex" piece of software from scratch? Even if you somehow track down every single dependency—and their correct versions, and their configurations—chances are, you’ll still hit a wall. Where are these big projects that used to compile with a command?

NixOS and the Nix package manager have revolutionized how I approach system configuration, development environments, and reproducible builds. Below, I break down the technical aspects that make Nix indispensable, complete with code examples and practical insights.

"Nix is a tool that takes a unique approach to package management and system configuration" and NixOs a Linux distro built above this paradigm.

The Flakes The Modern Way

The flakes experimental feature is a major development for Nix, it introduces a policy for managing dependencies between Nix expressions, it improves reproducibility, composability and usability in the Nix ecosystem. Although it's still an experimental feature, flakes have been widely used by the Nix community. Similar to your package.json, you have your flake.nix. Your package-lock.json flake.lock.

As the nix paradigm defines, everything is self-contained. So you can define your entire system, a development environment, or even a production deployment using flakes, and anyone with Nix can spin it up instantly——no more ‘it works on my machine’ headaches”.

On the other hand, Flakes experimental features did not break Nix's original design at the user level. The two new files flake.nix/flake.lock introduced by Flakes are just a wrapper for other Nix configurations

The benefits of Flakes are evident, and the entire NixOS community has embraced it wholeheartedly. Currently, more than half of the users utilize Flakes, providing assurance that Flakes will not be deprecated.

Want to replicate your setup on another machine? Clone the flake and run nixos-rebuild. Done.

NixOS: Atomic System Management & The Future of Declarative Infrastructure

What truly sets NixOS apart is its declarative, atomic approach to system services. Enabling a service like services.ssh.enable = true; isn’t just a configuration toggle—it triggers a meticulously orchestrated chain of events.

1. Dependency Resolution: Nix calculates exactly which OpenSSH version, config files, and runtime dependencies (like PAM or SSL libraries) are neeeded.

2. Isolated Build: The service and its dependencies are built in a sandboxed environment, isolated from your current system state.

3. Atomic Activation: The entire system configuration—kernel modules, firewall rules, SSH server binaries, and even /etc/ssh/sshd_config—is assembled into a single immutable generation. When you run nixos-rebuild switch, NixOS atomically switches to this new generation via a symlink flip at /nix/var/nix/profiles/system. No half-configured states. No dangling processes.

Why Atomic Updates Matter

Traditional package managers modify /usr live, risking conflicts (e.g., a failed apt upgrade leaving your system in limbo). NixOS avoids this entirely:

1. Rollbacks are trivial: Reboot into any previous generation from your bootloader. Each generation is a complete, working system.

2. No "works on my machine": Deploy the same configuration to a server, and you’ll get bit-for-bit identical behavior, thanks to content-addressed storage.

3. SteamOS/Fedora Silverblue Parallels: Like Valve’s SteamOS (immutable base + transactional updates), NixOS treats the OS as a build artifact. But NixOS takes it further—every component (kernel, services, user apps) is managed through the same declarative pipeline.

The Bigger Picture: Systems as Declarative Artifacts

NixOS isn’t just a Linux distro—it’s a blueprint for the future of systems engineering. The same principles power tools like Kubernetes (declarative infrastructure) and Terraform (immutable cloud resources).

While SteamOS and others adopt immutability for stability, NixOS adds flexibility—you declare what you want, and Nix handles the how, whether you’re configuring a Raspberry Pi or a Kubernetes node. It’s not just an OS—it’s a paradigm shift.

Future of Nix

Projects like Lix (a community-driven Nix fork) and NixOps (for cloud deployments) highlight Nix's growing ecosystem. Companies like Google use Nix internally for reproducible builds and new public projects (idx).

Conclusion

NixOS isn’t just a Linux distribution—it’s a paradigm shift. Nix provides unparalleled reproducibility, isolation, and flexibility. While the learning curve is steep, the payoff in productivity and reliability is immense.

Resources:

Nix Pills: Master the Nix language through bite-sized tutorials.

NixOS Wiki: Community-driven guides and best practices.

Zero to Nix: Modern introduction to Nix concepts.

NixOS