From 336fd9c49fff3e2e2d8ce751007fab52a9a6f044 Mon Sep 17 00:00:00 2001 From: austinried <4966622+austinried@users.noreply.github.com> Date: Fri, 9 Oct 2026 07:42:05 +0000 Subject: [PATCH] build: guard local gradle runs against exhausting the box The devshell `gradle` now serialises local builds with flock and runs them under `nice` with capped workers, so several agents building at once queue instead of piling up daemons and compile workers and taking the machine down. With CI/GITHUB_ACTIONS set it execs Gradle directly, leaving CI untouched. Also shorten the Gradle daemon idle timeout so idle daemons are reaped sooner. --- AGENTS.md | 1 + flake.nix | 10 +++++++++- gradle.properties | 1 + 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/AGENTS.md b/AGENTS.md index 5e3b046a..241af7bf 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -14,6 +14,7 @@ Everything comes from the Nix flake devshell; do not install toolchains by hand. - The default devshell provides JDK 21, Gradle 9, the Android SDK (platform 37, build-tools 37.0.0, platform-tools 37.0.1) and nushell. - The integration harness needs real servers, so it lives in a separate `nix develop .#integration` shell (navidrome, gonic, lms, php, Nextcloud with the Music app, sqlite). Keeping them out of the default shell avoids pulling that closure into everyday builds. - Build with the devshell `gradle`, not `./gradlew`. CI uses the nix Gradle pinned by `flake.lock`; the wrapper is kept only for people without Nix. +- The devshell `gradle` is a wrapper: outside CI it takes a lock (`flock /tmp/subtracks-gradle.lock`) and runs under `nice` with capped workers, so several agents building at once queue instead of exhausting the box. With `CI`/`GITHUB_ACTIONS` set (i.e. CI) it execs Gradle directly, unchanged. ## Commands diff --git a/flake.nix b/flake.nix index 6a76b535..2a465840 100644 --- a/flake.nix +++ b/flake.nix @@ -40,9 +40,17 @@ }; androidSdk = android.androidsdk; + gradle_wrapper = pkgs.writeShellScriptBin "gradle" '' + if [ -n "''${CI:-}''${GITHUB_ACTIONS:-}" ]; then + exec ${pkgs.gradle_9}/bin/gradle "$@" + fi + exec ${pkgs.util-linux}/bin/flock /tmp/subtracks-gradle.lock \ + ${pkgs.coreutils}/bin/nice -n 10 ${pkgs.gradle_9}/bin/gradle --max-workers=4 "$@" + ''; + basePackages = [ pkgs.jdk21 - pkgs.gradle_9 + gradle_wrapper pkgs.git pkgs.curl pkgs.unzip diff --git a/gradle.properties b/gradle.properties index 4839c061..889e554e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,6 +3,7 @@ org.gradle.parallel=true org.gradle.caching=true org.gradle.configuration-cache=true org.gradle.configuration-cache.problems=warn +org.gradle.daemon.idletimeout=600000 android.useAndroidX=true android.nonTransitiveRClass=true