From 1b2095aa5bdc0096f604c7dfe75a9cceb4d02533 Mon Sep 17 00:00:00 2001 From: Guillaume ETHEVE Date: Fri, 6 Nov 2026 04:21:21 +0100 Subject: [PATCH] build: add reproducible Nix Android and Wear OS environment --- .envrc | 3 ++ .gitignore | 5 +++ App_Resources/Android/app.gradle | 8 ++++ devenv.lock | 65 ++++++++++++++++++++++++++++++++ devenv.nix | 42 +++++++++++++++++++++ devenv.yaml | 7 ++++ docs/development-nix.md | 29 ++++++++++++++ scripts/check-devenv.sh | 18 +++++++++ 8 files changed, 177 insertions(+) create mode 100644 .envrc create mode 100644 devenv.lock create mode 100644 devenv.nix create mode 100644 devenv.yaml create mode 100644 docs/development-nix.md create mode 100644 scripts/check-devenv.sh diff --git a/.envrc b/.envrc new file mode 100644 index 00000000..7b430716 --- /dev/null +++ b/.envrc @@ -0,0 +1,3 @@ +watch_file devenv.nix devenv.yaml devenv.lock +eval "$(devenv direnvrc)" +use devenv diff --git a/.gitignore b/.gitignore index 326fbf1f..7c5c5213 100644 --- a/.gitignore +++ b/.gitignore @@ -49,6 +49,11 @@ faceclaw_settings.xml faceclaw_settings*.json # Developer configs +.devenv* +.direnv/ +.android/ +devenv.local.nix +local.properties build_paths.sh **/xcuserdata/ diff --git a/App_Resources/Android/app.gradle b/App_Resources/Android/app.gradle index 997e1f4d..9e3c4b63 100644 --- a/App_Resources/Android/app.gradle +++ b/App_Resources/Android/app.gradle @@ -162,6 +162,14 @@ tasks.register("prepareFaceclawNativeLibs") { def faceclawLlamaCppTag = "b10333" def faceclawFindSdkCmakeDir = { + // NixOS and other managed environments can provide patched host tools. + def explicitCmake = System.getenv("ANDROID_CMAKE_HOME") + if (explicitCmake != null) { + def explicitDir = file(explicitCmake) + if (faceclawHostExecutable(file("$explicitDir/bin"), "cmake").exists() + && faceclawHostExecutable(file("$explicitDir/bin"), "ninja").exists()) return explicitDir + throw new GradleException("ANDROID_CMAKE_HOME must contain bin/cmake and bin/ninja: $explicitDir") + } def sdkRoot = System.getenv("ANDROID_HOME") ?: System.getenv("ANDROID_SDK_ROOT") if (sdkRoot == null) return null def cmakeRoot = file("$sdkRoot/cmake") diff --git a/devenv.lock b/devenv.lock new file mode 100644 index 00000000..76a4dbe1 --- /dev/null +++ b/devenv.lock @@ -0,0 +1,65 @@ +{ + "nodes": { + "devenv": { + "locked": { + "dir": "src/modules", + "lastModified": 1793731702, + "narHash": "sha256-WlVNaWXVTYaGBNey2Z+20sY1lT7BvzJEECb+VlDDdk0=", + "owner": "cachix", + "repo": "devenv", + "rev": "9655d320b8f9df74dbecf681f52a7334574606c3", + "type": "github" + }, + "original": { + "dir": "src/modules", + "owner": "cachix", + "repo": "devenv", + "type": "github" + } + }, + "nixpkgs": { + "inputs": { + "nixpkgs-src": "nixpkgs-src" + }, + "locked": { + "lastModified": 1793043970, + "narHash": "sha256-m14odYTdkBUEkJOiEYs2zjGjn8fcjvdCJsm45+k084U=", + "owner": "cachix", + "repo": "devenv-nixpkgs", + "rev": "d97234e58d4e90e3bf77c082fc3b546e51200938", + "type": "github" + }, + "original": { + "owner": "cachix", + "ref": "rolling", + "repo": "devenv-nixpkgs", + "type": "github" + } + }, + "nixpkgs-src": { + "flake": false, + "locked": { + "lastModified": 1792812153, + "narHash": "sha256-T2+XBfNbf9pecLUWS4+RtuVNZ3W8K5taG5QdV71mWlk=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "674a2028661e550a97400c1cc992b9cca9a668a1", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "devenv": "devenv", + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} \ No newline at end of file diff --git a/devenv.nix b/devenv.nix new file mode 100644 index 00000000..61f3f63e --- /dev/null +++ b/devenv.nix @@ -0,0 +1,42 @@ +{ pkgs, config, lib, ... }: +{ + languages.javascript = { + enable = true; + package = pkgs.nodejs_22; + }; + languages.java = { + enable = true; + jdk.package = pkgs.jdk21; + lsp.enable = false; + }; + android = { + enable = true; + platforms.version = [ "35" ]; + buildTools.version = [ "34.0.0" "35.0.0" "35.0.1" ]; + ndk.enable = true; + ndk.version = [ "27.2.12479018" ]; + cmake.version = [ ]; + emulator.enable = false; + systemImages.enable = false; + sources.enable = false; + }; + packages = with pkgs; [ git gh curl jq ripgrep python3 pkg-config gnumake gcc unzip zip ]; + # Gradle's downloaded aapt2 cannot run directly on NixOS. + # Keep API 35 aapt2 for phone builds even with Wear's older tools installed. + env.GRADLE_OPTS = lib.mkForce "-Dorg.gradle.project.android.aapt2FromMavenOverride=${config.env.ANDROID_HOME}/build-tools/35.0.0/aapt2"; + # NativeScript's doctor rejects a valid build-only SDK without an emulator. + # enterTest below checks the actual tools used by our local builds. + env.NS_SKIP_ENV_CHECK = "1"; + env.ANDROID_CMAKE_HOME = "${pkgs.symlinkJoin { + name = "faceclaw-cmake"; + paths = [ pkgs.cmake pkgs.ninja ]; + }}"; + scripts.faceclaw-setup.exec = "npm ci"; + scripts.faceclaw-test.exec = "npm test"; + enterShell = '' + export PATH="$DEVENV_ROOT/node_modules/.bin:$PATH" + ''; + enterTest = '' + bash "$DEVENV_ROOT/scripts/check-devenv.sh" + ''; +} diff --git a/devenv.yaml b/devenv.yaml new file mode 100644 index 00000000..e950cd74 --- /dev/null +++ b/devenv.yaml @@ -0,0 +1,7 @@ +inputs: + nixpkgs: + url: github:cachix/devenv-nixpkgs/rolling +nixpkgs: + allow_unfree: true + android_sdk: + accept_license: true diff --git a/docs/development-nix.md b/docs/development-nix.md new file mode 100644 index 00000000..9cb52233 --- /dev/null +++ b/docs/development-nix.md @@ -0,0 +1,29 @@ +# Nix development environment + +Install Nix with flakes and devenv, then run `devenv shell` in this directory +(or `nix run nixpkgs#devenv -- shell`). With direnv, `direnv allow` loads `.envrc`. +The committed `devenv.lock` pins the environment inputs. + +The environment provides Node 22/npm, Java 21, Android SDK/platform 35, +build-tools 34.0.0 (Wear OS) and 35.0.0/35.0.1 (phone and NativeScript plugins), NDK 27, CMake, +Git/GitHub CLI, Python and build utilities. `ANDROID_CMAKE_HOME` selects the +Nix-patched CMake/Ninja pair for the native Android libraries (the SDK's bundled +Ninja can crash on NixOS). Other environments keep using the SDK's CMake. +Android SDK licenses are accepted through `devenv.yaml`. Gradle uses the +Nix-patched SDK aapt2. Gradle itself comes from the repository's wrapper. +The emulator and system images are omitted. `NS_SKIP_ENV_CHECK=1` bypasses +NativeScript doctor's mandatory emulator check; `devenv test` checks the actual +SDK/JDK build prerequisites instead. + +Run `faceclaw-setup` (`npm ci`) once, then `faceclaw-test` (`npm test`), +`npm run lint` and `npm run test:kotlin`. `devenv test` checks the environment. +`bash build.sh` builds the Android app; it does not install it. On NixOS, any +additional downloaded native executables may require the host's nix-ld support. +iOS builds still require macOS/Xcode and are outside this Linux environment. + +Keep machine-specific signing/device settings in the ignored `build_paths.sh`. +Use `gh auth login` separately if GitHub CLI is not already authenticated. + +Software tests do not validate Bluetooth behavior on physical glasses. Record +device/firmware versions and manual results separately for hardware checks. +Do not flash firmware during development without explicit permission. diff --git a/scripts/check-devenv.sh b/scripts/check-devenv.sh new file mode 100644 index 00000000..3caf9c34 --- /dev/null +++ b/scripts/check-devenv.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash +set -euo pipefail + +node --version +java -version +test -f "$ANDROID_HOME/platforms/android-35/android.jar" +for version in 34.0.0 35.0.0 35.0.1; do + "$ANDROID_HOME/build-tools/$version/aapt2" version +done +"$ANDROID_HOME/platform-tools/adb" version +"$ANDROID_CMAKE_HOME/bin/cmake" --version +"$ANDROID_CMAKE_HOME/bin/ninja" --version +case "$(uname -s)" in + Darwin) ndk_host=darwin-x86_64 ;; + *) ndk_host=linux-x86_64 ;; +esac +test -x "$ANDROID_HOME/ndk/27.2.12479018/toolchains/llvm/prebuilt/$ndk_host/bin/clang" +echo "Faceclaw development tools verified."