Skip to content

build(nix): publish LLVM/MLIR 23 via cachix instead of per-user source builds - #45

Merged
t3tra-dev merged 9 commits into
t3tra-dev:mainfrom
Comamoca:feat/nix-flake-cachix
Oct 17, 2026
Merged

t3tra-dev merged 9 commits into
t3tra-dev:mainfrom
Comamoca:feat/nix-flake-cachix

Conversation

@Comamoca

@Comamoca Comamoca commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds Nix support to lython.

https://nixos.org/

Nix is a purely functional package manager characterized by its ability to perform idempotent builds.
This PR adds flake.nix, a file used to build lython using Nix, and the lock file flake.lock.

Motivation

lython is built with C++ and depends on LLVM.
These two have a relatively high barrier to environment setup, and it also takes time to set up a development environment to run it.
Supporting Nix lowers the difficulty of environment setup, making it easier for users interested in lython to run it easily and participate in its development.

Changes

Added flake.nix, which defines the build and development environment for lython.
Additionally, a sub-flake structure is used to prevent inputs for development environment use from being downloaded when running nix run.

Special Notes

LLVM23 has not yet been released on nixpkgs, and as of now (2026/10/9), no build cache exists on hydra.
Therefore, running this flake will start building lython locally, including a build of LLVM23.

Since this is an extremely heavy process, I have published the cache generated when I built lython using Nix on cachix.

Since it is not a build from nixpkgs, use it at your own risk, but if you want to reduce the build load even a little or build faster, please feel free to use it together.

https://app.cachix.org/cache/comamoca-lython

…e builds

nixpkgs has no llvmPackages_23, so this flake builds two LLVM trees from
source (~1h, llvm23 1.2GiB + mlir23 774MiB). Every nix run user would
pay that, so:

- flake.nix nixConfig: add comamoca-lython.cachix.org as an extra
  substituter with its trusted public key, so first-time users get a
  one-time accept prompt and pull the prebuilt closure.
- .github/workflows/nix-cache.yml: rebuild and push llvm23/mlir23/
  lython on pushes touching the flake or compiler sources
  (CACHIX_AUTH_TOKEN secret), keeping the cache fresh.
- .gitignore: result*, .direnv/.
@coderabbitai

coderabbitai Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 87b9a679-04ee-46c0-b2fa-cdb0c68eb69e

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Flake inputs are fetched lazily, but flake-parts' mkFlake forces its
`imports`, so evaluating packages.default dragged flake-parts,
nixpkgs-lib, systems, treefmt-nix and git-hooks-nix into every end-user
fetch. Hand-rolled outputs keep the tooling inputs referenced only from
checks/formatter, which `nix run`/`nix build` never touch; the
nixpkgs follows collapse the lock from three nixpkgs revisions to one
(11 nodes -> 6).

`nix run` also could not execute at all: it looked for bin/lython (the
pname) while CMake installs bin/lyc, so meta.mainProgram = "lyc" now
points it at the real binary.

Verified with forged-narHash probes: packages.default succeeds with all
four dev inputs poisoned, while checks.* still fail (they do fetch
them). nix flake check, nix develop -c true and
`nix run . -- parse examples/hello.py` all pass; nix fmt fixed the
trailing-newline diff that kept treefmt/pre-commit checks red.
nixpkgs-unstable now ships LLVM/MLIR 23 (previously only 21), so the
custom nix/llvm23.nix and nix/mlir23.nix (which built the upstream
release tarball to get a shared MLIR CMake target) are redundant.

- flake.nix: drop the llvm23Overlay and the llvm23/mlir23 package
  outputs; pull pkgs.llvmPackages_23.{llvm,mlir,tblgen} directly.
- build-lython.nix: take llvm / mlir / tblgen as arguments; pass
  LLVM_TABLEGEN_EXE and MLIR_TABLEGEN_EXE because nixpkgs's mlir
  derivation does not install mlir-tblgen into its `out`.
- delete nix/llvm23.nix and nix/mlir23.nix (no longer referenced).
- nix-cache.yml: drop .#llvm23 and .#mlir23 from the Cachix push set;
  nixpkgs already provides them as binary cache hits.
cmake's find_program for mlir-tblgen (Lython's CMakeLists.txt:283)
was failing inside `nix develop` because the nixpkgs mlir derivation
does not install mlir-tblgen into its `out`. The build-lython.nix
side already worked around this by passing the tablegen path
explicitly; the devShell side was missing the same fix.

Lython's devShell workflow (`cmake -B build && cmake --build build`
inside `nix develop`) now works again, which is required to build the
test suite (`LYTHON_BUILD_TESTS=ON`).
`nix develop` users building lython with `cmake -B build-test` (or
any other suffixed build dir) would otherwise accidentally stage the
hundreds of generated files the next time they ran `git add -A`.

The existing `build/` entry only matched an exact name; `build-*/`
catches `build-test`, `build-debug`, `build-asan`, etc.
LLVM/MLIR is now sourced from nixpkgs's llvmPackages_23, which is already
on the public binary cache. The Cachix push workflow no longer needs to
hold a self-built LLVM/MLIR (those derivations are gone), and lython's
own source build is cheap enough that a private cache adds little
value.

- .github/workflows/nix-cache.yml: deleted (Cachix push no longer needed)
- flake.nix: drop git-hooks-nix input and the pre-commit check
  (the URL is github:cachix/git-hooks.nix, the only remaining cachix
  reference; the pre-commit hooks depended on it)
- flake.lock: regenerated without git-hooks-nix and its transitive
  inputs (flake-compat, gitignore)
@Comamoca
Comamoca force-pushed the feat/nix-flake-cachix branch from 494b310 to 50f6ee3 Compare October 12, 2026 06:52
t3tra-dev added a commit that referenced this pull request Oct 17, 2026
`nix run`, `nix develop` and `nix flake check` for aarch64-darwin,
aarch64-linux and x86_64-linux, against nixpkgs' llvmPackages_23. Hydra
builds it and cache.nixos.org serves it for all three, so no LLVM is built
on a user's machine and no other binary cache is trusted. lyc links it as
shared libraries out of the store, as it links Homebrew's or apt's; nothing
is bundled. Measured: the package builds in about 2 minutes on either
platform, and the ctest suite (bench aside) passes in the sandbox -- 839 of
839 on aarch64-darwin and aarch64-linux.

Taken in part from PR #45 (Comamoca): the flake layout, the systems, the
.envrc and .gitignore entries, `mainProgram`, tests off in the package. Not
taken: building LLVM and MLIR from source with a personal Cachix in
nixConfig -- the lock predated LLVM 23 in nixpkgs, and that is now cached
upstream -- nor treefmt/git-hooks inputs, nor AGENTS.md.

Differences from that PR, and why:
- llvmPackages_23.stdenv, so Linux builds with the clang that matches the
  LLVM, as every other build of this tree does.
- lyc is wrapped with that clang and lld on PATH: AOT and WASI links run
  them, and a wrapped clang is what finds this system's libc.
- googletest comes from nixpkgs' source through
  FETCHCONTENT_SOURCE_DIR_GOOGLETEST, so the suite runs in the sandbox as
  `checks`.
- x86_64-darwin is left out: nixpkgs no longer builds it.

Building against it found four defects that Homebrew and apt hide, each
fixed in its own commit before this one (GCC's pattern names, ld64's local
personality, aarch64's type-table width, the macOS version), and
.github/workflows/nix.yml keeps all three systems building and tested.
@t3tra-dev
t3tra-dev merged commit d464118 into t3tra-dev:main Oct 17, 2026
1 check passed
@t3tra-dev

Copy link
Copy Markdown
Owner

Thank you for the updates.

  • With nix flake check, we pass googletest from the nixpkgs source and run ctest inside the sandbox.
  • Since nixpkgs has dropped builds for x86_64-darwin, we have removed it from the supported systems.
    Therefore, nix/build-lython.nix was removed as its role overlaps with nix/package.nix. This PR also includes build/ and build-*/ in .gitignore (the exact same .envrc was already present).
    By building against LLVM from nixpkgs, four bugs on the Lython side that did not appear with Homebrew or apt were uncovered and fixed:
  • Because the Linux libMLIR is built with GCC, the debug names for MLIR patterns differed from Clang, causing a fold to take effect that should have been disabled.
  • The ld64 in nixpkgs could not resolve a personality set to internal linkage.
  • The personality could not read the 8-byte-width type table for aarch64 ELF.
  • The macOS versions for the object and the link were mismatched.

This is all thanks to you bringing in the Nix pipeline. Thank you very much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants