Newer
Older
{
description = "The PrivateStorage Mobile application";
inputs = {
nixpkgs = {
url = "github:NixOS/nixpkgs?ref=nixos-22.05";
};
flake-utils.url = "github:numtide/flake-utils";
pypi-deps-db = {
flake = false;
url = "github:DavHau/pypi-deps-db";
};
mach-nix-flake = {
flake = true;
url = "github:DavHau/mach-nix";
inputs = {
nixpkgs.follows = "nixpkgs";
flake-utils.follows = "flake-utils";
pypi-deps-db.follows = "pypi-deps-db";
};
};
buildozerSrc = {
flake = false;
url = "github:PrivateStorageio/buildozer?ref=build-without-installing";
};
pythonForAndroidSrc = {
flake = false;
url = "github:PrivateStorageio/python-for-android?ref=work-on-nixos";
};
};
outputs = { self, nixpkgs, flake-utils, mach-nix-flake, buildozerSrc, pythonForAndroidSrc, ... }:
flake-utils.lib.eachSystem [
"x86_64-linux"
] (system: let
mach-nix = mach-nix-flake.lib.${system};
config = {
allowUnfree = true;
android_sdk.accept_license = true;
};
lib = pkgs.lib;
python-for-android = mach-nix.buildPythonPackage {
src = pythonForAndroidSrc;
requirementsExtra = ''
sh>=1.10
'';
};
buildozer = mach-nix.buildPythonPackage {
src = buildozerSrc;
packagesExtra = [ ];
};
kivy-env = mach-nix.mkPython {
python = "python39";
requirements = ''
kivy
Pillow
cython
'';
packagesExtra = [ python-for-android buildozer ];
};
# THESE MUST AGREE WITH app/app/build.gradle
#
# If they do not you will get failures that look something like:
# FAILURE: Build failed with an exception.
#
# * What went wrong:
# Could not determine the dependencies of task ':app:compileReleaseJavaWithJavac'.
# > Failed to install the following SDK components:
# platforms;android-32 Android SDK Platform 32
# The SDK directory is not writable (/nix/store/46214a16f22rd7q8vkrhsa907ra0405l-androidsdk/libexec/android-sdk)
cmakeVersion = "3.10.2";
buildToolsVersion = "30.0.3";
# Check out pkgs/development/mobile/androidenv/repo.json for
# nixpkgs-supported versions.
ndkVersion = "23.0.7123448-rc1";
# Also includes ndk
androidComposition = pkgs.callPackage ./android.nix {
inherit cmakeVersion buildToolsVersion ndkVersion;
};
getBuildInputs = getInputs: xs: builtins.foldl' (accum: drv: (getInputs drv) ++ accum) [] xs;
chaquopy-env = mach-nix.mkPython {
python = "python39";
requirements = ''
chaquopy
'';
};
in {
packages.apk = pkgs.androidenv.buildApp {
name = "PrivateStorage Mobile";
src = ./app;
release = false;
platformVersions = [ "31" ];
includeNDK = false;
};
type = "app";
program = let
emulator = pkgs.androidenv.emulateApp {
name = "PrivateStorage Mobile";
abiVersion = "x86_64";
systemImageType = "default";
Jean-Paul Calderone
committed
app = self.packages.${system}.apk;
package = "MyApp";
activity = "MainActivity";
};
in
"${emulator}/bin/run-test-emulator";
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
};
devShells.gradle = pkgs.mkShell rec {
name = "nix-native";
version = "2022.11.09";
ANDROIDSDK = "${androidComposition.androidsdk}/libexec/android-sdk";
ANDROIDNDK = "${ANDROIDSDK}/ndk-bundle";
buildInputs = with pkgs; [
# XXXX
# gradle finds an aapk2 from some random tgz it downloads from internet instead of from our ANDROIDSDK! GREAT!!!!!!!!!!11111
#
# Fix the one it downloads, if it didn't already root you, with:
#
# patchelf --set-interpreter <correct ld.so> ~/.gradle/<...path to aapt2>
gradle
ant
# openjdk8
android-studio
android-tools
python39
];
};
devShells.default = self.devShells.${system}.gradle;
# https://github.com/NixOS/nixpkgs/blob/master/doc/languages-frameworks/android.section.md
# is a good reference for this stuff.
devShells.kivy = pkgs.mkShell rec {
name = "ps-mobile";
version = "2022.10.21";
# The docs talk about ANDROID_SDK_ROOT but apparently it has been
# renamed yet again.
ANDROIDSDK = "${androidComposition.androidsdk}/libexec/android-sdk";
ANDROIDNDK = "${ANDROIDSDK}/ndk-bundle";
shellHook = ''
export PATH="$(echo "$ANDROIDSDK/cmake/${cmakeVersion}".*/bin):$PATH"
'';
buildInputs = with pkgs; [
android-studio
kivy-env
# https://github.com/kivy/python-for-android/blob/v2020.04.29/doc/source/troubleshooting.rst#errors-related-to-java-version
openjdk8
Jean-Paul Calderone
committed
# python-for-android recipes all want to download and unpack their
# own sources! aaaaaa
unzip
] ++
# Also we need build dependencies for all of the things it is going to
# build!
(getBuildInputs (drv: drv.buildInputs) [ openssl libffi python39 ]);
nativeBuildInputs =
with pkgs; getBuildInputs (drv: drv.nativeBuildInputs) [ openssl libffi python39 ];