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
This commit is contained in:
parent
0e147618d0
commit
c9204ad0e0
5 changed files with 134 additions and 5 deletions
|
|
@ -20,7 +20,7 @@ The hyperhive flake ships these:
|
||||||
| archetype | what it sets |
|
| archetype | what it sets |
|
||||||
| ------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
| ------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||||
| `reviewer` | permissions `messaging`, `inbox`, `execution`: the default set without `meta`. With `execution` it can run `hive-forge`, `git` and other commands. |
|
| `reviewer` | permissions `messaging`, `inbox`, `execution`: the default set without `meta`. With `execution` it can run `hive-forge`, `git` and other commands. |
|
||||||
| `android-dev` | installs `android-tools` (`adb`, `fastboot`), Gradle and a JDK; default permissions. |
|
| `android-dev` | installs `android-tools` (`adb`, `fastboot`), Gradle, a JDK, the Android SDK (build-tools 36.1.0, platform 35) and nix-ld, and sets `ANDROID_HOME`, `ANDROID_SDK_ROOT` and `JAVA_HOME`, so the `aapt2` Gradle downloads runs; default permissions. |
|
||||||
| `reverse-engineer` | sets `services.hyperhive.agent.rea.enable`: installs REA, Ghidra 12.1 and procps, and allows all REA MCP tools; default permissions and the agent's normal memory cap. |
|
| `reverse-engineer` | sets `services.hyperhive.agent.rea.enable`: installs REA, Ghidra 12.1 and procps, and allows all REA MCP tools; default permissions and the agent's normal memory cap. |
|
||||||
| `ruth` | the manager agent. Inference model `sonnet`; permissions: the default set plus `manage_root_agent`, `logs` and `metrics`. Its module is empty. The swarm UI's setup assistant creates ruth from it. |
|
| `ruth` | the manager agent. Inference model `sonnet`; permissions: the default set plus `manage_root_agent`, `logs` and `metrics`. Its module is empty. The swarm UI's setup assistant creates ruth from it. |
|
||||||
| `triage` | labels and assigns every new issue and pull request, then routes it. Inference model `haiku`; default permissions. It has no forge subscription: [its flows](#notification-flows) send it a todo for each new or reopened issue and each new pull request. |
|
| `triage` | labels and assigns every new issue and pull request, then routes it. Inference model `haiku`; default permissions. It has no forge subscription: [its flows](#notification-flows) send it a todo for each new or reopened issue and each new pull request. |
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,33 @@
|
||||||
android-dev = {
|
android-dev = {
|
||||||
module =
|
module =
|
||||||
{ pkgs, lib, ... }:
|
{ pkgs, lib, ... }:
|
||||||
|
let
|
||||||
|
# build-tools 36.1.0 and platform 35: the pair the damocles agent builds
|
||||||
|
# with. No emulator and no system images; they are large, and a build
|
||||||
|
# is run against a device or an emulator elsewhere.
|
||||||
|
sdk = pkgs.androidenv.composeAndroidPackages {
|
||||||
|
buildToolsVersions = [ "36.1.0" ];
|
||||||
|
platformVersions = [ "35" ];
|
||||||
|
includeEmulator = false;
|
||||||
|
includeSystemImages = false;
|
||||||
|
};
|
||||||
|
sdkRoot = "${sdk.androidsdk}/libexec/android-sdk";
|
||||||
|
# The unfree names the SDK needs: each package it is built from and
|
||||||
|
# the archives those fetch. Read off the SDK itself, because the
|
||||||
|
# archive names carry versions that change with every nixpkgs bump.
|
||||||
|
asDrvs =
|
||||||
|
v:
|
||||||
|
if lib.isDerivation v then
|
||||||
|
[ v ]
|
||||||
|
else if lib.isList v then
|
||||||
|
lib.concatMap asDrvs v
|
||||||
|
else
|
||||||
|
[ ];
|
||||||
|
sdkParts = lib.concatMap asDrvs (lib.attrValues (removeAttrs sdk [ "recurseForDerivations" ]));
|
||||||
|
sdkUnfree = lib.unique (
|
||||||
|
map lib.getName (lib.concatMap (part: [ part ] ++ asDrvs (part.src or [ ])) sdkParts)
|
||||||
|
);
|
||||||
|
in
|
||||||
{
|
{
|
||||||
services.hyperhive.agent.icon = lib.mkDefault ./icons/android-dev.svg;
|
services.hyperhive.agent.icon = lib.mkDefault ./icons/android-dev.svg;
|
||||||
environment.systemPackages = [
|
environment.systemPackages = [
|
||||||
|
|
@ -37,10 +64,26 @@
|
||||||
pkgs.gradle
|
pkgs.gradle
|
||||||
pkgs.jdk
|
pkgs.jdk
|
||||||
];
|
];
|
||||||
|
environment.variables = {
|
||||||
|
ANDROID_HOME = sdkRoot;
|
||||||
|
ANDROID_SDK_ROOT = sdkRoot;
|
||||||
|
JAVA_HOME = "${pkgs.jdk.home}";
|
||||||
|
};
|
||||||
|
# Gradle downloads and runs its own prebuilt `aapt2`, a foreign dynamic
|
||||||
|
# binary that NixOS cannot start without a loader at /lib64. nix-ld is
|
||||||
|
# that loader. Its default library set already carries the C++ runtime
|
||||||
|
# and zlib that the download links against, and the module-eval check
|
||||||
|
# asserts it still does.
|
||||||
|
programs.nix-ld.enable = true;
|
||||||
|
# The SDK packages are unfree and ask for their licence to be accepted.
|
||||||
|
# `allowUnfreePackages` adds to the claude-code allowance the agent
|
||||||
|
# modules set, where a second `allowUnfreePredicate` would replace it.
|
||||||
|
nixpkgs.config.android_sdk.accept_license = true;
|
||||||
|
nixpkgs.config.allowUnfreePackages = sdkUnfree;
|
||||||
};
|
};
|
||||||
meta = {
|
meta = {
|
||||||
icon = builtins.readFile ./icons/android-dev.svg;
|
icon = builtins.readFile ./icons/android-dev.svg;
|
||||||
description = "Builds Android apps: adb and fastboot (android-tools), Gradle and a JDK are installed. It holds the default permissions.";
|
description = "Builds Android apps: adb and fastboot (android-tools), Gradle, a JDK, the Android SDK (build-tools 36.1.0, platform 35) and nix-ld, so Gradle's downloaded aapt2 runs. ANDROID_HOME and JAVA_HOME are set. It holds the default permissions.";
|
||||||
prompt = builtins.readFile ./prompts/android-dev.md;
|
prompt = builtins.readFile ./prompts/android-dev.md;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,10 @@
|
||||||
# Android developer
|
# Android developer
|
||||||
|
|
||||||
You build Android apps, and you like it when the build is boring. You have a
|
You build Android apps, and you like it when the build is boring. You have a
|
||||||
JDK, Gradle, `adb` and `fastboot` at hand, and you use them the way a careful
|
JDK, Gradle, the Android SDK (`ANDROID_HOME` is set), `adb` and `fastboot` at
|
||||||
mobile developer does: you run the build, read what it says, and trust the
|
hand, and you use them the way a careful mobile developer does: you run the
|
||||||
device over your own guess about what the code does.
|
build, read what it says, and trust the device over your own guess about what
|
||||||
|
the code does.
|
||||||
|
|
||||||
You work from evidence. A crash is a stack trace from `adb logcat`, not a
|
You work from evidence. A crash is a stack trace from `adb logcat`, not a
|
||||||
theory; a layout bug is a screenshot or a view dump, not a hunch. When
|
theory; a layout bug is a screenshot or a view dump, not a hunch. When
|
||||||
|
|
|
||||||
|
|
@ -296,6 +296,11 @@ in
|
||||||
inherit (pkgs) lib;
|
inherit (pkgs) lib;
|
||||||
shared = moduleEvalShared;
|
shared = moduleEvalShared;
|
||||||
};
|
};
|
||||||
|
module-eval-agent-android-dev = import ./module-eval/agent-android-dev.nix {
|
||||||
|
inherit pkgs self nixosSystem;
|
||||||
|
inherit (pkgs) lib;
|
||||||
|
shared = moduleEvalShared;
|
||||||
|
};
|
||||||
|
|
||||||
# Builds `mkServiceImage` around `hello` and reads the tarball back, so the
|
# Builds `mkServiceImage` around `hello` and reads the tarball back, so the
|
||||||
# function is tested without compiling a hyperhive binary. The two `grep -q`
|
# function is tested without compiling a hyperhive binary. The two `grep -q`
|
||||||
|
|
|
||||||
80
nix/module-eval/agent-android-dev.nix
Normal file
80
nix/module-eval/agent-android-dev.nix
Normal file
|
|
@ -0,0 +1,80 @@
|
||||||
|
# `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 [ ]));
|
||||||
|
}
|
||||||
|
]
|
||||||
Loading…
Reference in a new issue