Watch
0
0
Fork
You've already forked hyperhive
0
hyperhive/nix/module-eval/agent-android-dev.nix
maia c9204ad0e0 android-dev archetype: ship the Android SDK and nix-ld so a Gradle build runs
The archetype installed Gradle, a JDK and android-tools but no SDK, no
ANDROID_HOME/JAVA_HOME and no nix-ld, so the aapt2 Gradle downloads could not
start on NixOS and an agent could not build an app.

It now builds an SDK (build-tools 36.1.0, platform 35, no emulator or system
images), sets ANDROID_HOME, ANDROID_SDK_ROOT and JAVA_HOME, and enables
programs.nix-ld. The SDK's unfree names are read off the SDK and added to
allowUnfreePackages, which adds to the claude-code allowance instead of
replacing it.

Closes #6696
2026-11-20 19:35:47 +01:00

80 lines
3 KiB
Nix

# `checks.module-eval-agent-android-dev` — see ./lib.nix for the shared
# rationale (why this suite exists, naming convention, "evaluates
# not executes").
{
pkgs,
lib,
self,
nixosSystem,
shared,
}:
let
inherit
(import ./lib.nix {
inherit
pkgs
lib
self
nixosSystem
;
})
agentWith
runGroup
;
# The archetype's own module is the "on" arm; a bare agent is every absence.
android = agentWith self.hyperhiveArchetypes.android-dev.module;
bare = shared.agentBare;
vars = machine: machine.environment.variables;
libNames = machine: map lib.getName machine.programs.nix-ld.libraries;
# Forcing the string forces the SDK derivation, which is where nixpkgs refuses
# an unfree package that is not allowed. `tryEval` turns that refusal into
# `false`.
sdkEvaluates =
machine: (builtins.tryEval (builtins.stringLength (vars machine).ANDROID_HOME > 0)).success;
allowsUnfree = machine: pname: machine.nixpkgs.config.allowUnfreePredicate { inherit pname; };
in
runGroup "agent-android-dev" [
{
# Gradle and the Android tools read `ANDROID_HOME` first and
# `ANDROID_SDK_ROOT` as the older spelling, so both must name the same
# tree, which has to be the SDK's own `libexec/android-sdk`.
name = "android-dev points ANDROID_HOME and ANDROID_SDK_ROOT at the SDK and JAVA_HOME at the JDK";
ok =
(vars android).ANDROID_HOME == (vars android).ANDROID_SDK_ROOT or null
&& lib.hasSuffix "-androidsdk/libexec/android-sdk" (vars android).ANDROID_HOME
&& (vars android).JAVA_HOME == "${pkgs.jdk.home}";
}
{
# Without the loader, the `aapt2` Gradle downloads cannot start on NixOS,
# which is the failure this archetype exists to prevent.
name = "android-dev enables nix-ld, whose libraries include the C++ runtime and zlib that Gradle's downloaded aapt2 links against";
ok =
android.programs.nix-ld.enable
&& lib.elem (lib.getName pkgs.stdenv.cc.cc.lib) (libNames android)
&& lib.elem (lib.getName pkgs.zlib) (libNames android);
}
{
# The SDK is unfree and nixpkgs throws when it is not allowed. The claude-code
# allowance the agent modules set must survive next to it: a second
# `allowUnfreePredicate` would replace it, which is why the SDK is allowed by name.
name = "android-dev's SDK evaluates, claude-code stays allowed, and an unrelated unfree package is not";
ok =
sdkEvaluates android
&& allowsUnfree android "claude-code"
&& lib.all (n: lib.elem n android.nixpkgs.config.allowUnfreePackages) [
"android-sdk-platform-tools"
"android-sdk-build-tools"
]
&& !(allowsUnfree android "some-other-unfree-package");
}
{
name = "an agent without the archetype gets no nix-ld, no Android variables and no SDK allowance";
ok =
!bare.programs.nix-ld.enable
&& !(vars bare ? ANDROID_HOME)
&& !(vars bare ? ANDROID_SDK_ROOT)
&& !(lib.elem "android-sdk-platform-tools" (bare.nixpkgs.config.allowUnfreePackages or [ ]));
}
]