# About This is a demo of using [Haskell](https://haskell.org), [Nix](https://nixos.org/) and [Miso](https://haskell-miso.org) to produce a [LynxJS](https://lynxjs.org) application for Android. The main interest about this demo is that everything is reproducibly built with Nix, including the building of the `.apk` with `gradle`. # Requirements - `nix` [installed](https://nixos.org/download/). - A host supporting the [Kernel Virtual Machine (KVM) hypervisor](https://developer.android.com/studio/run/emulator-acceleration) (and having it enabled in its BIOS), or and Android device in debug mode to install the `.apk`. # Usage ## For an Android emulator Running: ```console nix -L run git+https://radicle-mermet.sourcephile.fr/z2BeGZUdNCY3FzYarKMV7XXXuc5os.git#android-emulator-x86_64 ``` or alternatively (for hacking): ```console git clone https://radicle-mermet.sourcephile.fr/z2BeGZUdNCY3FzYarKMV7XXXuc5os.git haskell-miso-nix-demo && cd haskell-miso-nix-demo && nix -L run .#android-emulator-x86_64 ``` or alternatively (for [radicle](https://radicle.xyz) users): ```console rad clone z2BeGZUdNCY3FzYarKMV7XXXuc5os && cd haskell-miso-nix-demo && nix -L run .#android-emulator-x86_64 ``` should saturate your download link, fill you `/nix/store/`, produce a lot of heat and eventually spawn an Android emulator running a demo app where you can increase (resp. decrease) a counter by tapping on a cat 🐈 (resp. a ramen dish 🍜). __ResourceWarning:__ because the Haskell compiler (GHC) has to be patched (otherwise the buttons of the app do not work) and is not using the same `nixpkgs` as the ones on the public cache `haskell-miso-cachix.cachix.org`, this demo requires a lot of CPU cycles and memory space in `/tmp` to build that patched GHC. __ResourceWarning:__ besides part of it being in the `/nix/store/` the actual Android system remains in `/tmp/nix-android-user-home-*` after closing the emulator, since it weights several gibibits you may want to remove it before your next reboot. ## For an Android device ```console git clone https://radicle-mermet.sourcephile.fr/z2BeGZUdNCY3FzYarKMV7XXXuc5os.git haskell-miso-nix-demo && cd haskell-miso-nix-demo && nix -L build .#default && adb install result/app-debug.apk ``` __PortabilityNote:__ this demo targets the Android platform 34 which requires Android >= 14, and all main computer architectures should be supported: ```console $ aapt dump badging result/app-debug.apk | grep native-code native-code: 'arm64-v8a' 'armeabi-v7a' 'x86' 'x86_64' ``` # Acknowledgements - https://github.com/haskell-miso/miso-lynx provided the `counter` example. - https://github.com/lynx-family/integrating-lynx-demo-projects provided the `JavaEmptyProject`. # Hack Java dependencies in `android/deps.json` can be updated with: ```console nix -L run .#default.update-deps ``` Using `nix -L develop` registers the custom GHC to the host Nix's garbage-collector in `haskell/cache/gc-roots/ghcjs-ghc`, manually remove this symbolic link to let `nix-collect-garbage` reclaim it. ## ToDo - SecurityToDo: sign the APK.