Open source · LGPL-2.1-or-later

The Nix package manager, rebuilt in Rust with the EU CRA in mind.

cranix is a from-scratch implementation of Nix: the language, the store and the builder. It is bit-compatible with Nix 2.24, so the same expression gives the same .drv path, and it is built to make software supply chains easy to account for.

  • bit-identical .drv paths to Nix 2.24, down to the darwin stdenv bootstrap
  • −23 % peak memory evaluating hello from nixpkgs (157 vs. 205 MiB)
  • 0.25 s to evaluate hello.drvPath, on par with Nix at 0.29 s
  • ~115 builtins, checked against Nix by a differential test suite

The name

A crane that lifts packages

cranix brings together two things: compliance work under Europe’s new product security law, and a bird that has carried symbolism for a very long time.

CRA · nix

The Cyber Resilience Act

The EU Cyber Resilience Act asks makers of software to know exactly what goes into a product, to handle vulnerabilities and to document both. A Nix closure already is an exact, hash-pinned bill of materials. cranix is built to turn that into the reports the regulation asks for.

Kranich

The common crane /ˈkʁaːnɪç/

Kranich is German for crane, and cranix is pronounced the same way: /ˈkʁaːnɪç/. The grey bird with the red crown gave its name to the machine that lifts loads into place, and the logo is both: a crane with a long beak like a jib, lifting a package.

Design

Written against Nix’s behaviour, shaped by Rust

cranix follows the specification of what Nix does: store path fingerprints, ATerm, NAR and the evaluation semantics. It is not a line-by-line translation of the C++ code. Small library crates hold the formats, so other tools can hash, read NARs and handle derivations without pulling in an evaluator.

Evaluator

A hand-written parser feeds a compile pass that resolves every statically bound variable to a (depth, slot) pair, so undefined variables are reported before evaluation starts. Values are 16 bytes; attribute sets are sorted vectors of interned symbols, and a // b on a large a is a layer instead of a copy.

Store

A store has a logical directory, the one baked into hashes, and a physical one. By default objects live in your home directory while paths stay /nix/store, so results match a regular Nix install without root. Metadata is one small file per path, written atomically.

Builder

A ready-queue scheduler over a thread pool builds the derivation graph in parallel, after fetching what it can from signed binary caches. Builders run sandboxed with Nix’s environment, or on remote machines; outputs are scanned for references and fixed-output hashes are verified.

Features

From the language to the supply chain

Everything marked available is on the main branch and checked against Nix by its test suites. The supply-chain tooling comes next.

Available

  • Nix language evaluator

    The full language with with, rec, formals, string contexts, search paths and import from derivation. It evaluates nixpkgs, including lib and the module system.

  • Store and garbage collection

    NAR serialisation, reference scanning, closures, GC roots and collection, and verification, in a store that needs no root.

  • Parallel builder

    Builds whole derivation graphs with -j jobs, multiple outputs, fixed-output derivations, time limits and per-derivation logs.

  • Sandboxed builds

    Builds run isolated from the network and the rest of the system, seeing only their declared inputs, on Linux and macOS.

  • Binary caches

    Substitution from file:// and HTTP caches with signed .narinfo files, copy to caches Nix reads, and signing keys.

  • Daemon and remote builders

    The Nix daemon protocol in both directions: Nix clients can use a cranix store, and cranix can use a Nix daemon. Builds go to other machines over ssh-ng:// or ssh://.

  • Flakes and fetchers

    Flakes with lock files, the flake registry, and fetchGit, fetchTarball and fetchTree for Git, GitHub, GitLab and tarballs.

  • Content-addressed derivations

    Outputs addressed by what they contain, and impure derivations, with realisations recorded in the store and the same paths as Nix.

  • Error messages, TOML and XML

    Errors that point at the source with a hint, readable stack traces, and fromTOML and toXML.

Planned

  • SBOM generation

    A software bill of materials for any closure, in standard formats, straight from the derivation graph.

  • Vulnerability scanning

    Match the components of a closure against known vulnerabilities and report which builds are affected.

  • Build provenance

    Signed statements of what was built from which inputs, on which machine, so a release can be traced back to its sources.

  • Registry caches and upload while building

    Binary caches in GitLab and GitHub package registries, filled as each output is finished instead of after the whole build.

  • Faster repeated evaluation

    Compiled Nix files and flake evaluation results cached on disk, so evaluating the same package set again skips most of the work.

Performance

As fast as Nix, with less memory

Evaluating (import <nixpkgs> {}).<attr>.drvPath with both tools. Both print the same path.

Apple M-series (aarch64-darwin), nixpkgs 24.11pre, best of three runs, .drv files already in both stores.
Attribute Nix 2.24 time cranix time Nix peak memory cranix peak memory
hello 0.29 s 0.25 s 205 MiB 157 MiB
python3 0.29 s 0.26 s 206 MiB 160 MiB
git 0.36 s 0.35 s 265 MiB 225 MiB

Memory is reference counted, with no tracing garbage collector and no global evaluator state. Overlays and bootstrap stages layer over the shared package set instead of copying it, and mapAttrs results share one function and the interned attribute name.

Correctness is pinned to Nix: unit tests fix hashes, store paths and .drv paths to the values Nix produces, and a differential suite evaluates the same corpus with both tools, from the builtins to the drvPaths of hello, python3 and git.

Get started

Build it, then point it at nixpkgs

cranix builds with a stable Rust toolchain and Cargo. It reads store paths it does not have from the host’s /nix/store, so an existing nixpkgs checkout works directly.

  1. Build from source

    git clone https://github.com/tmmy-cc/cranix.git
    cd cranix
    cargo build --release
  2. Evaluate a package

    target/release/cranix eval nixpkgs#hello.drvPath
    "/nix/store/…-hello-2.12.1.drv"
  3. Build into a store of your own

    target/release/cranix --store ~/cranix-store build tests/build.nix -j 8 -L

Commands: eval, instantiate, build, run, shell, develop, flake metadata|show|lock|update|check|init|new, copy, daemon, show-derivation, realisation info, hash, key, nar dump|restore and store add|path-info|sign|closure|ls|verify|gc|serve. Global options include --store, --builders, --option, --show-trace, -I, --arg, --argstr, --system and --pure.

Read the code, run the tests.

Each crate does one job, from hashing and NAR files to the daemon, and the test suites pin their behaviour to Nix’s output. Issues and pull requests are welcome.