Skip to content
Snippets Groups Projects
default.nix 3.85 KiB
Newer Older
{ system ? builtins.currentSystem
, nix-thunk ? import ./dep/nix-thunk {}
, obelisk ? import ./.obelisk/impl {
    inherit system;
    iosSdkVersion = "13.2";

    # Here we insert our own nixpkgs overlays. Since it's a bit awkward, a
    # future version of Obelisk will make this more straightforward (link?),
    # but for now, the way to do this is by modifying the reflex-platform
    # function to modify its nixpkgsOverlays argument.
    reflex-platform-func = (args: import (nix-thunk.thunkSource ./.obelisk/impl + "/dep/reflex-platform")
      (args // { nixpkgsOverlays = args.nixpkgsOverlays ++ [(import ./nixpkgs-overlay.nix { inherit nix-thunk; })]; } ) );

    # You must accept the Android Software Development Kit License Agreement at
    # https://developer.android.com/studio/terms in order to build Android apps.
    # Uncomment and set this to `true` to indicate your acceptance:
    config.android_sdk.accept_license = true;

    # In order to use Let's Encrypt for HTTPS deployments you must accept
    # their terms of service at https://letsencrypt.org/repository/.
    # Uncomment and set this to `true` to indicate your acceptance:
    # terms.security.acme.acceptTerms = false;
  }
}:
let
  p =
    with obelisk;
    project ./. ({ pkgs, ... }: {
      # Not using "storage.private" (our newer domain name) since that makes the build
      # fail: "[...] is not a valid Java package name as 'private' is a Java keyword."
      android.applicationId = "io.privatestorage.privatestoragemobile";
      android.displayName = "Private Storage Mobile";
      android.resources = ./frontend/android/res;
      android.iconPath = "@mipmap/ic_launcher";

      # This should work but even if it does, putting the config here removes
      # our ability to build apks.
      android.gradleTask = "bundleRelease";
      android.isRelease = true;

      # We use magic-wormhole which depends on saltine which depends on libsodium.
      # We have to explicitly mention libsodium here to get it included in the
      # apk.
      android.runtimeSharedLibs = nixpkgs: [
        "${nixpkgs.libsodium}/lib/libsodium.so"
      ];

      ios.bundleIdentifier = "systems.obsidian.obelisk.examples.minimal";
      ios.bundleName = "Obelisk Minimal Example";

      # Override some elements of the Haskell package set - get newer versions,
      # add custom libraries that aren't packaged upstream, etc.
      overrides = pkgs.callPackage ./haskell-overrides.nix {
        inherit nix-thunk;
      };

      shellToolOverrides = ghc: super: {
        inherit (ghc) haskell-language-server ghcid;
        nix-thunk = nix-thunk.command;
      };
    });

  inherit
    (import "${(builtins.fetchTarball https://github.com/masaeedu/nix-optics/archive/028b4e0f721d902aa97bc3535cb3d265bfc53abb.tar.gz)}/utils.nix")
    optics
    fn;

  makeReleaseBundle =
    let
      # Tell gradle to build the aab.
      fixGradle =
        with optics fn;
        path
          [ "android" "frontend" ]
          (super: super.override {
            # "assembleDebug" or "assembleRelease" to build a debug or release apk
            # (respectively) or "bundleRelease" to build a release bundle (aab).
            gradleTask = "bundleRelease";
            isRelease = true;
      # Change the final installation instructions to work with the aab we
      # built instead of an apk.
      fixInstall =
        with optics fn;
        path
          ["android" "frontend" "inputDerivation" "src"]
          (super: super.overrideAttrs (old: {
            installPhase = ''
              mkdir -p $out
              cp -RL build/outputs/bundle/*/*.aab $out
      fn.pipe [
        fixInstall
        fixGradle
      ];
  # Make sure we use the same nixpkgs here as we gave to obelisk /
  # reflex-platform above.
  inherit (obelisk) nixpkgs;
} // {
  releaseBundle = makeReleaseBundle p;