Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Nixpkgs Format release.nix #806

Draft
wants to merge 2 commits into
base: nixpkgs-unstable
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 30 additions & 29 deletions android/AndroidManifest.xml.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,34 @@
}:
let
boolStr = x: if x then "true" else "false";
in ''
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="${applicationId}"
android:versionCode="${version.code}"
android:versionName="${version.name}">
<application android:label="@string/app_name"
android:icon="${iconPath}"
android:allowBackup="${boolStr allowBackup}"
android:fullBackupContent="${boolStr fullBackupContent}"
android:hardwareAccelerated="true"
android:usesCleartextTraffic="${boolStr usesCleartextTraffic}">
<activity android:name="systems.obsidian.HaskellActivity"
android:label="@string/app_name"
android:configChanges="orientation|screenSize"
android:windowSoftInputMode="adjustResize"
${activityAttributes}
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
${intentFilters}
</activity>
${services}
</application>
<uses-permission android:name="android.permission.INTERNET" />
${permissions}
</manifest>
in
''
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="${applicationId}"
android:versionCode="${version.code}"
android:versionName="${version.name}">
<application android:label="@string/app_name"
android:icon="${iconPath}"
android:allowBackup="${boolStr allowBackup}"
android:fullBackupContent="${boolStr fullBackupContent}"
android:hardwareAccelerated="true"
android:usesCleartextTraffic="${boolStr usesCleartextTraffic}">
<activity android:name="systems.obsidian.HaskellActivity"
android:label="@string/app_name"
android:configChanges="orientation|screenSize"
android:windowSoftInputMode="adjustResize"
${activityAttributes}
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
${intentFilters}
</activity>
${services}
</application>
<uses-permission android:name="android.permission.INTERNET" />
${permissions}
</manifest>
''
2 changes: 1 addition & 1 deletion android/Application.mk.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
, abiVersions
}:
''
APP_ABI := ${nixpkgs.lib.concatStringsSep " " abiVersions}
APP_ABI := ${nixpkgs.lib.concatStringsSep " " abiVersions}
''
118 changes: 76 additions & 42 deletions android/build-gradle-app.nix
Original file line number Diff line number Diff line change
@@ -1,13 +1,35 @@
{ stdenv, lib, androidenv, jdk, gnumake, gawk, file
, which, gradle, fetchurl, buildEnv, runCommand }:
{ stdenv
, lib
, androidenv
, jdk
, gnumake
, gawk
, file
, which
, gradle
, fetchurl
, buildEnv
, runCommand
}:

args@{ name, src, platformVersions ? [ "8" ]
, buildToolsVersions ? [ "30.0.2" ]
, useGoogleAPIs ? false, useGooglePlayServices ? false
, release ? false, keyStore ? null, keyAlias ? null
, keyStorePassword ? null, keyAliasPassword ? null
, useNDK ? false, buildInputs ? [], mavenDeps, gradleTask
, buildDirectory ? "./.", acceptAndroidSdkLicenses ? false }:
args@{ name
, src
, platformVersions ? [ "8" ]
, buildToolsVersions ? [ "30.0.2" ]
, useGoogleAPIs ? false
, useGooglePlayServices ? false
, release ? false
, keyStore ? null
, keyAlias ? null
, keyStorePassword ? null
, keyAliasPassword ? null
, useNDK ? false
, buildInputs ? [ ]
, mavenDeps
, gradleTask
, buildDirectory ? "./."
, acceptAndroidSdkLicenses ? false
}:

assert release -> keyStore != null;
assert release -> keyAlias != null;
Expand All @@ -18,34 +40,45 @@ assert acceptAndroidSdkLicenses;
let
inherit (lib) optionalString optional;

m2install = { repo, version, artifactId, groupId
, jarSha256, pomSha256, aarSha256, suffix ? ""
, customJarUrl ? null, customJarSuffix ? null }:
let m2Name = "${artifactId}-${version}";
m2Path = "${builtins.replaceStrings ["."] ["/"] groupId}/${artifactId}/${version}";
jarFile = fetchurl {
url = if customJarUrl != null then customJarUrl else "${repo}${m2Path}/${m2Name}${suffix}.jar";
sha256 = jarSha256;
};
in runCommand m2Name {} (''
installPath="$out"/m2/'${m2Path}'
mkdir -p "$installPath"
'' + optionalString (jarSha256 != null) ''
install -D '${jarFile}' "$installPath"/'${m2Name}${suffix}.jar'
${optionalString (customJarSuffix != null) ''
install -D '${jarFile}' "$installPath"/'${m2Name}${suffix}${customJarSuffix}.jar'
''}
'' + optionalString (pomSha256 != null) ''
install -D ${fetchurl {
url = "${repo}${m2Path}/${m2Name}${suffix}.pom";
sha256 = pomSha256;
}} "$installPath/${m2Name}${suffix}.pom"
'' + optionalString (aarSha256 != null) ''
install -D ${fetchurl {
url = "${repo}${m2Path}/${m2Name}${suffix}.aar";
sha256 = aarSha256;
}} "$installPath/${m2Name}${suffix}.aar"
'');
m2install =
{ repo
, version
, artifactId
, groupId
, jarSha256
, pomSha256
, aarSha256
, suffix ? ""
, customJarUrl ? null
, customJarSuffix ? null
}:
let
m2Name = "${artifactId}-${version}";
m2Path = "${builtins.replaceStrings ["."] ["/"] groupId}/${artifactId}/${version}";
jarFile = fetchurl {
url = if customJarUrl != null then customJarUrl else "${repo}${m2Path}/${m2Name}${suffix}.jar";
sha256 = jarSha256;
};
in
runCommand m2Name { } (''
installPath="$out"/m2/'${m2Path}'
mkdir -p "$installPath"
'' + optionalString (jarSha256 != null) ''
install -D '${jarFile}' "$installPath"/'${m2Name}${suffix}.jar'
${optionalString (customJarSuffix != null) ''
install -D '${jarFile}' "$installPath"/'${m2Name}${suffix}${customJarSuffix}.jar'
''}
'' + optionalString (pomSha256 != null) ''
install -D ${fetchurl {
url = "${repo}${m2Path}/${m2Name}${suffix}.pom";
sha256 = pomSha256;
}} "$installPath/${m2Name}${suffix}.pom"
'' + optionalString (aarSha256 != null) ''
install -D ${fetchurl {
url = "${repo}${m2Path}/${m2Name}${suffix}.aar";
sha256 = aarSha256;
}} "$installPath/${m2Name}${suffix}.aar"
'');
androidsdkComposition = androidenv.composeAndroidPackages {
inherit platformVersions useGoogleAPIs buildToolsVersions;
includeNDK = true;
Expand All @@ -55,16 +88,17 @@ let
in
stdenv.mkDerivation ({
inherit src;
name = builtins.replaceStrings [" "] [""] args.name;
name = builtins.replaceStrings [ " " ] [ "" ] args.name;

ANDROID_HOME = "${androidsdkComposition.androidsdk}/libexec";
ANDROID_NDK_HOME = "${androidsdkComposition.ndk-bundle}/libexec/android-sdk/ndk-bundle";

buildInputs = [ jdk gradle ] ++ buildInputs ++ lib.optional useNDK [ androidsdkComposition.ndk-bundle gnumake gawk file which ];

DEPENDENCIES = buildEnv { name = "${name}-maven-deps";
paths = map m2install mavenDeps;
};
DEPENDENCIES = buildEnv {
name = "${name}-maven-deps";
paths = map m2install mavenDeps;
};

buildPhase = ''
${optionalString release ''
Expand Down Expand Up @@ -110,4 +144,4 @@ stdenv.mkDerivation ({
meta = {
license = lib.licenses.unfree;
};
} // builtins.removeAttrs args ["name" "mavenDeps"])
} // builtins.removeAttrs args [ "name" "mavenDeps" ])
Loading