Skip to content

Commit 3551106

Browse files
committed
build: make flake usable for host Android builds
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
1 parent 8fb1ef9 commit 3551106

4 files changed

Lines changed: 91 additions & 139 deletions

File tree

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ android/local.properties
2626
tailscale.jks
2727

2828
# android sdk dir
29-
./android-sdk
29+
/android-sdk/
3030

3131
# Persistent $HOME/.android for `make docker-*` (keeps debug.keystore so
3232
# the debug signer is stable across container runs).

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,37 @@ alias nix='nix --extra-experimental-features "nix-command flakes"'
9292
nix develop
9393
```
9494

95+
The flake provides host tools such as Java, `make`, `curl`, and `git`, and
96+
points the build at a repo-local Android SDK in `./android-sdk`. The SDK
97+
directory is ignored by Git and is reused across builds.
98+
99+
On first use, install the Android SDK components:
100+
101+
```sh
102+
make androidsdk
103+
```
104+
105+
Then build normally:
106+
107+
```sh
108+
make tailscale-debug
109+
```
110+
111+
The debug APK is written to `./tailscale-debug.apk`.
112+
113+
For one-shot commands without entering an interactive shell:
114+
115+
```sh
116+
nix develop --command make androidsdk
117+
nix develop --command make tailscale-debug
118+
```
119+
120+
For faster Kotlin-only iteration while avoiding the `gomobile bind` step:
121+
122+
```sh
123+
nix develop --command bash -lc 'cd android && ./gradlew ktfmtCheck compileDebugKotlin'
124+
```
125+
95126
## Building
96127

97128
```sh

flake.lock

Lines changed: 5 additions & 92 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 54 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,66 @@
11
{
2-
description = "Tailscale build environment";
2+
description = "Tailscale Android build environment";
33

44
inputs = {
5-
nixpkgs.url = "github:NixOS/nixpkgs";
6-
android.url = "github:tadfisher/android-nixpkgs";
7-
android.inputs.nixpkgs.follows = "nixpkgs";
5+
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
86
};
97

10-
outputs = { self, nixpkgs, android }:
8+
outputs = { self, nixpkgs }:
119
let
1210
supportedSystems = [ "x86_64-linux" "x86_64-darwin" "aarch64-darwin" ];
1311
forAllSystems = f: nixpkgs.lib.genAttrs supportedSystems (system: f system);
1412
in
1513
{
16-
devShells = forAllSystems
17-
(system:
18-
let
19-
pkgs = import nixpkgs {
20-
inherit system;
21-
};
22-
android-sdk = android.sdk.${system} (sdkPkgs: with sdkPkgs;
23-
[
24-
build-tools-30-0-2
25-
cmdline-tools-latest
26-
platform-tools
27-
platforms-android-31
28-
platforms-android-30
29-
ndk-23-1-7779620
30-
patcher-v4
31-
]);
32-
in
33-
{
34-
default = (with pkgs; buildFHSUserEnv {
35-
name = "tailscale";
36-
profile = ''
37-
export ANDROID_SDK_ROOT="${android-sdk}/share/android-sdk"
38-
export JAVA_HOME="${jdk8.home}"
39-
'';
40-
targetPkgs = pkgs: with pkgs; [
41-
android-sdk
42-
jdk8
43-
clang
44-
] ++ (if stdenv.isLinux then [
45-
vulkan-headers
46-
libxkbcommon
47-
wayland
48-
xorg.libX11
49-
xorg.libXcursor
50-
xorg.libXfixes
51-
libGL
52-
pkgconfig
53-
] else [ ]);
54-
}).env;
55-
}
56-
);
14+
devShells = forAllSystems (system:
15+
let
16+
pkgs = import nixpkgs { inherit system; };
17+
18+
commonPackages = with pkgs; [
19+
bash
20+
cacert
21+
curl
22+
git
23+
gnumake
24+
gzip
25+
jdk21
26+
unzip
27+
zip
28+
];
29+
30+
linuxPackages = with pkgs; [
31+
gcc
32+
glibc
33+
libGL
34+
libx11
35+
libxcursor
36+
libxfixes
37+
libxkbcommon
38+
pkg-config
39+
stdenv.cc.cc.lib
40+
wayland
41+
zlib
42+
];
43+
44+
shellProfile = ''
45+
export JAVA_HOME="${pkgs.jdk21.home}"
46+
export ANDROID_SDK_ROOT="''${ANDROID_SDK_ROOT:-$PWD/android-sdk}"
47+
export ANDROID_HOME="''${ANDROID_HOME:-$ANDROID_SDK_ROOT}"
48+
export PATH="$PWD/tool:$PWD/android/build/go/bin:$ANDROID_HOME/cmdline-tools/latest/bin:$ANDROID_HOME/platform-tools:$PATH"
49+
50+
export GOTOOLCHAIN=local
51+
export TS_USE_TOOLCHAIN=1
52+
53+
if [ ! -x "$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager" ]; then
54+
echo "Android SDK not found at $ANDROID_HOME."
55+
echo "Run: make androidsdk"
56+
fi
57+
'';
58+
in
59+
{
60+
default = pkgs.mkShell {
61+
packages = commonPackages ++ pkgs.lib.optionals pkgs.stdenv.isLinux linuxPackages;
62+
shellHook = shellProfile;
63+
};
64+
});
5765
};
5866
}

0 commit comments

Comments
 (0)