Skip to content
Snippets Groups Projects
flake.nix 5.6 KiB
Newer Older
  • Learn to ignore specific revisions
  • {
      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};
    
    Jean-Paul Calderone's avatar
    Jean-Paul Calderone committed
          pkgs = import nixpkgs {
            inherit system;
    
            config = {
              allowUnfree = true;
              android_sdk.accept_license = true;
            };
    
    Jean-Paul Calderone's avatar
    Jean-Paul Calderone committed
          };
    
          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)
    
    
          buildToolsVersion = "30.0.3";
          # Check out pkgs/development/mobile/androidenv/repo.json for
          # nixpkgs-supported versions.
          ndkVersion = "23.0.7123448-rc1";
    
          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
            '';
          };
    
          packages.apk = pkgs.androidenv.buildApp {
    
            name = "PrivateStorage Mobile";
            src = ./app;
            release = false;
    
    
            platformVersions = [ "31" ];
    
          apps.emulate = {
    
            type = "app";
            program = let
              emulator = pkgs.androidenv.emulateApp {
                name = "PrivateStorage Mobile";
    
                platformVersion = "31";
    
                abiVersion = "x86_64";
                systemImageType = "default";
                app = ./app/app/build/outputs/apk/debug/app-debug.apk;
                package = "MyApp";
                activity = "MainActivity";
              };
            in
              "${emulator}/bin/emulate-it???";
          };
          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 {
    
            # 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 and python-for-android depend on:
    
    Jean-Paul Calderone's avatar
    Jean-Paul Calderone committed
              # https://github.com/kivy/python-for-android/blob/v2020.04.29/doc/source/troubleshooting.rst#errors-related-to-java-version
    
    
              # 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 ];