Skip to content

feat: add flake.nix for Linux development and Nix packaging#2561

Open
Flexksx wants to merge 5 commits into
moonrepo:masterfrom
Flexksx:feat/nix-flake
Open

feat: add flake.nix for Linux development and Nix packaging#2561
Flexksx wants to merge 5 commits into
moonrepo:masterfrom
Flexksx:feat/nix-flake

Conversation

@Flexksx

@Flexksx Flexksx commented Jun 9, 2026

Copy link
Copy Markdown

Summary

  • Adds flake.nix exposing packages.default (the moon + moonx binaries) and devShells.default for Linux development
  • Targets x86_64-linux and aarch64-linux
  • Pins the exact Rust 1.96.0 toolchain via rust-overlay reading rust-toolchain.toml
  • Adds .github/workflows/nix.yml as a guardrail — runs nix flake check and nix build on every relevant change

Motivation

The nixpkgs derivation for moon is currently at 1.41.8, while the project is at 2.3.2. A flake shipped with the repo lets Nix users pin directly to any commit or release without waiting for a nixpkgs update:

```bash
nix run github:moonrepo/moon -- --version

nix develop github:moonrepo/moon
```

Technical notes

OPENSSL_NO_VENDOR = 1reqwest enables native-tls-vendored for musl targets. On glibc Linux this forces pkg-config lookup of the system openssl instead of compiling it from source.

protobuf in nativeBuildInputscrates/daemon-proto/build.rs invokes protoc via tonic-prost-build at compile time. This dependency was added after the nixpkgs derivation was last updated.

cargoLock.lockFile — the project has no git-sourced Cargo dependencies, so no outputHashes are needed.

doCheck = false — tests download Node, Bun, Deno, etc. at runtime and cannot pass in the Nix sandbox.

Test plan

  • nix flake check --no-build passes locally
  • Derivation evaluates to a valid .drv on x86_64-linux
  • nix build .#default succeeds in CI (workflow added in this PR)

Adds a Nix flake that provides:
- packages.default: moon binary built with rustPlatform.buildRustPackage,
  pinned to the exact Rust 1.96.0 toolchain via rust-overlay.
- devShells.default: full dev environment (rustToolchain, protobuf,
  openssl, just, cargo-nextest) matching what CI uses.

Targets x86_64-linux and aarch64-linux. OPENSSL_NO_VENDOR=1 is set to
avoid compiling vendored OpenSSL — reqwest's native-tls-vendored feature
is present for musl targets only; on glibc Linux we rely on system openssl
via pkg-config.

protobuf is added to nativeBuildInputs because crates/daemon-proto/build.rs
invokes protoc via tonic-prost-build at compile time.

Also adds .github/workflows/nix.yml to keep the flake buildable on every
relevant change.

Closes: helps close the version gap between nixpkgs (1.35.5) and the
current release (2.3.2).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings June 9, 2026 08:23

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds Nix Flake-based packaging/dev shell and a GitHub Actions workflow to validate the flake and build the default package in CI.

Changes:

  • Introduce flake.nix to build the Rust CLI via buildRustPackage and provide a dev shell.
  • Add GitHub Actions workflow to run nix flake check and nix build on relevant changes.

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 4 comments.

File Description
flake.nix Defines flake inputs/outputs: Rust package build + devShell with Rust toolchain and native deps.
.github/workflows/nix.yml Adds CI job to check the flake and build the default package on PRs/pushes.

Comment thread flake.nix
Comment thread .github/workflows/nix.yml
Comment thread flake.nix Outdated
Comment thread flake.nix Outdated
Flexksx and others added 3 commits June 9, 2026 11:26
- Remove all comments
- Add installShellFiles + postInstall for bash/fish/zsh completions
- Add writableTmpDirAsHomeHook (moon accesses HOME during postInstall)
- Add RUSTFLAGS="-C strip=symbols" to match nixpkgs build flags
- Drop cargoBuildFlags; default-members in Cargo.toml already scopes to moon_cli
- Set doCheck = false; tests require internet and tool installation
- Mirror env block style from nixpkgs package.nix

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
magic-nix-cache-action requires FlakeHub registration. Use plain
actions/cache on /nix/store keyed on flake.lock + Cargo.lock instead.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@Flexksx Flexksx requested a review from Copilot June 9, 2026 11:08

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 3 changed files in this pull request and generated 3 comments.

Comment thread flake.nix
Comment on lines +43 to +46
env = {
RUSTFLAGS = "-C strip=symbols";
OPENSSL_NO_VENDOR = 1;
};
Comment thread flake.nix
Comment on lines +30 to +36
}).buildRustPackage {
pname = "moon";
version = "2.3.2";
src = ./.;

cargoLock.lockFile = ./Cargo.lock;

Comment thread .github/workflows/nix.yml
Comment on lines +36 to +40
- uses: actions/cache@v4
with:
path: /nix/store
key: nix-${{ runner.os }}-${{ hashFiles('flake.lock', 'Cargo.lock') }}
restore-keys: nix-${{ runner.os }}-
@milesj

milesj commented Jun 13, 2026

Copy link
Copy Markdown
Collaborator

@Flexksx I'm not familiar with nix, what does this do exactly? Allow people to use moon in their nix environment?

@Flexksx

Flexksx commented Jun 14, 2026

Copy link
Copy Markdown
Author

@milesj hi!

Allow people to use moon in their nix environment?

Yes, that's the biggest reason

Nix lets you package packages in a way that keeps them isolated, so I could have 2 different projects using moon and I could configure them to use slightly different versions of moon.

And each project would have its own isolated moon that is provided through the nix store.

I just recently stumbled across moon and I'm using it for a personal project and to be fair I'm amazed at how old is the current nixpkgs version for it, so I opened a PR as well NixOS/nixpkgs#529832

So for my project, I had to configure nix in a way that would build it from a specific, newer commit in the repo.
Which does not really have that much ergonomics 🤷

So adding a flake.nix would let as well other people easier interact with it, install it on their machines.

Also having a flake.nix lets other people with nix systems develop and contribute safely, since normally on NixOS you don't really install any packages globally, everything is managed with nix

@codspeed-hq

codspeed-hq Bot commented Jun 14, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

⚠️ Unknown Walltime execution environment detected

Using the Walltime instrument on standard Hosted Runners will lead to inconsistent data.

For the most accurate results, we recommend using CodSpeed Macro Runners: bare-metal machines fine-tuned for performance measurement consistency.

✅ 23 untouched benchmarks


Comparing Flexksx:feat/nix-flake (285c3e6) with master (b009ad3)

Open in CodSpeed

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants