diff --git a/docs/2-handbook/swarm/archetypes.md b/docs/2-handbook/swarm/archetypes.md index 319db6d0a..8c3a08f3e 100644 --- a/docs/2-handbook/swarm/archetypes.md +++ b/docs/2-handbook/swarm/archetypes.md @@ -20,7 +20,7 @@ The hyperhive flake ships these: | 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. | -| `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. | | `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. | diff --git a/nix/archetypes/default.nix b/nix/archetypes/default.nix index be9f67ad6..545c77b2c 100644 --- a/nix/archetypes/default.nix +++ b/nix/archetypes/default.nix @@ -30,6 +30,33 @@ android-dev = { module = { 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; environment.systemPackages = [ @@ -37,10 +64,26 @@ pkgs.gradle 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 = { 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; }; }; diff --git a/nix/archetypes/prompts/android-dev.md b/nix/archetypes/prompts/android-dev.md index 4ef75e50b..d880dd875 100644 --- a/nix/archetypes/prompts/android-dev.md +++ b/nix/archetypes/prompts/android-dev.md @@ -1,9 +1,10 @@ # Android developer 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 -mobile developer does: you run the build, read what it says, and trust the -device over your own guess about what the code does. +JDK, Gradle, the Android SDK (`ANDROID_HOME` is set), `adb` and `fastboot` at +hand, and you use them the way a careful mobile developer does: you run the +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 theory; a layout bug is a screenshot or a view dump, not a hunch. When diff --git a/nix/checks.nix b/nix/checks.nix index 081c8336f..3c2c7e32f 100644 --- a/nix/checks.nix +++ b/nix/checks.nix @@ -296,6 +296,11 @@ in inherit (pkgs) lib; 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 # function is tested without compiling a hyperhive binary. The two `grep -q` diff --git a/nix/module-eval/agent-android-dev.nix b/nix/module-eval/agent-android-dev.nix new file mode 100644 index 000000000..3a9c76568 --- /dev/null +++ b/nix/module-eval/agent-android-dev.nix @@ -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 [ ])); + } +]