From Fedora Project Wiki

Nix package tool

Summary

Add the nix functional package manager developer tool to Fedora.

Owner


Current status

Detailed Description

Nix is a cross-platform package manager for Unix-like systems with its own package ecosystem. It is also the package manager for the NixOS Linux operating system. The nix package tool provides access to the nixpkgs ecosystem with over 100,000 packages. Packages and environments can be specified in nix's declarative functional programming language using so-called derivations. Nix flakes provide a newer way to specify these project development environments.

Nix has two main modes of installation/setup: multi-user mode (with nix-daemon) and single-user mode (below these are abbreviated as "multiuser" and "singleuser" respectively). The Fedora package tries to support both of them, though multiuser mode setup where available is more seamless. It does this by providing nix-daemon and nix-system subpackages which both require nix-filesystem. The /nix toplevel directory is defined with tmpfiles.d and can be a Btrfs subvolume if setup.

Note: for any avoidance of doubt, nix-managed packages will not become part of the Fedora distribution, and no QA or support will be provided for them. This is similar to how e.g. pip can be used to install Python packages from external locations, or how flatpak can install flatpaks not produced by Fedora.

Feedback

Benefit to Fedora

Some developers and upstream projects now prefer or use nix for development and reproducible build environments. Just as we have apt and zypper packaged in Fedora, this change adds a nix package allowing access to its ecosystem from Fedora.

With the implementation of this Change, Fedora users will be able to install nix easily on their system and leverage it in development projects that may require nix. They will also be able to easily try out some of the many packages in nixpkgs for testing or experimenting, etc.

For some time I have maintained a nix copr repo which is quite popular (see the download numbers and note a number of other nix copr repos also exist), but it will be easier for Fedora users to have the nix package directly available from Fedora repos.

Scope

  • Policies and guidelines:
    • FESCO has approved an exception to allow the /nix toplevel directory to be used at runtime, as it is needed to make full use of nixpkgs and binary package caches, etc.
    • The approved exception has been documented [pr]
    • To be clear: nix and its subpackages will remain optional development packages that Fedora users can install manually if they wish, and in particular /nix which is owned by nix-filesystem is not going to be used for Fedora Linux development and will not be pulled in by the base Fedora filesystem package.
  • Trademark approval: N/A (not needed for this Change)
  • Alignment with the Fedora Strategy:

Upgrade/compatibility impact

How To Test

Installation/setup:

Either:

  • Multiuser daemon mode:
    • sudo dnf install nix nix-daemon
    • sudo systemctl enable --now nix-daemon

or

  • Singleuser rootful mode (specially in containers)
    • sudo dnf install nix --exclude nix-daemon
    • sudo usermod -aG nixbld $USER

or

  • Singleuser rootless mode (no system /nix):
    • sudo dnf install nix-core nix-legacy

(Note for rpm-ostree, stateful nix-legacy commands do not work (since they require /nix bootstrap), so just installing nix-core may be sufficient.)

See also https://src.fedoraproject.org/rpms/nix (/usr/share/doc/nix/README.fedora.md).

Then try out the tool:

  • nix shell nixpkgs#hello (modern flake) or nix-shell -p hello (legacy)
    • this puts you in a nix shell where you can run 'hello' (note for the flake the prompt does not change by default)
    • you can also try: nix run nixpkgs#hello
  • nix develop nixpkgs#empty (empty flake)
  • nix eval nixpkgs#zed-editor.version
    • note you can use Tab completion with nix subcommands (down to the package level and below)
  • try the *.nix examples in https://src.fedoraproject.org/rpms/nix/blob/rawhide/f/examples
  • nix search nixpkgs <package-regexp>
  • try online projects or documentation examples

Notes:

  • Upstream recommends using the nix-daemon multiuser mode.
  • /nix is incompatible with rpm-ostree: so on ostree systems one should use nix either within a toolbox container or nix-core with a rootless mode installation.
    • (Some work is ongoing to try to bind mount to /nix for bootc Image Mode)
  • Since containers generally do not have functioning systemd: it is not possible to use nix-daemon inside containers by default
  • Be warned that nix can easily use up large amounts of diskspace. You can use nix-collect-garbage (or nix store gc) to clean up or clear /nix/store/. After uninstalling nix*, it should be safe to rm -r /nix/ to recover space. You can also check ~/.local/share/nix/root/nix/store/ for rootless mode.
  • Please use nix and nixpkgs etc at your own risk, as you would other upstream community ecosystem packages.

User Experience

Fedora users can now easily install and use the Nix package manager for development or running its packages locally on their system.

Dependencies

There are no blocking dependencies. However:

  • newer boost library (1.87 or later) would allow updating to latest nix 2.32 [tracker]
  • mdbook (rust-based documentation tool) would allow building the manual [old review]


Contingency Plan

  • Contingency mechanism: (What to do? Who will do it?) N/A (not a System Wide Change)
  • Contingency deadline: N/A (not a System Wide Change)
  • Blocks release? N/A (not a System Wide Change)

Documentation

Release Notes

  • The Nix package manager developer tool has been packaged in Fedora for users.