Skip to content

feat: support nix flake and minimize rust binary size#127

Open
thinkgos wants to merge 1 commit into
Haleclipse:masterfrom
thinkgos:master
Open

feat: support nix flake and minimize rust binary size#127
thinkgos wants to merge 1 commit into
Haleclipse:masterfrom
thinkgos:master

Conversation

@thinkgos

@thinkgos thinkgos commented Jun 22, 2026

Copy link
Copy Markdown

I use it on Nix, but the upstream repository doesn't support it yet. I've added Nix flake support in this PR and using it in my home-manager configuration.

Additionally, minimize rust binary size.

Summary by Sourcery

Add Nix flake support and tune the Rust release build profile for smaller binaries.

New Features:

  • Provide a Nix flake definition to build and package the project across common Linux and macOS systems.
  • Add a Nix development shell configuration with an appropriate Rust toolchain and environment setup.

Enhancements:

  • Configure the Rust release profile to optimize for minimal binary size via more aggressive compilation settings.

@sourcery-ai

sourcery-ai Bot commented Jun 22, 2026

Copy link
Copy Markdown

Reviewer's Guide

Adds Nix flake-based packaging and development environment, and tightens Rust release build settings to minimize the compiled binary size.

File-Level Changes

Change Details Files
Configure Rust release profile for smaller, more optimized binaries.
  • Set release opt-level to 'z' to optimize for binary size over speed
  • Enable symbol stripping in release builds
  • Enable Link Time Optimization (LTO) for release builds
  • Reduce codegen-units to 1 for better cross-crate optimization at the cost of compile time
  • Switch panic strategy to 'abort' in release to remove unwinding support and shrink binaries
Cargo.toml
Introduce Nix flake for building, packaging, and developing the project on Nix-based systems.
  • Define flake inputs for nixpkgs, flake-parts, and oxalica rust-overlay
  • Declare supported systems matrix for Linux and Darwin on x86_64 and aarch64
  • Configure pkgs import to use rust-overlay via flake-parts perSystem
  • Create a Rust build environment using makeRustPlatform and rust-bin toolchains
  • Derive package name and version from Cargo.toml via fromTOML
  • Define a default package using buildRustPackage with Cargo.lock and non-auditable build
  • Set package metadata including homepage, description, license, and mainProgram for Nix consumers
  • Provide a devShell that reuses package dependencies and installs a full Rust toolchain with rust-analyzer, setting RUST_SRC_PATH and a shell greeting
flake.nix
flake.lock

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot 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.

Hey - I've found 1 issue, and left some high level feedback:

  • The [profile.release] changes (especially panic = "abort", lto = true, and codegen-units = 1) globally affect all release builds and can make debugging and integration with other tooling harder; consider moving these to an opt-in profile or gating them behind a Cargo feature to avoid surprising consumers.
  • In flake.nix, you define both rustToolchain and a separate rustPlatform using rust-bin.stable.latest.minimal; you could simplify by deriving rustPlatform from rustToolchain (or vice versa) to avoid duplicating version/toolchain configuration.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The `[profile.release]` changes (especially `panic = "abort"`, `lto = true`, and `codegen-units = 1`) globally affect all release builds and can make debugging and integration with other tooling harder; consider moving these to an opt-in profile or gating them behind a Cargo feature to avoid surprising consumers.
- In `flake.nix`, you define both `rustToolchain` and a separate `rustPlatform` using `rust-bin.stable.latest.minimal`; you could simplify by deriving `rustPlatform` from `rustToolchain` (or vice versa) to avoid duplicating version/toolchain configuration.

## Individual Comments

### Comment 1
<location path="flake.nix" line_range="62-53" />
<code_context>
+        {
+          # overlay
+          # https://flake.parts/overlays.html#consuming-an-overlay
+          _module.args.pkgs = import inputs.nixpkgs {
+            inherit system;
+            overlays = [ (import inputs.rust-overlay) ];
</code_context>
<issue_to_address>
**issue (bug_risk):** The `pkgs` used in `let` bindings likely doesn't include the `rust-overlay`, which can break `pkgs.rust-bin.*` and `makeRustPlatform`.

In this `perSystem` block, the `pkgs` in the `let` come from the un-overlaid argument and are only later replaced via `_module.args.pkgs = import inputs.nixpkgs { ... overlays = [ (import inputs.rust-overlay) ]; };`. As a result, `rustToolchain` / `rustPlatform` are likely defined from a `pkgs` without `rust-overlay`, so `pkgs.rust-bin.*` may be missing or inconsistent.

To avoid this ordering issue, import `nixpkgs` with the overlay into a dedicated binding and use it everywhere, for example:

```nix
let
  pkgsWithRust = import inputs.nixpkgs {
    inherit system;
    overlays = [ (import inputs.rust-overlay) ];
  };
  rustToolchain = pkgsWithRust.rust-bin.stable.latest.default.override { ... };
  rustPlatform = pkgsWithRust.makeRustPlatform { ... };
  cargoToml = fromTOML (builtins.readFile ./Cargo.toml);
in {
  _module.args.pkgs = pkgsWithRust;
  ...
}
```

This keeps the overlayed `pkgs` consistent and avoids subtle breakage if the `pkgs` argument changes.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread flake.nix
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.

1 participant