Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ android/local.properties
tailscale.jks

# android sdk dir
./android-sdk
/android-sdk/

# Persistent $HOME/.android for `make docker-*` (keeps debug.keystore so
# the debug signer is stable across container runs).
Expand Down
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,37 @@ alias nix='nix --extra-experimental-features "nix-command flakes"'
nix develop
```

The flake provides host tools such as Java, `make`, `curl`, and `git`, and
points the build at a repo-local Android SDK in `./android-sdk`. The SDK
directory is ignored by Git and is reused across builds.

On first use, install the Android SDK components:

```sh
make androidsdk
```

Then build normally:

```sh
make tailscale-debug
```

The debug APK is written to `./tailscale-debug.apk`.

For one-shot commands without entering an interactive shell:

```sh
nix develop --command make androidsdk
nix develop --command make tailscale-debug
```

For faster Kotlin-only iteration while avoiding the `gomobile bind` step:

```sh
nix develop --command bash -lc 'cd android && ./gradlew ktfmtCheck compileDebugKotlin'
```

## Building

```sh
Expand Down
97 changes: 5 additions & 92 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

100 changes: 54 additions & 46 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,58 +1,66 @@
{
description = "Tailscale build environment";
description = "Tailscale Android build environment";

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs";
android.url = "github:tadfisher/android-nixpkgs";
android.inputs.nixpkgs.follows = "nixpkgs";
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
};

outputs = { self, nixpkgs, android }:
outputs = { self, nixpkgs }:
let
supportedSystems = [ "x86_64-linux" "x86_64-darwin" "aarch64-darwin" ];
forAllSystems = f: nixpkgs.lib.genAttrs supportedSystems (system: f system);
in
{
devShells = forAllSystems
(system:
let
pkgs = import nixpkgs {
inherit system;
};
android-sdk = android.sdk.${system} (sdkPkgs: with sdkPkgs;
[
build-tools-30-0-2
cmdline-tools-latest
platform-tools
platforms-android-31
platforms-android-30
ndk-23-1-7779620
patcher-v4
]);
in
{
default = (with pkgs; buildFHSUserEnv {
name = "tailscale";
profile = ''
export ANDROID_SDK_ROOT="${android-sdk}/share/android-sdk"
export JAVA_HOME="${jdk8.home}"
'';
targetPkgs = pkgs: with pkgs; [
android-sdk
jdk8
clang
] ++ (if stdenv.isLinux then [
vulkan-headers
libxkbcommon
wayland
xorg.libX11
xorg.libXcursor
xorg.libXfixes
libGL
pkgconfig
] else [ ]);
}).env;
}
);
devShells = forAllSystems (system:
let
pkgs = import nixpkgs { inherit system; };

commonPackages = with pkgs; [
bash
cacert
curl
git
gnumake
gzip
jdk21
unzip
zip
];

linuxPackages = with pkgs; [
gcc
glibc
libGL
libx11
libxcursor
libxfixes
libxkbcommon
pkg-config
stdenv.cc.cc.lib
wayland
zlib
];

shellProfile = ''
export JAVA_HOME="${pkgs.jdk21.home}"
export ANDROID_SDK_ROOT="''${ANDROID_SDK_ROOT:-$PWD/android-sdk}"
export ANDROID_HOME="''${ANDROID_HOME:-$ANDROID_SDK_ROOT}"
export PATH="$PWD/tool:$PWD/android/build/go/bin:$ANDROID_HOME/cmdline-tools/latest/bin:$ANDROID_HOME/platform-tools:$PATH"

export GOTOOLCHAIN=local
export TS_USE_TOOLCHAIN=1

if [ ! -x "$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager" ]; then
echo "Android SDK not found at $ANDROID_HOME."
echo "Run: make androidsdk"
fi
'';
in
{
default = pkgs.mkShell {
packages = commonPackages ++ pkgs.lib.optionals pkgs.stdenv.isLinux linuxPackages;
shellHook = shellProfile;
};
});
};
}
Loading