pdtpartners/nix-ninja
{ "createdAt": "2025-03-29T12:34:55Z", "defaultBranch": "main", "description": "Ninja-compatible incremental build system for Nix", "fullName": "pdtpartners/nix-ninja", "homepage": "", "language": "Rust", "name": "nix-ninja", "pushedAt": "2025-09-07T07:35:11Z", "stargazersCount": 220, "topics": [ "build-system", "ninja", "nix", "nixos" ], "updatedAt": "2025-11-26T02:01:59Z", "url": "https://github.com/pdtpartners/nix-ninja"}nix-ninja
Section titled “nix-ninja”Incremental compilation of [Ninja build files][ninja-build] using [Nix Dynamic Derivations][dynamic-derivations].
Choosing ninja as the build graph representation lets us support any build system that outputs ninja like CMake, meson, premake, gn, etc.
[Key features]!(#key-features) • [Getting started]!(#getting-started) • [Design notes][design notes] • [Contributing]!(CONTRIBUTING.md)
Key features
Section titled “Key features”[!IMPORTANT] There are still major todos, and depends on experimental features from an unreleased version of Nix. Come help us get nix-ninja to be useful day-to-day and working with an official Nix release!
- Parses
ninja.buildfiles and generates a derivation per compilation unit. - Stores build inputs & outputs in content-addressed derivations for granular and Nix-native incrementality.
- Compatible CLI for ninja, so if you set
$NINJAtonix-ninjathen meson just works. - Supports running locally (which runs
nix buildon your behalf), or inside a Nix derivation (which creates dynamic derivations).
Getting started
Section titled “Getting started”First you need to use Nix 2.30 or later (newer than stable) and enable the following experimental features:
experimental-features = ["nix-command" "dynamic-derivations" "ca-derivations" "recursive-nix"]Then you can try building the examples:
# Builds a basic main.cpp.nix build github:pdtpartners/nix-ninja#example-hello
# Builds a basic main.cpp with dependency inference for its header.nix build github:pdtpartners/nix-ninja#example-header
# Builds Nix 2.27.1.nix build github:pdtpartners/nix-ninja#example-nixYou can also try running nix-ninja outside of Nix, but you’ll need both
nix-ninja and nix-ninja-task to be in your $PATH. Make sure
nix-ninja-task is from the /nix/store as it is needed inside derivations
nix-ninja generates.
export NIX_NINJA=$(nix build --print-out-paths)export PATH="${NIX_NINJA}/bin:$PATH"# Meson respects this environment variable and uses it as if its ninja.export NINJA="${NIX_NINJA}/bin/nix-ninja"Then you can go to an example and run it like so:
$ nix-shell$ cd examples/hello$ meson setup build$ cd build$ meson compile hello$ ./helloHello Nix dynamic derivations!Contributing
Section titled “Contributing”We still have major TODOs, so would appreciate any help. We’ve organize them under two [GitHub milestones][milestones] !:
0.1.0- The first release ofnix-ninjaaiming for correctness.0.2.0- Major performance features to make incremental builds productive.
Regardless, pull requests are welcome for any changes. Consider opening an issue to discuss larger changes first, especially when the design space is large.
Please read [CONTRIBUTING]!(CONTRIBUTING.md) and the [design notes] so you understand the big picture and prior art.
License
Section titled “License”The source code developed for nix-ninja is licensed under MIT License.
[design notes] !: docs/design.md [dynamic-derivations] !: docs/dynamic-derivations.md [milestones] !: https://github.com/pdtpartners/nix-ninja/milestones [ninja-build] !: https://ninja-build.org/