Skip to content
Oeiuwq Faith Blog OpenSource Porfolio

psyclyx/fix

Fast nIX language evaluator

psyclyx/fix.json
{
"createdAt": "2026-06-26T08:38:03Z",
"defaultBranch": "main",
"description": "Fast nIX language evaluator",
"fullName": "psyclyx/fix",
"homepage": "",
"language": "Zig",
"name": "fix",
"pushedAt": "2026-08-03T00:32:09Z",
"stargazersCount": 35,
"topics": [
"bytecode",
"debugger",
"evaluator",
"home-manager",
"nix",
"nix-lang",
"nixos",
"zig"
],
"updatedAt": "2026-08-03T22:22:29Z",
"url": "https://github.com/psyclyx/fix"
}

![fix]!(demo/banner.svg)

fix is a fast, parallel evaluator and command-line tool for the Nix language, written in Zig.

It is a from-scratch implementation, not a wrapper around the Nix evaluator. fix parses Nix source, compiles it to bytecode, evaluates expressions lazily, computes derivations and store paths, and speaks the Nix daemon protocol for store operations and builds. It is intended to run existing Nix expressions and produce the same values and derivations while making evaluation faster.

fix also treats the evaluator as something you should be able to inspect. It includes a heap and bytecode explorer, a source-level debugger, an interactive REPL, evaluation statistics, and Perfetto-compatible traces.

![Exploring a running evaluation with fix]!(demo/explorer.gif)

fix can evaluate thunk work on multiple worker threads. A thunk contains a Future: one fiber claims an unresolved thunk, while another fiber that reaches the same in-flight thunk can park and let its worker run something else. Speculative forcing and strict-demand fan-out provide work for otherwise idle workers; both can be disabled when diagnosing parallel behavior.

The worker count is configurable, including a single-worker mode when repeatability or debugging matters more than throughput. Memory is managed by a parallel generational garbage collector.

The core concurrency protocols — future wait, fiber dispatch, shutdown, and the GC barrier — are [modeled in TLA+]!(model/README.md) and checked for safety, deadlock freedom, and liveness. A nightly CI lane evaluates real configurations in parallel against a reference Nix under ThreadSanitizer.

Compatibility is a target backed by several kinds of tests:

  • Derivation tests cover canonical ATerm serialization, hashing, string context, and expected .drv and output store paths.
  • The pinned Lix and snix language suites compare evaluation and parse results.
  • A separate differential test evaluates every benchmark fixture with fix and a reference Nix, then compares the strict JSON results structurally.
  • A whole-nixpkgs differential evaluates the entire nixpkgs CI job universe (ci/eval/outpaths.nix, about 80,000 derivations) with fix and a reference Nix and compares every .drv store path. A drvPath match certifies the complete derivation that produced it — inputs, environment, and builder, transitively.
  • fix parse emits the same JSON-shaped syntax tree used by nix-instantiate --parse.

The current pinned language suites pass, and the pinned nixpkgs universe evaluates to identical derivation paths (80,586 of 80,586 attributes, including agreement on which attributes fail to evaluate). See [the language-test documentation]!(test/lang/README.md) for exactly what is run. The nixpkgs differential runs monolithically with zig build test-nixpkgs (it wants a large-memory machine and caches the reference results per pin) and as a sharded matrix in CI.

The VM explorer and debugger are part of fix, rather than separate instrumented builds. They operate on the real compiler, bytecode, stacks, thunks, and heap used by ordinary evaluations.

The explorer can move from source expressions to compiled chunks and instructions, inspect heap objects and their references, search stores, and set breakpoints. Large chunk and object collections are represented with range nodes and bounded queries rather than one UI row per entry.

The debugger supports:

  • pending and resolved source-line breakpoints;
  • builtins.break and stops on evaluation errors;
  • step, next, finish, and continue;
  • lexical locals, captured values, the operand stack, and annotated bytecode;
  • evaluating a Nix expression in the scope of the current pause; and
  • opening the VM explorer without leaving the debugging session.

fix eval --debugger and fix repl --debugger use one worker. A transient :debug session in an ordinary REPL temporarily disables parallel submissions.

![A source breakpoint in the fix debugger]!(demo/debugger.gif)

This demo first evaluates a NixOS toplevel, then starts a debugger session while that evaluation’s heap remains available to inspect.

![Debugging after a NixOS evaluation with a large retained heap]!(demo/nixos-debugger.gif)

fix is alpha-quality software under active development. Development currently takes place on x86_64 Linux; other platforms have not received the same level of use.

Nix is not required to build fix. A direct build requires Zig 0.16, pkg-config, libcurl, and libgit2:

Terminal window
$ git clone https://github.com/psyclyx/fix
$ cd fix
$ zig build --release=fast

The executable is zig-out/bin/fix. Alternatively, Nix can provide the pinned build environment and dependencies:

Terminal window
$ nix-shell --run 'zig build --release=fast'

Evaluation does not require a Nix or Lix executable; store-writing commands need a reachable Nix or Lix daemon. Tagged releases publish optimized build archives for x86_64 Linux, aarch64 Linux, and aarch64 macOS.

Terminal window
$ ./zig-out/bin/fix eval -E '1 + 2'
3
$ ./zig-out/bin/fix build -A fix
$ ./zig-out/bin/fix repl

The package also includes shell completions for Bash, Fish, and Zsh.

fix speaks the stable Nix worker protocol to CppNix and Lix daemons (Nix ≥ 2.4) over daemon, unix://, tcp://, and ssh-ng:// stores. local/auto stores and Lix’s experimental lix-xp-1 protocol are not implemented and fail explicitly — nothing falls back to an installed Nix. The selector matrix and configuration details are in [Nix/Lix store compatibility]!(docs/store-compatibility.md).

<nixpkgs> and other lookup paths resolve like Nix’s: from -I, then $NIX_PATH, and — when neither is set — from the user and root channel profiles, so a machine configured purely through nix-channel works without any environment setup.

builtins.nixVersion deliberately reports 2.18.3: it is the evaluator compatibility baseline, not the version of the connected daemon. Supported experimental and deprecated language switches are listed in [the CLI reference]!(docs/cli.md#evaluation—output).

fix covers the common path from evaluating an expression to realizing and running its output:

CommandPurpose
fix evalEvaluate expressions, files, attributes, or flake outputs
fix instantiateEvaluate derivations and write their .drv files
fix buildEvaluate and build derivations, with result links and GC roots
fix runBuild an installable and run its declared program
fix shellEnter a shell containing selected packages
fix print-dev-envEmit a derivation’s build environment as a shell script
fix replEvaluate interactively and enter the explorer or debugger
fix parseParse Nix and emit a compatible JSON syntax tree
fix disasmCompile an expression and print its bytecode
fix flakeShow, check, lock, update, and inspect flake metadata
fix switchBuild and activate a system or user configuration
fix completionsGenerate shell completions

Run fix <command> --help for the documented inputs and options.

Commands accept expressions, file paths, attribute paths, and repeated mixed inputs. File paths are positional, and omitting the source uses ./default.nix:

Terminal window
$ fix eval -E '{ answer = 6 * 7; }' -A answer
42
$ fix eval --strict --json packages.nix
$ fix instantiate -A fix
/nix/store/...-fix.drv
$ fix build -A fix

Arguments can be supplied with --arg and --argstr. Evaluation can produce Nix, JSON, XML, or raw output, and can be made strict. Builds can target direct Unix-socket, SSH, and TCP daemon endpoints.

Terminal window
$ fix run --flake nixpkgs#hello
$ fix shell -p ripgrep jq

fix run builds the selected installable and chooses its executable from meta.mainProgram, pname, or name. fix shell constructs and realizes an environment containing the requested packages.

Flake commands require Nix’s flakes experimental feature. Enable it in nix.conf, or pass it for an invocation:

Terminal window
$ fix flake show . --extra-experimental-features flakes

fix print-dev-env evaluates a derivation and prints a Bash program that reconstructs its build environment without building the derivation:

Terminal window
$ eval "$(fix print-dev-env ./shell.nix)"

The included direnv integration provides use fix and use fix_flake. See [the direnv documentation]!(contrib/direnv/README.md) for installation and options.

fix switch can build and activate NixOS configurations. It also implements the conventional nix-darwin and Home Manager activation paths, although those two have not been verified locally. It supports switch, boot, test, build, and dry-activate actions. When supplied, the action must be the first argument after fix switch.

Terminal window
$ fix switch --nixos
$ fix switch build --home-manager --flake .#me

This command is intentionally experimental. I am still thinking about what exactly fix switch should be—its scope, its interface, and its relationship to the existing rebuild tools—and it will likely change in the future. Treat the current command as a useful prototype, not a stable automation interface.

Start the REPL with fix repl. From there:

  • :vm opens the full-screen VM explorer;
  • :d EXPR evaluates an expression in the debugger; and
  • :help lists the available REPL commands.

The debugger can also be enabled directly on an evaluation:

Terminal window
$ fix eval --debugger ./expression.nix

Inside the debugger, break FILE:LINE adds a source breakpoint. A breakpoint may remain pending until that source is compiled; it resolves automatically when the matching code appears. breakpoints lists breakpoints and delete N removes one. :gc runs a full collection while preserving the paused session’s values and refreshes the heap views.

Both tools also have bounded text output for non-interactive use. Start the REPL with fix repl --no-tui when an alternate-screen interface is undesirable.

The chart below compares wall-clock evaluation time across synthetic stress tests, real NixOS and Home Manager configurations, and JSON-producing workloads. Each cell is relative to the fastest evaluator for that workload; 1.00× is fastest. The harness defaults to five recorded runs.

![fix evaluator benchmark]!(demo/benchmark.png)

Full benchmark tables
CommandMean [ms]Min [ms]Max [ms]Relative
fix-1core64.2 ± 1.562.465.71.00 ± 0.07
fix-autocore72.3 ± 3.367.975.81.13 ± 0.09
nix64.1 ± 4.259.770.51.00
lix77.7 ± 2.375.180.81.21 ± 0.09
detsys-1core83.8 ± 10.675.6101.51.31 ± 0.19
detsys-autocore75.9 ± 0.875.177.21.18 ± 0.08
CommandMean [ms]Min [ms]Max [ms]Relative
fix-1core222.2 ± 5.8216.3231.11.00
fix-autocore224.2 ± 2.9220.3227.61.01 ± 0.03
nix330.6 ± 12.1323.9352.11.49 ± 0.07
lix307.6 ± 1.4305.3308.61.38 ± 0.04
detsys-1core507.7 ± 2.8505.1512.32.29 ± 0.06
detsys-autocore502.9 ± 15.0476.3511.62.26 ± 0.09
CommandMean [ms]Min [ms]Max [ms]Relative
fix-1core18.6 ± 0.717.519.51.00
fix-autocore22.9 ± 0.422.423.31.23 ± 0.05
nix24.9 ± 2.021.426.61.34 ± 0.12
lix22.7 ± 0.721.623.71.22 ± 0.06
detsys-1core31.0 ± 1.229.132.41.67 ± 0.09
detsys-autocore31.4 ± 3.725.134.51.69 ± 0.21
CommandMean [ms]Min [ms]Max [ms]Relative
fix-1core115.1 ± 3.4111.6120.71.00
fix-autocore128.5 ± 8.8121.0143.81.12 ± 0.08
nix151.6 ± 2.4149.1154.71.32 ± 0.04
lix135.2 ± 2.7132.1139.31.18 ± 0.04
detsys-1core216.3 ± 1.0215.4217.71.88 ± 0.06
detsys-autocore218.5 ± 2.8215.9223.31.90 ± 0.06
CommandMean [s]Min [s]Max [s]Relative
fix-1core1.127 ± 0.0101.1171.1431.00
fix-autocore1.185 ± 0.0161.1701.2051.05 ± 0.02
nix1.329 ± 0.0301.2951.3771.18 ± 0.03
lix1.149 ± 0.0081.1401.1611.02 ± 0.01
detsys-1core2.012 ± 0.0391.9492.0551.79 ± 0.04
detsys-autocore2.036 ± 0.0142.0142.0491.81 ± 0.02
CommandMean [ms]Min [ms]Max [ms]Relative
fix-1core44.7 ± 2.441.948.11.03 ± 0.06
fix-autocore79.2 ± 3.975.685.71.82 ± 0.11
nix50.9 ± 2.248.353.41.17 ± 0.06
lix43.5 ± 1.441.945.51.00
detsys-1core63.1 ± 2.060.064.91.45 ± 0.07
detsys-autocore64.1 ± 2.461.566.91.47 ± 0.07
CommandMean [ms]Min [ms]Max [ms]Relative
fix-1core88.8 ± 1.187.790.51.00
fix-autocore121.9 ± 4.6117.4129.11.37 ± 0.05
nix92.3 ± 1.491.094.31.04 ± 0.02
lix95.8 ± 2.493.798.51.08 ± 0.03
detsys-1core130.2 ± 34.1113.6191.11.47 ± 0.38
detsys-autocore116.0 ± 1.5114.3118.11.31 ± 0.02
CommandMean [s]Min [s]Max [s]Relative
fix-1core1.304 ± 0.0021.3021.3081.60 ± 0.04
fix-autocore0.815 ± 0.0190.7890.8351.00
nix1.372 ± 0.0091.3641.3861.68 ± 0.04
lix1.309 ± 0.0141.2951.3301.61 ± 0.04
detsys-1core1.673 ± 0.0351.6421.7282.05 ± 0.06
detsys-autocore1.654 ± 0.0291.6231.6862.03 ± 0.06
CommandMean [s]Min [s]Max [s]Relative
fix-1core2.727 ± 0.0202.7152.7602.88 ± 0.05
fix-autocore0.947 ± 0.0160.9230.9651.00
nix2.702 ± 0.0292.6602.7272.85 ± 0.06
lix2.547 ± 0.0302.5142.5852.69 ± 0.05
detsys-1core3.331 ± 0.0403.2953.3943.52 ± 0.07
detsys-autocore3.335 ± 0.0243.3163.3773.52 ± 0.06
CommandMean [s]Min [s]Max [s]Relative
fix-1core2.978 ± 0.0232.9453.0052.91 ± 0.04
fix-autocore1.022 ± 0.0111.0041.0331.00
nix3.015 ± 0.0302.9783.0482.95 ± 0.04
lix2.898 ± 0.0342.8712.9462.84 ± 0.04
detsys-1core3.720 ± 0.0233.6923.7543.64 ± 0.04
detsys-autocore3.681 ± 0.0223.6623.7083.60 ± 0.04
CommandMean [s]Min [s]Max [s]Relative
fix-1core2.144 ± 0.0302.1062.1833.57 ± 0.10
fix-autocore0.600 ± 0.0150.5790.6171.00
nix2.167 ± 0.0422.1322.2313.61 ± 0.11
lix2.080 ± 0.0512.0212.1513.47 ± 0.12
detsys-1core2.701 ± 0.0052.6922.7064.50 ± 0.11
detsys-autocore2.738 ± 0.0382.7012.7814.56 ± 0.13
CommandMean [ms]Min [ms]Max [ms]Relative
fix-1core21.3 ± 0.221.121.61.00
fix-autocore30.4 ± 0.829.231.31.43 ± 0.04
nix38.2 ± 0.737.338.91.79 ± 0.04
lix39.5 ± 0.938.140.21.85 ± 0.04
detsys-1core48.3 ± 3.545.654.22.27 ± 0.17
detsys-autocore49.4 ± 0.848.250.32.32 ± 0.04
CommandMean [ms]Min [ms]Max [ms]Relative
fix-1core608.8 ± 12.0601.8630.11.44 ± 0.03
fix-autocore424.2 ± 3.2420.1427.71.00
nix1077.9 ± 21.21055.21106.72.54 ± 0.05
lix1234.5 ± 31.11203.31286.62.91 ± 0.08
detsys-1core1136.0 ± 22.61110.71171.32.68 ± 0.06
detsys-autocore834.4 ± 14.9822.5859.91.97 ± 0.04
CommandMean [ms]Min [ms]Max [ms]Relative
fix-1core445.2 ± 10.9432.9462.43.58 ± 0.10
fix-autocore165.2 ± 1.6163.2167.51.33 ± 0.02
nix654.9 ± 16.1643.0680.85.26 ± 0.15
lix617.9 ± 15.6605.6642.44.97 ± 0.14
detsys-1core998.8 ± 40.2957.41041.68.03 ± 0.34
detsys-autocore124.4 ± 1.6122.4126.51.00
CommandMean [ms]Min [ms]Max [ms]Relative
fix-1core334.6 ± 2.8330.4337.33.82 ± 0.12
fix-autocore87.7 ± 2.785.492.01.00
nix448.0 ± 10.8436.4461.35.11 ± 0.20
lix395.4 ± 6.0384.7398.54.51 ± 0.15
detsys-1core653.8 ± 5.2647.0659.07.46 ± 0.23
detsys-autocore661.2 ± 16.2641.3686.27.54 ± 0.29

These results are point-in-time measurements from pinned inputs, not a claim that fix wins every workload. The timing harness uses Hyperfine, with separate warmup and measured runs and optional cache reclamation between runs. Correctness is checked separately by zig build test-bench-fixtures; it is not part of the timing script. See [the benchmark documentation]!(bench/README.md) for the workloads and reproduction commands.

fix runs nixboy, a Game Boy emulator written in Nix.

Pokemon Red (every third frame, playback 2x speed)

https://github.com/user-attachments/assets/0353b17c-f196-4dda-ba19-1329b651d9ae

Bad Apple!! (every frame, playback 5x speed)

https://github.com/user-attachments/assets/3e3e44af-03dc-4c4d-89aa-e64eddf847cc

The repository exports modules for NixOS, nix-darwin, and Home Manager:

let
fixSource = /path/to/a/pinned/fix;
fixProject = import fixSource {};
in {
imports = [
fixProject.homeManagerModules.fix
];
programs.fix.enable = true;
}

Use nixosModules.fix or darwinModules.fix in the corresponding module system. Enabling programs.direnv enables the bundled integration by default and installs fix; it can be controlled explicitly with programs.direnv.fix.enable. Use programs.fix.enable when you want the CLI without direnv.

fix is alpha-quality software under active development. Compatibility is a concrete target and is continuously tested, but this is not yet a promise that every Nix program or workflow is supported. Development currently takes place on x86_64 Linux; release builds also cover aarch64 Linux and aarch64 macOS. Keep Nix installed: it is a runtime requirement because fix uses the Nix daemon for store operations and builds.

If fix produces a different value, derivation, or store path from Nix for supported input, that is a bug. Releases are documented in [the changelog]!(CHANGELOG.md).

Enter the pinned development environment and build an optimized binary with:

Terminal window
$ nix-shell --run 'zig build --release=fast'

The result is zig-out/bin/fix. Useful checks include:

Terminal window
$ zig build test
$ zig build check
$ zig build test-lang
$ zig build test-bench-fixtures
$ zig build test-nixpkgs

Start with [the developer documentation]!(docs/README.md) for the architecture, runtime invariants, testing strategy, and performance model.