Nix (package manager)
{{Short description|Purely functional package manager}}
{{Infobox software
| name = Nix
| released = {{start date and age|2003|6|15}}
| latest release version = {{Wikidata|properties|references|edit|P348}}
| latest release date = {{Start date and age|{{Wikidata|qualifier|P348|P577}}}}
| latest preview version = {{Wikidata|properties|references|edit|P348|P548=Q51930650}}
| latest preview date = {{Start date and age|{{Wikidata|qualifier|single|P348|P548=Q51930650|P577}}}}
| programming language = {{Wikidata|properties|references|edit|P277}}
| author = Eelco Dolstra
| platform = {{Wikidata|properties|references|edit|P306}}
| genre = {{Wikidata|properties|references|edit|P31}}
| license = {{Wikidata|properties|references|edit|P275}}
| website = {{URL|https://nixos.org}}
}}
Nix is a cross-platform package manager for Unix-like systems, and a tool to instantiate and manage those systems, invented in 2003{{cite book |last=Dolstra |first=Eelco |title=Software Configuration Management |year=2003 |isbn=978-3-540-14036-8 |series=Lecture Notes in Computer Science |volume=2649 |pages=102–117 |chapter=Integrating Software Construction and Software Deployment |doi=10.1007/3-540-39195-9_8 |chapter-url=https://nixos.org/~eelco/pubs/iscsd-scm11-final.pdf |archive-url=https://web.archive.org/web/20190421081837/https://nixos.org/~eelco/pubs/iscsd-scm11-final.pdf |archive-date=2019-04-21 |url-status=dead}} by Eelco Dolstra.
Approach
The Nix package manager employs a model in which software packages are each installed into unique directories with immutable contents. These directory names correspond to cryptographic hashes that take into account all dependencies of a package, including other packages managed by Nix. As a result, Nix package names are content-identifying since packages with the same name will have had the same inputs and the same build platform, and therefore the same build result.
Implementation
Package recipes for Nix are written in the purpose-built "Nix language", a declarative, purely functional, lazily evaluated, dynamically typed programming language.{{cite web|title=Nix Reference Manual: Nix Language|url=https://nixos.org/manual/nix/stable/language/|access-date=4 March 2024}} Distinguishing features of the Nix language are strings with "context", string interpolation, first-class file system paths, and "indented strings", which in combination allow concisely expressing dependencies between file system data when specifying the contents of new files.
Dependencies between files, as declared in the Nix language, are automatically tracked and persisted in the "Nix store".{{cite web|title=Nix Reference Manual: Nix Store|url=https://nixos.org/manual/nix/stable/store/|date=4 March 2024}} New files in the Nix store are created through "derivations". A derivation is a persistent data structure that specifies an executable, arguments and environment variables for its invocation (see execve
), and other files to be read from the Nix store. The executable is then run in a sandbox that prohibits access to anything but the explicitly specified input files and only allows writing to the designated output path. Nix preserves dependency information in output files by scanning for the distinctive hashes used for package directory names.
Automatic reference tracking ensures integrity of packages, even when they are transferred across machines. It also enables garbage collection of unused packages when no other package depends on them. At the cost of greater storage requirements, all upgrades in Nix are guaranteed to be both atomic and capable of efficient rollback. Unique directory names allow installing many packages with differing versions of shared libraries, and is claimed to eliminate so-called dependency hell.{{cite web |last1=Prins |first1=Pjotr |last2=Suresh |first2=Jeeva |last3=Dolstra |first3=Eelco |title=Nix fixes dependency hell on all Linux distributions |url=https://www.linux.com/news/nix-fixes-dependency-hell-all-linux-distributions/ |website=Linux.com |access-date=11 July 2023 |date=22 December 2008}} This also lets multiple users safely install software on the same system without administrator privileges. As a result, the Nix package management and deployment model advertises more reliable, reproducible, and portable packages.{{cite conference |last1=Dolstra |first1=Eelco |last2=de Jonge |first2=Merijn |last3=Visser |first3=Eelco |title=Nix: A Safe and Policy-Free System for Software Deployment |book-title=LISA '04: Proceedings of the 18th USENIX Conference on System Administration |date=November 2004 |pages=79–92 |url=https://edolstra.github.io/pubs/nspfssd-lisa2004-final.pdf |access-date=11 July 2023}}{{cite thesis |type=Ph.D. |last1=Dolstra |first1=Eelco |title=The Purely Functional Software Deployment Model |date=2006 |url=https://nixos.org/~eelco/pubs/phd-thesis.pdf |access-date=11 July 2023 |publisher=Utrecht University}}
Nix has full support for Linux, macOS, and WSL, and can safely be installed side-by-side with another package manager.
= Nixpkgs =
Nixpkgs is the package repository built upon the Nix package manager. According to Repology, {{as of|2025|January|lc=y}} it contains more than 122,000 packages{{cite web |title=Nixpkgs unstable repository information - Repology |url=https://repology.org/repository/nix_unstable |archive-url=https://web.archive.org/web/20250115123328/https://repology.org/repository/nix_unstable |archive-date=2025-01-15}} and has a higher number of up-to-date packages than any other package repository.{{cite web | url=https://repology.org/repositories/statistics/newest | title=Repository statistics - Repology }} Operating systems supported by Nixpkgs are primarily Linux and Darwin, with some support for Windows and BSD variants. Supported CPU architectures include 64-bit x86 and ARM. Packages for these architectures are built regularly, using a continuous integration service called Hydra,{{cite web | url=https://github.com/NixOS/rfcs/blob/master/rfcs/0046-platform-support-tiers.md | title=RFC 0046 - Platform Support Tiers| website=GitHub}} and the results of these builds are uploaded to a public binary cache.{{cite web | url=http://cache.nixos.org/ | title=NixOS official binary cache}} When Nix installs a package, it checks this cache and downloads the binary package to avoid building it locally.
Nixpkgs is developed in a single Git repository on GitHub.{{cite web | url=https://github.com/NixOS/nixpkgs | title=Nixpkgs github repository | website=GitHub }} Beside packages, it also contains the source code for NixOS.
Projects using Nix
NixOS{{Cite web|url=https://nixos.org/|title=Nix & NixOS | Reproducible builds and deployments|website=nixos.org}} is a Linux distribution that uses Nix for managing the entire system configuration, including the Linux kernel.{{cite conference |last1=Dolstra |first1=Eelco | last2=Löh | first2=Andres | last3 = Pierron | first3=Nicolas |title=NixOS: A Purely Functional Linux Distribution |conference=ICFP 2008: 13th ACM SIGPLAN International Conference on Functional Programming |date=September 2008 |pages=367–378 |url=https://edolstra.github.io/pubs/nixos-jfp-final.pdf}}
Nix is used for software packaging and distribution in CERN's LHCb experiment.{{Cite web |last1=Burr |first1=Chris |last2=Clemencic |first2=Marco |last3=Couturier |first3=Ben |date=2018 |title=Software packaging and distribution for LHCb using Nix |url=https://cds.cern.ch/record/2700235/files/10.1051_epjconf_201921405005.pdf}} Nix underlies the distributed software development platforms Replit{{Cite web |last=Replit |date=2023-05-25 |title=Replit — Super Colliding Nix Stores: Nix Flakes for Millions of Developers |url=https://blog.replit.com/super-colliding-nix-stores |access-date=2024-03-05 |website=Replit Blog}} and Firebase Studio.{{Cite web |title=Customize your IDX workspace {{!}} Project IDX |url=https://developers.google.com/idx/guides/customize-idx-env |access-date=2024-03-05 |website=Google for Developers |language=en}}
Forks and alternative implementations
In 2021, a reimplementation by the name [https://tvix.dev Tvix] was announced,{{Cite web |title=TVL's blog: Tvix: We are rewriting Nix |url=https://tvl.fyi/blog/rewriting-nix |access-date=2024-05-19 |website=tvl.fyi}} with the goals of modularity, full compatibility with Nixpkgs, and improved evaluator performance. As of 2024, Tvix has an evaluator{{Cite web |title=TVL's blog: Tvix Status - September '22 |url=https://tvl.fyi/blog/tvix-status-september-22 |access-date=2024-05-19 |website=tvl.fyi}} and a store implementation,{{Cite web |title=TVL's blog: Tvix Status - February '24 |url=https://tvl.fyi/blog/tvix-update-february-24 |access-date=2024-05-19 |website=tvl.fyi}} though the authors do not consider the project yet stable or ready for use in production.{{Citation |title=tvlfyi/tvix |date=2024-05-18 |url=https://github.com/tvlfyi/tvix |access-date=2024-05-19 |publisher=The Virus Lounge}}{{Primary source inline|date=May 2024}} Tvix is written primarily in Rust.{{Cite web |title=tvix - depot - Sourcegraph |url=https://cs.tvl.fyi/depot/-/tree/tvix |access-date=2024-05-19 |website=cs.tvl.fyi}}
In 2024, a team of volunteers released the first version of [https://lix.systems Lix],{{Cite web |title=Lix {{!}} About Lix |url=https://lix.systems/about/ |access-date=2024-05-19 |website=lix.systems}}{{Primary source inline|date=May 2024}} a fork of Nix focused on correctness and compatibility that uses the Meson build automation system. The project intends to gradually rewrite parts of the code in Rust.
See also
{{Portal|Free and open-source software}}
- GNU Guix: another declarative package manager, and early clone of Nix, using GNU Guile for configuration and customization
- Maak: a build automation utility similar to make, and early precursor to Nix
- Runbook automation
References
{{reflist}}
External links
{{Wikidata property | P12433 }}
- {{Official website}}
- {{github|nixos/nix|Nix}}
- [https://lists.debian.org/debian-devel/2008/12/msg01027.html Discussion among developers] on the Debian mailing list (2008)
{{Package management systems}}
Category:Data management software
Category:Free computer programming tools
Category:Free package management systems
Category:Functional programming
Category:Linux package management-related software
Category:Configuration management
Category:Software using the GNU Lesser General Public License