-
-
Notifications
You must be signed in to change notification settings - Fork 240
feat: enhance flake for build cache performance #2649
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
lamalex
wants to merge
1
commit into
moonrepo:master
Choose a base branch
from
lamalex:feat/improve-flake
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+215
−89
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -50,3 +50,8 @@ dockerManifest.json | |
| # AI / agents | ||
| .claude/settings.local.json | ||
| .claude/worktrees | ||
|
|
||
| # Nix | ||
| result | ||
| result-* | ||
| .direnv/ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,95 +1,174 @@ | ||
| { | ||
| description = "A monorepo build system and task runner for the web ecosystem"; | ||
|
|
||
| nixConfig = { | ||
| extra-substituters = [ "https://moonrepo.cachix.org" ]; | ||
| extra-trusted-public-keys = [ | ||
| "moonrepo.cachix.org-1:n4zm4mkV1Eoqck4mQvAhJM28EQwFLU7kW4dEbtAXbD8=" | ||
| ]; | ||
| }; | ||
|
|
||
| inputs = { | ||
| nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; | ||
| flake-utils.url = "github:numtide/flake-utils"; | ||
| crane.url = "github:ipetkov/crane"; | ||
| rust-overlay = { | ||
| url = "github:oxalica/rust-overlay"; | ||
| inputs.nixpkgs.follows = "nixpkgs"; | ||
| }; | ||
| }; | ||
|
|
||
| outputs = { self, nixpkgs, flake-utils, rust-overlay }: | ||
| flake-utils.lib.eachSystem [ "x86_64-linux" "aarch64-linux" ] (system: | ||
| let | ||
| pkgs = import nixpkgs { | ||
| inherit system; | ||
| overlays = [ rust-overlay.overlays.default ]; | ||
| }; | ||
|
|
||
| rustToolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml; | ||
|
|
||
| devRustToolchain = rustToolchain.override { | ||
| extensions = [ "rust-src" ]; | ||
| }; | ||
|
|
||
| moonVersion = (builtins.fromTOML | ||
| (builtins.readFile ./crates/cli/Cargo.toml)).package.version; | ||
|
|
||
| nativeDeps = with pkgs; [ pkg-config protobuf ]; | ||
| buildDeps = with pkgs; [ openssl ]; | ||
| in | ||
| { | ||
| packages.default = (pkgs.makeRustPlatform { | ||
| cargo = rustToolchain; | ||
| rustc = rustToolchain; | ||
| }).buildRustPackage { | ||
| pname = "moon"; | ||
| version = moonVersion; | ||
| src = ./.; | ||
|
|
||
| cargoLock.lockFile = ./Cargo.lock; | ||
|
|
||
| nativeBuildInputs = nativeDeps ++ (with pkgs; [ | ||
| installShellFiles | ||
| writableTmpDirAsHomeHook | ||
| ]); | ||
| buildInputs = buildDeps; | ||
|
|
||
| env = { | ||
| RUSTFLAGS = "-C strip=symbols"; | ||
| OPENSSL_NO_VENDOR = "1"; | ||
| outputs = | ||
| { | ||
| self, | ||
| nixpkgs, | ||
| flake-utils, | ||
| crane, | ||
| rust-overlay, | ||
| }: | ||
| flake-utils.lib.eachSystem | ||
| [ | ||
| "x86_64-linux" | ||
| "aarch64-linux" | ||
| "aarch64-darwin" | ||
| ] | ||
| ( | ||
| system: | ||
| let | ||
| pkgs = import nixpkgs { | ||
| inherit system; | ||
| overlays = [ rust-overlay.overlays.default ]; | ||
| }; | ||
|
|
||
| postInstall = pkgs.lib.optionalString | ||
| (pkgs.stdenv.hostPlatform.emulatorAvailable pkgs.buildPackages) | ||
| ( | ||
| let emulator = pkgs.stdenv.hostPlatform.emulator pkgs.buildPackages; | ||
| in '' | ||
| installShellCompletion --cmd moon \ | ||
| --bash <(${emulator} $out/bin/moon completions --shell bash) \ | ||
| --fish <(${emulator} $out/bin/moon completions --shell fish) \ | ||
| --zsh <(${emulator} $out/bin/moon completions --shell zsh) | ||
| '' | ||
| ); | ||
|
|
||
| doCheck = false; | ||
|
|
||
| meta = with pkgs.lib; { | ||
| description = "A monorepo build system and task runner for the web ecosystem"; | ||
| mainProgram = "moon"; | ||
| homepage = "https://github.com/moonrepo/moon"; | ||
| changelog = "https://github.com/moonrepo/moon/releases/tag/v${moonVersion}"; | ||
| license = licenses.mit; | ||
| maintainers = [ ]; | ||
| platforms = platforms.linux; | ||
| rustToolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml; | ||
|
|
||
| devRustToolchain = rustToolchain.override { | ||
| extensions = [ "rust-src" ]; | ||
| }; | ||
| }; | ||
|
|
||
| devShells.default = pkgs.mkShell { | ||
| nativeBuildInputs = nativeDeps ++ [ | ||
| devRustToolchain | ||
| pkgs.just | ||
| pkgs.cargo-nextest | ||
| craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchain; | ||
|
|
||
| moonVersion = (builtins.fromTOML (builtins.readFile ./crates/cli/Cargo.toml)).package.version; | ||
|
|
||
| nativeDeps = with pkgs; [ | ||
| pkg-config | ||
| protobuf | ||
| ]; | ||
| buildDeps = with pkgs; [ openssl ] ++ lib.optionals stdenv.hostPlatform.isDarwin [ libiconv ]; | ||
|
|
||
| cargoFiles = pkgs.lib.fileset.unions [ | ||
| ./Cargo.toml | ||
| ./Cargo.lock | ||
| ./.cargo/config.toml | ||
| (craneLib.fileset.commonCargoSources ./crates) | ||
| ]; | ||
| buildInputs = buildDeps; | ||
|
|
||
| env = { | ||
| OPENSSL_NO_VENDOR = "1"; | ||
| RUST_SRC_PATH = "${devRustToolchain}/lib/rustlib/src/rust/library"; | ||
| cargoSource = pkgs.lib.fileset.toSource { | ||
| root = ./.; | ||
| fileset = cargoFiles; | ||
| }; | ||
|
|
||
| source = pkgs.lib.fileset.toSource { | ||
| root = ./.; | ||
| fileset = pkgs.lib.fileset.unions [ | ||
| cargoFiles | ||
| ./crates/daemon-proto/proto | ||
| ./crates/config-loader/res | ||
| ./crates/docker/templates/Dockerfile.tera | ||
| ./crates/app/src/commands/graph/html.tera | ||
| ./crates/query/src/mql.pest | ||
| ]; | ||
| }; | ||
|
|
||
| commonArgs = { | ||
| pname = "moon"; | ||
| version = moonVersion; | ||
| src = source; | ||
|
|
||
| cargoExtraArgs = "--locked --package moon_cli --bins"; | ||
| strictDeps = true; | ||
| doCheck = false; | ||
|
|
||
| nativeBuildInputs = nativeDeps; | ||
| buildInputs = buildDeps; | ||
|
|
||
| env = { | ||
| RUSTFLAGS = "-C strip=symbols"; | ||
| OPENSSL_NO_VENDOR = "1"; | ||
| }; | ||
| }; | ||
|
|
||
| cargoArtifacts = craneLib.buildDepsOnly ( | ||
| commonArgs | ||
| // { | ||
| src = cargoSource; | ||
| buildPhaseCargoCommand = "cargo build --release --locked --package moon_cli --bins"; | ||
| } | ||
| ); | ||
|
|
||
| moon = craneLib.buildPackage ( | ||
| commonArgs | ||
| // { | ||
| inherit cargoArtifacts; | ||
|
|
||
| nativeBuildInputs = | ||
| nativeDeps | ||
| ++ (with pkgs; [ | ||
| installShellFiles | ||
| writableTmpDirAsHomeHook | ||
| ]); | ||
|
|
||
| postInstall = | ||
| pkgs.lib.optionalString (pkgs.stdenv.hostPlatform.emulatorAvailable pkgs.buildPackages) | ||
| ( | ||
| let | ||
| emulator = pkgs.stdenv.hostPlatform.emulator pkgs.buildPackages; | ||
| in | ||
| '' | ||
| installShellCompletion --cmd moon \ | ||
| --bash <(${emulator} $out/bin/moon completions --shell bash) \ | ||
| --fish <(${emulator} $out/bin/moon completions --shell fish) \ | ||
| --zsh <(${emulator} $out/bin/moon completions --shell zsh) | ||
| '' | ||
| ); | ||
|
|
||
| meta = with pkgs.lib; { | ||
| description = "A monorepo build system and task runner for the web ecosystem"; | ||
| mainProgram = "moon"; | ||
| homepage = "https://github.com/moonrepo/moon"; | ||
| changelog = "https://github.com/moonrepo/moon/releases/tag/v${moonVersion}"; | ||
| license = licenses.mit; | ||
| maintainers = [ ]; | ||
| platforms = platforms.linux ++ [ "aarch64-darwin" ]; | ||
| }; | ||
| } | ||
| ); | ||
| in | ||
| { | ||
| packages = { | ||
| inherit moon; | ||
| moon-deps = cargoArtifacts; | ||
| default = moon; | ||
| }; | ||
|
|
||
| apps.default = { | ||
| type = "app"; | ||
| program = "${moon}/bin/moon"; | ||
| }; | ||
|
|
||
| devShells.default = pkgs.mkShell { | ||
| nativeBuildInputs = nativeDeps ++ [ | ||
| devRustToolchain | ||
| pkgs.just | ||
| pkgs.cargo-nextest | ||
| ]; | ||
| buildInputs = buildDeps; | ||
|
|
||
| env = { | ||
| OPENSSL_NO_VENDOR = "1"; | ||
| RUST_SRC_PATH = "${devRustToolchain}/lib/rustlib/src/rust/library"; | ||
| }; | ||
| }; | ||
| }; | ||
| } | ||
| ); | ||
| } | ||
| ); | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is intentional. craneLib.buildDepsOnly internally uses mkDummySrc, which replaces workspace sources and build scripts while compiling external dependencies. The real workspace crates and their compile-time assets are rebuilt by buildPackage using the broader
sourcefileset.Keeping these assets out of
cargoSourceprevents template, protobuf, grammar, or embedded WASM changes from unnecessarily invalidating the dependency artifact.This has been verified with successful full
moon-depsbuilds on Linux and Darwin, followed by a successful full aarch64-darwin package build.