Why every device will soon be running Nix and resistance is futile!

September 30, 2024 #Nix #DevOps #Google Playstore #Apple App Store #PC superpower

In the realm of software package management, Nix stands out as a groundbreaking tool. It redefines how we think about dependencies, reproducibility, and software distribution. Really this is one of those things you can do with benefits of hindsight, it makes you wonder why didn't people do things this way in the first place. It was actually a doctorate paper by some guy in the Netherlands.

TL:DR

( If you have issues with visability due to the index overlaping with the content, zoom out a little bit please. There's a weird little sweet spot where you can't scroll left and right and the index is overlaping the table, you probably won't even see it on the phones )

AspectNixTraditional Package ManagersApp StoresF-Droid
Dependency HandlingPurely functional approach.Dependency resolution via metadata.Bundled dependencies or minimal shared libraries.Bundled dependencies, focuses on self contained apps
Each package has its own isolated environment.Shared library approach, managing dependencies centrally.Often uses containerized solutions (e.g., Snap, Flatpak).Uses APK format, typically includes required libraries.
Avoids "dependency hell" by allowing multiple versions.Can face "dependency hell" when conflicts arise.- Dependencies are bundled with apps or minimally shared.Avoids dependency hell by packaging dependencies.
Package/Binary HostingNixpkgs and NixOS channels as main sources.Central repositories (e.g., APT, RPM) managed by distros.- Centralized app stores (e.g., Apple App Store, Google Play).F-Droid repository hosting open-source APKs.
Binary cache servers for fast downloads.Mirrors and central repositories for binaries.- Hosted binaries in app stores' servers.Can add third-party repositories.
Source code and build recipes included.Often binary-focused, with some source packages.- Binary-focused distribution.Source code for apps is available, encouraging transparency.
DistributionDeclarative configuration for reproducibility.Procedural updates, manual configuration.- User-friendly, often automated updates.Apps updated through repository or manual download.
System state described by a single configuration file.Package updates handled individually.- Apps typically update independently and automatically.Manual updates or repository-based updates.
Rollback and VersioningAtomic upgrades and rollbacks for system-wide consistency.Limited to manual intervention or specific tools.- Some support for previous versions, mostly automatic.Versions can be reverted manually, older versions available.
Easy to revert to previous states with Nix.System snapshots (e.g., Btrfs, LVM) needed for rollback.- Older versions might not be available after updates.Allows installation of multiple versions of apps.
Isolation and SandboxingComplete isolation per package.Limited sandboxing, mainly relies on system-level isolation.- Sandboxing varies, generally per app (e.g., iOS, Android).Android app-level sandboxing.
Prevents interference between packages.Possible interference between installed packages.- Apps isolated, limited system access (sandboxed).Standard Android app sandboxing, enhanced privacy features.
ReproducibilityHigh reproducibility due to pure functional builds.Varies widely, not inherently reproducible.- Low, more dependent on specific device configurations.Medium, builds are reproducible if source code is verified.
User ExperienceMore complex setup, targeted at power users.Generally straightforward with good documentation.- Designed for ease of use, typically very user-friendly.Focus on simplicity, but manual updates can be cumbersome.
Command-line and declarative focus.Mix of command-line and GUI tools.- GUI-centric, minimal command-line interaction.GUI-centric, simple but less polished compared to major stores.
Flexibility and ControlHigh flexibility and control over package versions and environments.- Moderate, depends on the package manager and distro.- Low, users have less control over app versions and dependencies.High, users can choose app versions and customize repositories.
Custom environments and builds are easy to create.Custom builds require manual setup and configuration.- Customization is typically limited to app settings.Allows addition of custom repositories.
System State ManagementEntire system state managed declaratively.System and package state managed separately.- Focus on app state, system state management is separate.Focus on app management, not system state.
PerformancePotentially slower builds due to isolation.Varies, often optimized for the specific distro.- Generally optimized for the specific device platform.Performance is app-specific, Android optimizations.
Community and EcosystemStrong, niche community focused on advanced use cases.Large, diverse communities with broad support.- Wide user base, driven by platform vendors.Dedicated FOSS community, smaller but active.
SecurityStrong security through isolation and reproducibility.Security varies, often relies on system security.- App-level security with platform-level enforcement.Security through open-source transparency, verified apps.
Integration and CompatibilityExcellent for integrating with other tools in a development environment.Generally good, but can struggle with cross-distro compatibility.- Seamless integration with the platform but limited to apps.Integrates well with Android's ecosystem, focuses on open-source compatibility.

What is Nix?

Nix is a package manager and build system that promises deterministic builds and isolation from the traditional system state. It achieves this by treating packages and their dependencies as fully self-contained entities. Where as when a package is installed across the entire system ( Globally ) , it means that its files, configurations, and dependencies are placed in directories and locations accessible system-wide, rather than being contained within a specific isolated environment.

How Nix Manages Dependencies

  1. Immutable Package Store: Nix stores each package in its own directory, isolated from others, identified by a cryptographic hash of all inputs, including dependencies. This guarantees that different versions or variations of a package do not interfere with one another.

  2. Functional Approach: Nix uses a functional language to describe package build instructions. This means that each package's build is purely functional, producing the same output given the same input, ensuring reproducibility.

  3. Declarative System Configuration: NixOS, the Linux distribution built on Nix, allows users to define their entire system configuration in a single declarative file. This file captures the exact state of the system, making it easy to recreate or roll back to previous states.

  4. Garbage Collection and Rollbacks: Unused packages can be safely garbage-collected without risking system stability. Rollbacks are straightforward because the entire state is version-controlled.

Comparing Nix with Traditional Package Managers

Traditional Package Managers

Package managers like APT (for Debian-based systems) or Yum (for Red Hat-based systems) follow a more conventional approach:

Nix’s Advantages

App Stores: A Different Paradigm

App stores operate differently from traditional package managers or Nix:

F-Droid: The Open Source App Store

F-Droid is a repository of free and open-source applications for Android. It:

Conclusion

Nix introduces a transformative approach to package management with its functional, reproducible, and isolated system. It stands in contrast to traditional package managers and curated app stores like F-Droid, which have their own strengths but also face challenges that Nix elegantly addresses. Whether managing server environments, development tools, or entire operating systems, Nix’s model offers a robust solution for avoiding dependency conflicts and ensuring system consistency.


F-Droid - Free and Open Source Android App Repository

Nix - Best package manager