Skip to content
Snippets Groups Projects
flake.nix 3.22 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 ];
    
    
          cmakeVersion = "3.10.2";
    
          # Also includes ndk
          androidComposition = pkgs.callPackage ./android.nix { inherit cmakeVersion; };
    
    
          getBuildInputs = getInputs: xs: builtins.foldl' (accum: drv: (getInputs drv) ++ accum) [] xs;
    
          # https://github.com/NixOS/nixpkgs/blob/master/doc/languages-frameworks/android.section.md
          # is a good reference for this stuff.
          devShells.default = 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
    
    
              # 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 ];