# `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 [ ])); } ]