I am trying to figure out how to use Nix to build an android development docker image

I am trying to figure out how to use Nix to build an android development docker image.
I’ve read the docker tutoril
and the android framework docs.

I have an old Docker file that builds a CI builder image, and my goal is to convert it to Nix.
I created an initial image based on what I gleaned from the docs and examples, but the resulting
image is about twice as large (9G vs 5G). I’m not sure if this is a result of the docker tools
or the android framework installing more than it needs to.

The original Docker file is:

FROM eclipse-temurin:17-jdk

# command line tools from https://developer.android.com/studio/#command-tools
ENV ANDROID_COMPILE_SDK=34 \
    ANDROID_BUILD_TOOLS=34.0.0 \
    ANDROID_CMDLINE_TOOLS=11076708

ENV ANDROID_SDK_ROOT=/usr/local/android-sdk-linux 

# set deprecated ANDROID_HOME to support old configs
ENV ANDROID_HOME=$ANDROID_SDK_ROOT 

# Update and install system tools

RUN apt update \
 && apt --quiet install --yes wget tar unzip lib32stdc++6 lib32z1

# Install the Android command line tools

RUN wget --output-document=commandlinetools.zip https://dl.google.com/android/repository/commandlinetools-linux-${ANDROID_CMDLINE_TOOLS}_latest.zip
RUN install -d $ANDROID_SDK_ROOT 
RUN unzip -d $ANDROID_SDK_ROOT/cmdline-tools commandlinetools.zip 
RUN mv $ANDROID_SDK_ROOT/cmdline-tools/cmdline-tools $ANDROID_SDK_ROOT/cmdline-tools/latest 
ENV PATH=${PATH}:${ANDROID_SDK_ROOT}/cmdline-tools/latest/bin/:${ANDROID_SDK_ROOT}/platform-tools

# Use the sdkmanager to install everything else

RUN echo y | sdkmanager "platforms;android-$ANDROID_COMPILE_SDK" 
RUN echo y | sdkmanager "platform-tools" 
RUN echo y | sdkmanager "build-tools;$ANDROID_BUILD_TOOLS" 
RUN echo y | sdkmanager "ndk-bundle" 
RUN yes | sdkmanager --licenses

And my first attempt at creating a flake for building it is:

{
  description = "";

  inputs = {
  };

  outputs = {
    self,
    nixpkgs,
  }: let
    system = "x86_64-linux";
    pkgs = import nixpkgs {
      inherit system;
      config.android_sdk.accept_license = true;
      config.allowUnfree = true;
    };
    sdk = pkgs.androidenv.composeAndroidPackages {
      cmdLineToolsVersion = "8.0";
      toolsVersion = null;
      buildToolsVersions = ["34.0.0"];
      platformVersions = ["34"];
      includeNDK = true;
      includeSources = false;
      includeSystemImages = false;
    };

    jdk17 = pkgs.dockerTools.pullImage {
      imageName = "eclipse-temurin";
      sha256 = "sha256-8dlxVTmsXgg7amfezG8d6rvhuOUDlbay4guSYPXSj88=";
      imageDigest = "sha256:39fc8112490b67760d2dd3c8d73176f0ed323e99e7a7f09449d44fb8d1b350cc";
    };
  in {
    packages.${system}.default = pkgs.dockerTools.buildImage {
      name = "pipeline";
      tag = "latest";
      fromImage = jdk17;
      copyToRoot = pkgs.buildEnv {
        name = "image-root";
        paths = [
          sdk.androidsdk
        ];
      };
    };
  };
}

Does anyone have any insights as to why the results are so different?