~f4814n/frost

cbd50323ee6c116e36d324ba2435aa97bfea8f9d — Fabian Geiselhart 4 months ago 11a4a65
improve flake
5 files changed, 167 insertions(+), 57 deletions(-)

M flake.lock
M flake.nix
A nix/frost-android.nix
A nix/frost-web.nix
A nix/frost.nix
M flake.lock => flake.lock +4 -4
@@ 33,10 33,10 @@
    },
    "nixpkgs": {
      "locked": {
        "lastModified": 1604243500,
        "narHash": "sha256-uu/BxxaeLiAWAbf4P8vrfJzPyKdhnlpUMuViBcXjsHQ=",
        "path": "/nix/store/s6kwb1d0qq7m69p08h6c0iqjm3izhhxm-source",
        "rev": "1c50dc407cfc4ed42cf753d2e41499842288d1d8",
        "lastModified": 1608632382,
        "narHash": "sha256-5Fr6LQtp9/IuW1vtSdYBMLs8jZsPvdIeLfjsqGMxIUc=",
        "path": "/nix/store/882pbw3vmqn8fnk4rmcky023372v346v-source",
        "rev": "bf05444d01eae9ac965d90bcbead661f29a28c74",
        "type": "path"
      },
      "original": {

M flake.nix => flake.nix +78 -53
@@ 11,66 11,91 @@
  };

  outputs = { self, nixpkgs, flake-utils, ... }:
    let
      devShell = with import nixpkgs { system = "x86_64-linux"; config = { android_sdk.accept_license = true; }; }; {
        devShell."x86_64-linux" = let
    flake-utils.lib.eachSystem [ "x86_64-linux" "aarch64-linux" "i686-linux" "x86_64-darwin" "x86_64-windows" ] (system:
      let
        hasSystem = nixpkgs.lib.lists.any (s: s == system);
        pkgs = import nixpkgs {
          system = system;
          config = {
            allowUnfree = true;
            android_sdk.accept_license = true;
          };
          # Fix xcode hash problems
          overlays = [
            (final: prev: let 
              xcode = prev.requireFile {
                name = "Xcode.app";
                hashMode = "recursive";
                sha256 = "1ydwkl8jxhsb5v10ym6zd06bhbzx911281148qnnrsh9hwvrlwgz";
                message = "nop";
              };
            in {
              darwin = prev.darwin // {
                xcode_10_3 = xcode;
                xcode = xcode;
              };
            })
          ];
        };
      in with pkgs; {
        devShell = let
          android = androidenv.composeAndroidPackages{
            platformVersions = [ "28" ];
            abiVersions = [ "arm64" ];
            abiVersions =  [ "arm64" ];
            includeNDK = true;
            includeEmulator = true;
            includeEmulator = !hasSystem [ "x86_64-darwin" ];
          };
        in mkShell {
          buildInputs = [
            android.androidsdk
            openjdk
            nixfmt
            go
            goimports
            gopls
            golangci-lint
            delve
            pkgconfig
            x11
            wayland
            libxkbcommon
            libGL
            graphviz
            olm
            xorg.libXcursor
            xorg.libXfixes
          ];
          in mkShell {
            buildInputs = [
              # nix stuff
              nixfmt

              # go
              go goimports gopls golangci-lint graphviz

              # Library dependencies
              olm
            ] ++ (
              # Only pull xorg and wayland on linux
              if hasSystem [ "x86_64-linux" "aarch64-linux" "i686-linux" ] 
              then [ x11 wayland libxkbcommon libGL xorg.libXcursor xorg.libXfixes ]

              # Only pull android on supported platforms
              else if !hasSystem [ "aarch64-linux" "i686-linux" ] 
              then [ android.androidsdk openjdk ]

              else if !hasSystem [ "aarch64-linux" ]
              then [ delve ]
              else []
            );
          shellHook = ''
            export GOPATH=~/.cache/gopath
            export PATH=$(go env GOPATH)/bin:${android.androidsdk}/libexec/android-sdk/build-tools/28.0.3:$PATH
            export ANDROID_SDK_ROOT=${android.androidsdk}/libexec/android-sdk
            export PATH=$(go env GOPATH)/bin:$PATH

            ${if !hasSystem [ "aarch64-linux" "i686-linux" ]
            then ''
              export PATH=${android.androidsdk}/libexec/android-sdk/build-tools/28.0.3:$PATH
              export ANDROID_SDK_ROOT=${android.androidsdk}/libexec/android-sdk
            ''
            else ""}
          '';
        };
      };
          };

      default = {
        name = "frost";
        src = self;
        subPackages = [ "./cmd/frost" ];
        vendorSha256 = "seuYxvDoTzGOBYiYZJMWuLS/W0hv2wwgp+oIeyXgoPg=";
      };
          packages = let
            pname = "frost";
            version = "0.0.0";
            vendorSha256 = "/4dUpvfJJPGYD4bsJGemxE7vpLG1Hj8RIpbR0QfQK3A=";
          in {
            frost = callPackage ./nix/frost.nix { inherit pname version vendorSha256; crypto = true; };

            frost-web = callPackage ./nix/frost-web.nix { inherit pname version vendorSha256; crypto = false; };

            frost-android = callPackage ./nix/frost-android.nix { inherit pname version vendorSha256; crypto = false; };
          };

      linuxPackages = flake-utils.lib.eachSystem [
        "x86_64-linux"
        "aarch64-linux"
        "i686-linux"
      ] (system:
        with import nixpkgs { system = system; };
        let
          frost = buildGoModule (default // {
            nativeBuildInputs = [ pkgconfig ];
            buildInputs = [ libGL wayland x11 libxkbcommon ];
          });
        in {
          packages.frost = frost;
          apps.frost = flake-utils.lib.mkApp { drv = frost; };
          defaultPackage = frost;
          defaultApp = flake-utils.lib.mkApp { drv = frost; };
        });
    in devShell // linuxPackages;
          defaultPackage = self.packages.${system}.frost;
          apps.frost = flake-utils.lib.mkApp { drv = self.packages.frost; };
          defaultApp = flake-utils.lib.mkApp { drv = self.packages.frost; };
        }
    );
}

A nix/frost-android.nix => nix/frost-android.nix +38 -0
@@ 0,0 1,38 @@
{
  buildGoModule, androidenv, openjdk, olm,
  pname, version, vendorSha256,
  crypto ? true,
}:

let
  androidsdk = (androidenv.composeAndroidPackages {
      platformVersions = [ "28" ];
      abiVersions = [ "arm64" ];
      includeNDK = true;
  }).androidsdk;
in buildGoModule {
  inherit version vendorSha256;

  pname = "${pname}-apk";

  src = ./..;

  nativeBuildInputs = [ openjdk androidsdk olm ];

  buildInputs = [ olm openjdk androidsdk ];

  buildPhase = ''
    runHook preBuild
    export CFLAGS=$NIX_CFLAGS_COMPILE
    export ANDROID_SDK_ROOT=${androidsdk}/libexec/android-sdk
    go run gioui.org/cmd/gogio -target android ${if !crypto then "-tags nocrypto" else ""} -appid de.f4814n.frost ./cmd/frost
  '';

  doCheck = false;
  dontFixup = true;

  installPhase = ''
    mkdir -p $out
    mv frost.apk $out
  '';
}

A nix/frost-web.nix => nix/frost-web.nix +27 -0
@@ 0,0 1,27 @@
{ buildGoModule, 
  version, pname, vendorSha256,
  crypto ? true,
}:

buildGoModule {
  inherit version vendorSha256;
  pname = "${pname}-web";

  src = ./..;

  allowGoReference = true;

  buildPhase = ''
    runHook preBuild
    go run gioui.org/cmd/gogio -target js ${if !crypto then "-tags nocrypto" else ""} -o frost ./cmd/frost
  '';

  doCheck = false;

  dontFixup = true;

  installPhase = ''
    mkdir -p $out
    mv frost/* $out
  '';
}

A nix/frost.nix => nix/frost.nix +20 -0
@@ 0,0 1,20 @@
{ stdenv, buildGoModule, 
  pkgconfig, olm, libGL, wayland, x11, libxkbcommon, xorg,
  pname, version, vendorSha256, crypto ? true,
}:

with stdenv.lib;

buildGoModule {
  inherit pname version vendorSha256;

  src = ./..;

  subPackages = [ "./cmd/frost" ];

  nativeBuildInputs = [ pkgconfig ];

  buildInputs = [ olm ] ++ optionals stdenv.isLinux [ libGL wayland x11 libxkbcommon xorg.libXcursor xorg.libXfixes ];

  buildFlags = if !crypto then [ "-tags" "nocrypto" ] else [];
}