-
Notifications
You must be signed in to change notification settings - Fork 5
chore: add nix flake dev shell #1238
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
icota
wants to merge
2
commits into
synonymdev:master
Choose a base branch
from
icota:chore/nix-flake-dev-shell
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| { | ||
| description = "Bitkit Android dev shell (JDK 17 + Android SDK 36/NDK r28b via androidenv)"; | ||
|
|
||
| # Provides the full toolchain to run: just compile / just build / just test / just lint | ||
| # | ||
| # Usage: | ||
| # nix develop # enter the shell | ||
| # just compile # or: ./gradlew assembleDevDebug | ||
| # | ||
| # Notes: | ||
| # - First `nix develop` downloads ~2 GB of SDK/NDK; first gradle run | ||
| # downloads the wrapper + all maven deps. | ||
| # - Emulator/system images are excluded to keep the closure small. | ||
| # For `just test android` without a physical device, flip the two | ||
| # flags in androidenv below. | ||
| # - On NixOS, adb access to a physical device needs udev rules: | ||
| # services.udev.packages = [ pkgs.android-udev-rules ]; | ||
| # - A fully sandboxed `nix build` of the APK is not provided: gradle | ||
| # needs network access for maven deps, which would require vendoring | ||
| # the whole dependency graph (e.g. via gradle2nix). | ||
|
|
||
| inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; | ||
|
|
||
| outputs = | ||
| { nixpkgs, ... }: | ||
| let | ||
| # Only x86_64-linux is verified; the rest should work via androidenv. | ||
| systems = [ | ||
| "x86_64-linux" | ||
| "aarch64-linux" | ||
| "x86_64-darwin" | ||
| "aarch64-darwin" | ||
| ]; | ||
| forAllSystems = nixpkgs.lib.genAttrs systems; | ||
| in | ||
| { | ||
| devShells = forAllSystems ( | ||
| system: | ||
| let | ||
| pkgs = import nixpkgs { | ||
| inherit system; | ||
| config = { | ||
| # Android SDK/NDK are unfree-licensed | ||
| allowUnfree = true; | ||
| android_sdk.accept_license = true; | ||
| }; | ||
| }; | ||
|
|
||
| buildToolsVersion = "36.0.0"; | ||
| # Keep in sync with ndk_ver in Justfile | ||
| ndkVersion = "28.1.13356709"; | ||
|
|
||
| androidSdk = pkgs.androidenv.composeAndroidPackages { | ||
| cmdLineToolsVersion = "latest"; | ||
| platformToolsVersion = "latest"; | ||
| platformVersions = [ "36" ]; # compileSdk/targetSdk | ||
| buildToolsVersions = [ buildToolsVersion ]; | ||
| includeNDK = true; | ||
| ndkVersions = [ ndkVersion ]; | ||
| includeEmulator = false; | ||
| includeSystemImages = false; | ||
| # No native code is built (rust libs ship as maven artifacts) | ||
| includeCmake = false; | ||
| }; | ||
|
|
||
| sdkRoot = "${androidSdk.androidsdk}/libexec/android-sdk"; | ||
| in | ||
| { | ||
| default = pkgs.mkShell { | ||
| packages = with pkgs; [ | ||
| jdk17 # AGP 9.3 / Gradle 9.5 require JDK 17+ | ||
| just | ||
| git | ||
| ]; | ||
|
|
||
| JAVA_HOME = "${pkgs.jdk17.home}"; | ||
| ANDROID_HOME = sdkRoot; | ||
| ANDROID_SDK_ROOT = sdkRoot; | ||
| ANDROID_NDK_ROOT = "${sdkRoot}/ndk/${ndkVersion}"; | ||
|
|
||
| shellHook = '' | ||
| export PATH="$ANDROID_HOME/platform-tools:$PATH" | ||
|
|
||
| # AGP fetches aapt2 from maven as an unpatched ELF binary that | ||
| # cannot run on NixOS; point it at the patched one from the SDK. | ||
| aapt2="$ANDROID_HOME/build-tools/${buildToolsVersion}/aapt2" | ||
| gradle_props="''${GRADLE_USER_HOME:-$HOME/.gradle}/gradle.properties" | ||
| mkdir -p "$(dirname "$gradle_props")" | ||
| touch "$gradle_props" | ||
| if grep -qs '^android.aapt2FromMavenOverride=' "$gradle_props"; then | ||
| # Refresh overrides previously written by this hook (stale store | ||
| # paths break after a flake update + gc); leave custom ones alone. | ||
| sed -i "s|^android.aapt2FromMavenOverride=/nix/store/.*|android.aapt2FromMavenOverride=$aapt2|" "$gradle_props" | ||
| else | ||
| echo "android.aapt2FromMavenOverride=$aapt2" >> "$gradle_props" | ||
| echo ">> added aapt2 override to $gradle_props" | ||
| fi | ||
|
|
||
| echo "bitkit-android dev shell" | ||
| echo " java: $(java -version 2>&1 | head -1)" | ||
| echo " ANDROID_HOME: $ANDROID_HOME" | ||
| ''; | ||
| }; | ||
| } | ||
| ); | ||
| }; | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If a developer has intentionally configured an aapt2 override under
/nix/store/, entering this shell replaces it because the pattern treats every Nix-store value as hook-owned. The hook edits the persistent user-level Gradle properties file, so this non-blocking issue can also change aapt2 behavior in unrelated Gradle projects. Track which value the hook generated instead of using the/nix/store/prefix as ownership.