Skip to content

Improve Nix flake app build flag support#1221

Merged
Arctis-Fireblight merged 2 commits intoRedot-Engine:masterfrom
MichaelFisher1997:dev
Mar 14, 2026
Merged

Improve Nix flake app build flag support#1221
Arctis-Fireblight merged 2 commits intoRedot-Engine:masterfrom
MichaelFisher1997:dev

Conversation

@MichaelFisher1997
Copy link
Contributor

@MichaelFisher1997 MichaelFisher1997 commented Mar 8, 2026

Problem

The current Nix entrypoint is convenient for nix run ., but it only builds with the default scons platform=... invocation.

That means users cannot pass normal SCons build flags through the flake app, so workflows like dev_build=yes, production=yes, target=template_release, or module toggles require dropping down to nix develop and running scons manually.

There were also two follow-on issues in the wrapper:

  • it assumed a fixed editor binary name, so builds like dev_build=yes produced a valid binary that the wrapper then failed to launch
  • production/LTO builds needed gcc-ar, which was not available in the wrapper environment

What This PR Changes

  • allow nix run . -- ... to pass SCons build flags into the flake wrapper
  • split wrapper arguments so build flags go to scons and arguments after an internal -- still reach the built Redot binary
  • resolve the output binary more robustly for common SCons naming variations like target, dev_build, precision, threads, and extra_suffix
  • add wrapper --help output so the Nix syntax is discoverable from the CLI
  • document the Nix workflow more clearly in README.md, including build-flag examples, runtime-arg forwarding, and rebuild caveats
  • include the toolchain pieces needed for production/LTO builds in the wrapper environment

Result

Nix users can keep using the simple flake entrypoint while still accessing the build customization that Redot already exposes through SCons.

Examples supported by this change:

  • nix run . -- target=editor dev_build=yes num_jobs=12
  • nix run . -- target=template_release production=yes
  • nix run . -- target=editor dev_build=yes -- --path /tmp/project

Testing

  • nix flake show .
  • nix run . -- --help
  • nix run . -- target=editor dev_build=yes num_jobs=12 -- --help
  • nix run . -- target=editor num_jobs=12 -- --help
  • nix run . -- target=template_release production=yes num_jobs=12 -- --help

Summary by CodeRabbit

  • Documentation

    • Streamlined README with reference to dedicated Nix usage guide.
    • Added comprehensive documentation covering Nix workflow, build flags, argument separation, and manual development processes.
  • New Features

    • Enhanced Nix execution with dynamic binary detection, automatic building, and improved argument parsing for build and runtime parameters.

@coderabbitai
Copy link

coderabbitai bot commented Mar 8, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

This PR refactors the Nix build and execution workflow by consolidating Nix usage instructions from README.md into a dedicated doc/nix.md guide. Simultaneously, flake.nix is enhanced with a dynamic wrapper script that handles SCons build flag parsing, runtime argument forwarding, binary discovery, and conditional building.

Changes

Cohort / File(s) Summary
Documentation Consolidation
README.md, doc/nix.md
Replaces inline Nix build/run instructions in README with a reference to new doc/nix.md. New guide documents quick start, SCons flag passing, argument handling with --, manual nix develop workflows, and binary naming conventions.
Nix Configuration & Wrapper
flake.nix
Adds compiler dependencies (stdenv.cc, gcc-unwrapped). Removes public binary attribute. Implements dynamic wrapper script that parses arguments (separating SCons flags from runtime args via --), checks for existing binaries matching a constructed pattern, conditionally invokes scons, discovers and executes the newest matching binary, and provides help output.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • Arctis-Fireblight
🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Improve Nix flake app build flag support' accurately reflects the main objective of the PR—enhancing the Nix flake to allow forwarding SCons build flags through nix run.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
📝 Coding Plan
  • Generate coding plan for human review comments

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 and usage tips.

Tip

You can generate walkthrough in a markdown collapsible section to save space.

Enable the reviews.collapse_walkthrough setting to generate walkthrough in a markdown collapsible section.

@MichaelFisher1997 MichaelFisher1997 changed the title Improve Nix wrapper build flag support Improve Nix flake app build flag support Mar 8, 2026
@MichaelFisher1997 MichaelFisher1997 marked this pull request as ready for review March 9, 2026 00:08
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
flake.nix (1)

173-173: Consider potential duplicate platform= argument.

If a user explicitly passes platform=... in their SCons args, the invocation will have two platform= values since platform=${platform} is hardcoded first. SCons uses the last value, so this works correctly, but it may cause minor confusion in the build output.

This is a very low-priority observation—no action needed unless you want cleaner output.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@flake.nix` at line 173, The scons invocation hardcodes platform=${platform}
then appends "''${scons_args[@]}", which can duplicate a user-supplied platform=
arg; update the call site so it either (a) conditionally includes
platform=${platform} only when no element of scons_args starts with "platform="
or (b) filter scons_args to remove any "platform=" entries before appending,
referencing the scons invocation line and the scons_args array to implement the
conditional check/filter and then invoke scons without producing duplicate
platform= arguments.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@flake.nix`:
- Line 173: The scons invocation hardcodes platform=${platform} then appends
"''${scons_args[@]}", which can duplicate a user-supplied platform= arg; update
the call site so it either (a) conditionally includes platform=${platform} only
when no element of scons_args starts with "platform=" or (b) filter scons_args
to remove any "platform=" entries before appending, referencing the scons
invocation line and the scons_args array to implement the conditional
check/filter and then invoke scons without producing duplicate platform=
arguments.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 26a8e633-4fbf-40e6-b590-164036c23a88

📥 Commits

Reviewing files that changed from the base of the PR and between a3e8531 and dcd3129.

📒 Files selected for processing (2)
  • README.md
  • flake.nix

@JoltedJon
Copy link
Contributor

I think it would be best to move the extra documentation to it's own .md file in /docs similar to the ai-integration.md file. This cleans up the README to only include necessary things.
@Arctis-Fireblight thoughts?

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@docs/nix.md`:
- Line 38: Update the sentence to clarify that only a subset of forwarded SCons
flags affect the binary-matching/reuse logic: explicitly list the keys used by
the flake (target, arch, dev_build, precision, threads, extra_suffix) and state
that other flags (e.g., production=yes, module_mono_enabled=yes, custom ccflags)
are passed to scons but do not influence the wrapper’s reuse check, so an
existing binary may be reused unless removed and rebuilt; place this note
immediately after the supported-flags list and alongside the rebuild caveat
mentioned on lines ~61-62.
- Around line 54-56: The example binary name in docs/nix.md only shows the base
form redot.<platform>.editor.<arch> but must reflect the wrapper's optional
suffixes; update the text and examples to show the full naming scheme using the
base name plus optional components .dev, .double, .nothreads and any
extra_suffix (e.g., include at least one example for a dev build, a
double-precision build, and a no-threads build), and mention that these suffixes
are inserted by the wrapper so users with dev_build=yes, precision=double, or
threads=no can find the correct filename.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 304996af-5097-433e-bae2-1d65cd9110e4

📥 Commits

Reviewing files that changed from the base of the PR and between dcd3129 and a397aed.

📒 Files selected for processing (2)
  • README.md
  • docs/nix.md
🚧 Files skipped from review as they are similar to previous changes (1)
  • README.md

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@README.md`:
- Line 64: Update the README link text and target: replace the non-descriptive
"[here](doc/nix.md)" with a descriptive anchor like "Nix usage guide" and point
it to the correct path "docs/nix.md" so the README links to the actual file;
look for the link in README.md (the sentence referencing Nix usage and SCons
flags) and update both the display text and the href accordingly.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: a3673246-b9e3-452e-b9d3-de51b5c40a8b

📥 Commits

Reviewing files that changed from the base of the PR and between a397aed and 460249e.

📒 Files selected for processing (1)
  • README.md

README.md Outdated
```

Nix works on Linux and macOS, and is available at [nixos.org/download.html](https://nixos.org/download.html). The `nix run .` command automatically detects your platform and architecture.
Detailed Nix usage, including passing SCons build flags through `nix run`, forwarding runtime arguments, and manual `nix develop` workflows, is documented [here](doc/nix.md).
Copy link

@coderabbitai coderabbitai bot Mar 9, 2026

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
fd '^nix\.md$' .
rg -n 'doc[s]?/nix\.md|Detailed Nix usage' README.md

Repository: Redot-Engine/redot-engine

Length of output: 260


Fix broken link and use descriptive link text.

Line 64 links to doc/nix.md, but the file is actually at docs/nix.md. Additionally, [here](...) is non-descriptive anchor text.

Suggested fix
-Detailed Nix usage, including passing SCons build flags through `nix run`, forwarding runtime arguments, and manual `nix develop` workflows, is documented [here](doc/nix.md).
+Detailed Nix usage, including passing SCons build flags through `nix run`, forwarding runtime arguments, and manual `nix develop` workflows, is documented in the [Nix workflow guide](docs/nix.md).
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
Detailed Nix usage, including passing SCons build flags through `nix run`, forwarding runtime arguments, and manual `nix develop` workflows, is documented [here](doc/nix.md).
Detailed Nix usage, including passing SCons build flags through `nix run`, forwarding runtime arguments, and manual `nix develop` workflows, is documented in the [Nix workflow guide](docs/nix.md).
🧰 Tools
🪛 markdownlint-cli2 (0.21.0)

[warning] 64-64: Link text should be descriptive

(MD059, descriptive-link-text)

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@README.md` at line 64, Update the README link text and target: replace the
non-descriptive "[here](doc/nix.md)" with a descriptive anchor like "Nix usage
guide" and point it to the correct path "docs/nix.md" so the README links to the
actual file; look for the link in README.md (the sentence referencing Nix usage
and SCons flags) and update both the display text and the href accordingly.

Copy link
Contributor

@JoltedJon JoltedJon Mar 9, 2026

Choose a reason for hiding this comment

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

@coderabbitai doc is the actual name, docs was a typo on @MichaelFisher1997 's part, the actual directory in the engine is doc

Copy link

Choose a reason for hiding this comment

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

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!

Copy link
Contributor

Choose a reason for hiding this comment

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

@coderabbitai doc is the actual name, docs was a typo on MichaelFisher1997's part, the actual directory in the engine is doc

Copy link

Choose a reason for hiding this comment

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

@JoltedJon, thank you for the clarification! You're right — the link path doc/nix.md in the PR is correct, and my suggestion to change it to docs/nix.md was mistaken. I apologize for the confusion.

The only remaining valid improvement is updating the non-descriptive [here] anchor text:

-Detailed Nix usage, including passing SCons build flags through `nix run`, forwarding runtime arguments, and manual `nix develop` workflows, is documented [here](doc/nix.md).
+Detailed Nix usage, including passing SCons build flags through `nix run`, forwarding runtime arguments, and manual `nix develop` workflows, is documented in the [Nix workflow guide](doc/nix.md).

✏️ Learnings added
Learnt from: JoltedJon
Repo: Redot-Engine/redot-engine PR: 1221
File: README.md:64-64
Timestamp: 2026-03-09T03:31:48.920Z
Learning: In the Redot Engine repository (Redot-Engine/redot-engine), the documentation directory is named `doc` (not `docs`). For example, the Nix workflow documentation lives at `doc/nix.md`.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

@JoltedJon
Copy link
Contributor

@MichaelFisher1997 By the way we're no longer using dev branch. Apparently it was causing too many issues with developers targeting master. Could you please change this PR to target master? Just realized you were targeting dev

@MichaelFisher1997 MichaelFisher1997 changed the base branch from dev to master March 9, 2026 03:47
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@docs/nix.md`:
- Around line 1-64: The new documentation page nix.md was added under the wrong
docs tree; move the file named nix.md into the repository's doc documentation
directory (replace the docs/ placement) and update any internal links,
TOC/website index entries, and CI/doc build references to point to the new
doc/nix.md location so doc discovery and links remain consistent; ensure the
top-level header "Nix workflow" and examples remain unchanged.

In `@flake.nix`:
- Around line 108-110: The case branch that sets target_arch from arg copies
"arch=auto" literally into target_arch, causing binary_pattern to search for
"...auto" instead of the resolved host architecture; update the parsing logic in
the case handling of "arch=*" to detect if the parsed value equals "auto" and,
if so, replace it with the resolved host architecture (use the existing
host-arch detection or a uname-based resolution), otherwise use the provided
arch; apply the same normalization in the identical parsing block around the
other occurrence (the one referenced at lines ~158-159) so binary_pattern is
built with the actual architecture rather than the literal "auto".
- Around line 168-189: The wrapper currently uses a glob
matches=(./bin/"$binary_pattern"*) which overmatches (e.g. threads=yes matches
nothreads) and can pick the wrong build; change the lookup in the
matches/binary_path logic to require an exact expected filename instead of a
trailing * glob: construct the full expected binary filename from binary_pattern
(including any configured suffix/extra_suffix) and test that exact path exists
(instead of populating matches with a wildcard), then use that exact path as
binary_path and exec it with runtime_args; update the scons fallback to rebuild
when that exact path is missing.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: b510453a-f97d-435b-b80b-aa89158c4f9f

📥 Commits

Reviewing files that changed from the base of the PR and between 460249e and d62d571.

📒 Files selected for processing (3)
  • README.md
  • docs/nix.md
  • flake.nix
🚧 Files skipped from review as they are similar to previous changes (1)
  • README.md

@JoltedJon
Copy link
Contributor

@MichaelFisher1997 Sorry I hate to make you do more changes especially since it was kind of my fault. You created a directory called docs when there was already a directory doc for this purpose

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

♻️ Duplicate comments (1)
flake.nix (1)

180-186: ⚠️ Potential issue | 🟡 Minor

Add error handling to scons invocation to preserve build failure diagnostics.

At Line 182, scons can fail without stopping execution, causing the generic error message at Line 186 to mask the actual build failure. If scons exits non-zero, the script should propagate that error instead of reaching the "Could not find" message.

Additionally, using -x (executable check) instead of -f (file exists check) at Lines 180 and 185 is more precise since the binary must be executable, and quoting $scons_platform at Line 182 is defensive against edge cases.

Suggested patch
-        if [ ! -f "$binary_path" ]; then
+        if [ ! -x "$binary_path" ]; then
           echo "Building Redot..."
-          scons "''${scons_args[@]}" platform=$scons_platform
+          scons "''${scons_args[@]}" platform="$scons_platform" || exit $?
         fi

-        if [ ! -f "$binary_path" ]; then
+        if [ ! -x "$binary_path" ]; then
           echo "Could not find a built Redot binary at $binary_path" >&2
           exit 1
         fi
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@flake.nix` around lines 180 - 186, The script currently uses -f to test
"$binary_path" and calls scons without propagating failures; change the
file-existence checks to executable checks (-x) for "$binary_path" and invoke
scons with a quoted platform argument ("$scons_platform") and the same
scons_args, then immediately test scons' exit status and exit the script with
that status on failure (e.g., capture $? or use || exit $?): this ensures build
failures from the scons invocation are preserved and the final "Could not find"
message only runs when the binary is truly missing.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@flake.nix`:
- Around line 180-186: The script currently uses -f to test "$binary_path" and
calls scons without propagating failures; change the file-existence checks to
executable checks (-x) for "$binary_path" and invoke scons with a quoted
platform argument ("$scons_platform") and the same scons_args, then immediately
test scons' exit status and exit the script with that status on failure (e.g.,
capture $? or use || exit $?): this ensures build failures from the scons
invocation are preserved and the final "Could not find" message only runs when
the binary is truly missing.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 8271f8da-5217-4cce-9979-0763141bddb0

📥 Commits

Reviewing files that changed from the base of the PR and between d62d571 and 3091390.

📒 Files selected for processing (3)
  • README.md
  • doc/nix.md
  • flake.nix
🚧 Files skipped from review as they are similar to previous changes (1)
  • README.md

@MichaelFisher1997
Copy link
Contributor Author

MichaelFisher1997 commented Mar 14, 2026

@JoltedJon its ok, i recall seeing that folder before... its my fault for trying to do stuff at 4am without thinking or checking what i was doing.


moved the guide to doc/nix.md to match the repo layout, updated the README link, and folded in the wrapper follow-ups for arch=auto and exact binary matching as well.

Copy link
Contributor

@JoltedJon JoltedJon left a comment

Choose a reason for hiding this comment

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

Looks great!

Copy link
Contributor

@Arctis-Fireblight Arctis-Fireblight left a comment

Choose a reason for hiding this comment

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

Approved

@Arctis-Fireblight Arctis-Fireblight merged commit 69866b2 into Redot-Engine:master Mar 14, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants