nix: Some minor fixes

This commit is contained in:
Pedro Pombeiro 2019-08-14 09:05:32 +02:00
parent b635691c25
commit ff721ba1bf
No known key found for this signature in database
GPG Key ID: C4A24185B2AA48A1
8 changed files with 51 additions and 106 deletions

3
.gitignore vendored
View File

@ -32,12 +32,15 @@ project.xcworkspace
.gradle .gradle
*.iml *.iml
**/android/.project **/android/.project
**/android/.settings/org.eclipse.buildship.core.prefs
local.properties
# Atom # Atom
.tags* .tags*
# VS Code # VS Code
.vscode/ipch/ .vscode/ipch/
.vscode/settings.json
# node.js # node.js
# #

View File

@ -68,7 +68,6 @@ nix-update-npm: export TARGET_OS := none
nix-update-npm: ##@nix Update node2nix expressions based on current package.json nix-update-npm: ##@nix Update node2nix expressions based on current package.json
nix/desktop/realm-node/generate-nix.sh nix/desktop/realm-node/generate-nix.sh
nix-update-gradle: export TARGET_OS := android
nix-update-gradle: ##@nix Update maven nix expressions based on current gradle setup nix-update-gradle: ##@nix Update maven nix expressions based on current gradle setup
nix/mobile/android/maven-and-npm-deps/maven/generate-nix.sh nix/mobile/android/maven-and-npm-deps/maven/generate-nix.sh
@ -113,12 +112,14 @@ release: release-android release-ios ##@build build release for Android and iOS
release-android: export TARGET_OS ?= android release-android: export TARGET_OS ?= android
release-android: export BUILD_ENV ?= prod release-android: export BUILD_ENV ?= prod
release-android: export BUILD_TYPE ?= nightly release-android: export BUILD_TYPE ?= nightly
release-android: export BUILD_NUMBER ?= 9999
release-android: export NDK_ABI_FILTERS ?= armeabi-v7a;arm64-v8a;x86 release-android: export NDK_ABI_FILTERS ?= armeabi-v7a;arm64-v8a;x86
release-android: export STORE_FILE ?= ~/.gradle/status-im.keystore release-android: export STORE_FILE ?= ~/.gradle/status-im.keystore
release-android: ##@build build release for Android release-android: ##@build build release for Android
nix/build.sh targets.mobile.$(TARGET_OS).release \ nix/build.sh targets.mobile.$(TARGET_OS).release \
--arg env '{NDK_ABI_FILTERS="$(NDK_ABI_FILTERS)";}' \ --arg env '{NDK_ABI_FILTERS="$(NDK_ABI_FILTERS)";}' \
--argstr build-type $(BUILD_TYPE) \ --argstr build-type $(BUILD_TYPE) \
--argstr build-number $(BUILD_NUMBER) \
--argstr keystore-file $(STORE_FILE) \ --argstr keystore-file $(STORE_FILE) \
--option extra-sandbox-paths $(STORE_FILE) --option extra-sandbox-paths $(STORE_FILE)

View File

@ -53,7 +53,7 @@ for path in ${drvPaths}; do
toDelete+=("${drv}" "${src}") toDelete+=("${drv}" "${src}")
done done
# remove dupicates # remove duplicates
cleanToDelete=$(echo "${toDelete[@]}" | sort | uniq) cleanToDelete=$(echo "${toDelete[@]}" | sort | uniq)
echo "Deleting..." echo "Deleting..."

View File

@ -1,4 +1,4 @@
{ config, stdenv, stdenvNoCC, target-os, callPackage, mkShell, { config, stdenv, stdenvNoCC, target-os ? "android", callPackage, mkShell,
mkFilter, androidenv, fetchurl, openjdk, nodejs, bash, maven, zlib, mkFilter, androidenv, fetchurl, openjdk, nodejs, bash, maven, zlib,
status-go, localMavenRepoBuilder, projectNodePackage, jsbundle }: status-go, localMavenRepoBuilder, projectNodePackage, jsbundle }:

View File

@ -25,7 +25,7 @@ let
deps = deps =
let let
# Place build target directories in NIX_BUILD_TOP (normally represents /build) # Place build target directories in NIX_BUILD_TOP (normally represents /build)
projectDir = "$NIX_BUILD_TOP/project"; projectBuildDir = "$NIX_BUILD_TOP/project";
mavenRepoDir = "$NIX_BUILD_TOP/.m2/repository"; mavenRepoDir = "$NIX_BUILD_TOP/.m2/repository";
reactNativeMavenPackageDir = "${mavenRepoDir}/com/facebook/react/react-native"; # This is directory where the react-native Maven package will be generated in reactNativeMavenPackageDir = "${mavenRepoDir}/com/facebook/react/react-native"; # This is directory where the react-native Maven package will be generated in
reactNativeDepsDir = "$NIX_BUILD_TOP/deps"; # Use local writable deps, otherwise (probably due to some interaction between Nix sandboxing and Java) gradle will fail copying directly from the nix store reactNativeDepsDir = "$NIX_BUILD_TOP/deps"; # Use local writable deps, otherwise (probably due to some interaction between Nix sandboxing and Java) gradle will fail copying directly from the nix store
@ -57,10 +57,10 @@ let
runHook preUnpack runHook preUnpack
# Copy project directory # Copy project directory
mkdir -p ${projectDir} mkdir -p ${projectBuildDir}
cp -a $src/. ${projectDir} cp -a $src/. ${projectBuildDir}
chmod u+w ${projectDir} chmod u+w ${projectBuildDir}
cd ${projectDir} cd ${projectBuildDir}
# Copy RN maven dependencies and make them writable, otherwise Gradle copy fails (since the top-level directory is read-only, Java isn't smart enough to copy the child files/folders into that target directory) # Copy RN maven dependencies and make them writable, otherwise Gradle copy fails (since the top-level directory is read-only, Java isn't smart enough to copy the child files/folders into that target directory)
mkdir -p ${mavenRepoDir} mkdir -p ${mavenRepoDir}
@ -73,21 +73,21 @@ let
done done
# Copy node_modules from Nix store # Copy node_modules from Nix store
rm -rf ${projectDir}/node_modules rm -rf ${projectBuildDir}/node_modules
mkdir -p ${projectDir}/node_modules mkdir -p ${projectBuildDir}/node_modules
cp -a ${projectNodePackage}/node_modules/. ${projectDir}/node_modules/ cp -a ${projectNodePackage}/node_modules/. ${projectBuildDir}/node_modules/
# Adjust permissions # Adjust permissions
chmod -R u+w ${projectDir} chmod -R u+w ${projectBuildDir}
cp -R ${projectDir}/status-modules/ ${projectDir}/node_modules/status-modules/ cp -R ${projectBuildDir}/status-modules/ ${projectBuildDir}/node_modules/status-modules/
cp -R ${projectDir}/translations/ ${projectDir}/node_modules/status-modules/translations/ cp -R ${projectBuildDir}/translations/ ${projectBuildDir}/node_modules/status-modules/translations/
# Set up symlinks to mobile enviroment in project root # Set up symlinks to mobile enviroment in project root
${createMobileFilesSymlinks projectDir} ${createMobileFilesSymlinks projectBuildDir}
# Create a dummy VERSION, since we don't want this expression to be invalidated just because the version changed # Create a dummy VERSION, since we don't want this expression to be invalidated just because the version changed
echo '0.0.1' > ${projectDir}/VERSION echo '0.0.1' > ${projectBuildDir}/VERSION
runHook postUnpack runHook postUnpack
''; '';
@ -97,7 +97,7 @@ let
prevSet=$- prevSet=$-
set -e set -e
patchShebangs ${projectDir} patchShebangs ${projectBuildDir}
function patchMavenSource() { function patchMavenSource() {
set +e set +e
@ -125,28 +125,34 @@ let
# Patch maven and google central repositories with our own local directories. This prevents the builder from downloading Maven artifacts # Patch maven and google central repositories with our own local directories. This prevents the builder from downloading Maven artifacts
patchMavenSources 'android/build.gradle' '${mavenLocalRepo}' patchMavenSources 'android/build.gradle' '${mavenLocalRepo}'
for f in `find ${projectDir}/node_modules/ -name build.gradle`; do for f in `find ${projectBuildDir}/node_modules/ -name build.gradle`; do
patchMavenSources $f '${mavenLocalRepo}' patchMavenSources $f '${mavenLocalRepo}'
done done
# Patch prepareJSC so that it doesn't try to download from registry # Patch prepareJSC so that it doesn't try to download from registry
substituteInPlace ${projectDir}/node_modules/react-native/ReactAndroid/build.gradle \ substituteInPlace ${projectBuildDir}/node_modules/react-native/ReactAndroid/build.gradle \
--replace 'prepareJSC(dependsOn: downloadJSC)' 'prepareJSC(dependsOn: createNativeDepsDirectories)' \ --replace 'prepareJSC(dependsOn: downloadJSC)' 'prepareJSC(dependsOn: createNativeDepsDirectories)' \
--replace 'def jscTar = tarTree(downloadJSC.dest)' "def jscTar = tarTree(new File(\"${react-native-deps}/deps/${jsc-filename}.tar.gz\"))" --replace 'def jscTar = tarTree(downloadJSC.dest)' "def jscTar = tarTree(new File(\"${react-native-deps}/deps/${jsc-filename}.tar.gz\"))"
# Do not add a BuildId to the generated libraries, for reproducibility # Do not add a BuildId to the generated libraries, for reproducibility
substituteInPlace ${projectDir}/node_modules/react-native/ReactAndroid/src/main/jni/Application.mk \ substituteInPlace ${projectBuildDir}/node_modules/react-native/ReactAndroid/src/main/jni/Application.mk \
--replace '-Wl,--build-id' '-Wl,--build-id=none' --replace \
'-Wl,--build-id' \
'-Wl,--build-id=none'
# Disable Gradle daemon and caching, since that causes rebuilds (and subsequently errors) anyway due to cache being considered stale # Disable Gradle daemon and caching, since that causes rebuilds (and subsequently errors) anyway due to cache being considered stale
substituteInPlace ${projectDir}/android/gradle.properties \ substituteInPlace ${projectBuildDir}/android/gradle.properties \
--replace 'org.gradle.jvmargs=-Xmx8704M' 'org.gradle.jvmargs=-Xmx8704M --replace \
'org.gradle.jvmargs=-Xmx8704M' \
'org.gradle.jvmargs=-Xmx8704M
org.gradle.daemon=false org.gradle.daemon=false
org.gradle.caching=false' org.gradle.caching=false'
# Patch the path to nodejs in project.ext.react # Patch the path to nodejs in project.ext.react
substituteInPlace ${projectDir}/android/app/build.gradle \ substituteInPlace ${projectBuildDir}/android/app/build.gradle \
--replace 'nodeExecutableAndArgs: ["node"' 'nodeExecutableAndArgs: ["${nodejs}/bin/node"' --replace \
'nodeExecutableAndArgs: ["node"' \
'nodeExecutableAndArgs: ["${nodejs}/bin/node"'
set $prevSet set $prevSet
@ -157,9 +163,9 @@ let
status-go.shellHook + '' status-go.shellHook + ''
export HOME=$NIX_BUILD_TOP export HOME=$NIX_BUILD_TOP
export REACT_NATIVE_DEPENDENCIES="${reactNativeDepsDir}" export REACT_NATIVE_DEPENDENCIES="${reactNativeDepsDir}"
export STATUS_REACT_HOME="${projectDir}" export STATUS_REACT_HOME="${projectBuildDir}"
pushd ${projectDir}/android pushd ${projectBuildDir}/android
# NOTE: This generates the react-native-android binaries under node_modules/react-native/android # NOTE: This generates the react-native-android binaries under node_modules/react-native/android
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${lib.makeLibraryPath [ zlib ]} \ LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${lib.makeLibraryPath [ zlib ]} \
gradle -Dmaven.repo.local=${mavenRepoDir} --offline -S react-native-android:installArchives || exit gradle -Dmaven.repo.local=${mavenRepoDir} --offline -S react-native-android:installArchives || exit
@ -168,24 +174,26 @@ let
doCheck = true; doCheck = true;
checkPhase = '' checkPhase = ''
runHook preCheck runHook preCheck
test -d ${projectDir}/node_modules/react-native/ReactAndroid/build/intermediates/javac/release/compileReleaseJavaWithJavac/classes/com/facebook || \ test -d ${projectBuildDir}/node_modules/react-native/ReactAndroid/build/intermediates/javac/release/compileReleaseJavaWithJavac/classes/com/facebook || \
exit 1 exit 1
test -d ${projectDir}/node_modules/react-native/ReactAndroid/build/react-ndk/exported || \ test -d ${projectBuildDir}/node_modules/react-native/ReactAndroid/build/react-ndk/exported || \
exit 2 exit 2
runHook postCheck runHook postCheck
''; '';
installPhase = '' installPhase = ''
rm -rf $out rm -rf $out
mkdir -p $out/project $out/.m2/repository mkdir -p $out/{project,.m2/repository}
# TODO: maybe node_modules/react-native/ReactAndroid/build/{tmp,generated} can be discarded? # TODO: maybe node_modules/react-native/ReactAndroid/build/{tmp,generated} can be discarded?
cp -R ${mavenRepoDir} $out/.m2/ cp -R ${mavenRepoDir} $out/.m2/
cp -R ${projectDir}/android/ ${projectDir}/node_modules/ $out/project cp -R ${projectBuildDir}/{android,node_modules}/ $out/project
''; '';
fixupPhase = '' fixupPhase = ''
# Patch prepareJSC so that it doesn't subsequently try to build NDK libs # Patch prepareJSC so that it doesn't subsequently try to build NDK libs
substituteInPlace $out/project/node_modules/react-native/ReactAndroid/build.gradle \ substituteInPlace $out/project/node_modules/react-native/ReactAndroid/build.gradle \
--replace 'packageReactNdkLibs(dependsOn: buildReactNdkLib, ' 'packageReactNdkLibs(' --replace \
'packageReactNdkLibs(dependsOn: buildReactNdkLib, ' \
'packageReactNdkLibs('
''; '';
# The ELF types are incompatible with the host platform, so let's not even try # The ELF types are incompatible with the host platform, so let's not even try

View File

@ -3,8 +3,8 @@
androidEnvShellHook, mavenAndNpmDeps, androidEnvShellHook, mavenAndNpmDeps,
nodejs, openjdk, jsbundle, status-go, zlib }: nodejs, openjdk, jsbundle, status-go, zlib }:
{ build-number ? "9999", { build-number,
build-type ? "nightly", # Build type (e.g. nightly, release, e2e). Default is to use .env.nightly file build-type, # Build type (e.g. nightly, release, e2e). Default is to use .env.nightly file
gradle-opts ? "", gradle-opts ? "",
keystore-file ? "", # Path to the .keystore file used to sign the package keystore-file ? "", # Path to the .keystore file used to sign the package
secrets-file ? "", # Path to the file containing secret environment variables secrets-file ? "", # Path to the file containing secret environment variables
@ -83,9 +83,9 @@ in stdenv.mkDerivation {
set -e set -e
substituteInPlace android/gradlew \ substituteInPlace android/gradlew \
--replace 'exec gradle' "exec gradle -S -Dmaven.repo.local='${localMavenRepo}' --offline ${gradle-opts}" --replace \
substituteInPlace android/gradle.properties \ 'exec gradle' \
--replace 'versionCode=9999' 'versionCode=${build-number}' "exec gradle -Dmaven.repo.local='${localMavenRepo}' --offline ${gradle-opts}"
# OPTIONAL: There's no need to forward debug ports for a release build, just disable it # OPTIONAL: There's no need to forward debug ports for a release build, just disable it
substituteInPlace node_modules/realm/android/build.gradle \ substituteInPlace node_modules/realm/android/build.gradle \
@ -113,7 +113,7 @@ in stdenv.mkDerivation {
${concatStrings (catAttrs "shellHook" [ mavenAndNpmDeps status-go ])} ${concatStrings (catAttrs "shellHook" [ mavenAndNpmDeps status-go ])}
pushd android pushd android
${adhocEnvVars} gradle assemble${capitalizedBuildType} -S -Dmaven.repo.local='${localMavenRepo}' --offline ${gradle-opts} || exit ${adhocEnvVars} ./gradlew -PversionCode=${build-number} assemble${capitalizedBuildType} || exit
popd > /dev/null popd > /dev/null
${unsetEnvVars} ${unsetEnvVars}

View File

@ -47,7 +47,7 @@ fi
if [[ "$TARGET_OS" =~ (linux|windows|darwin|macos) ]]; then if [[ "$TARGET_OS" =~ (linux|windows|darwin|macos) ]]; then
# This is a dirty workaround because 'yarn install' is an impure operation, # This is a dirty workaround because 'yarn install' is an impure operation,
# so we need to call it from an impure shell. # so we need to call it from an impure shell.
# Hopefull we'll be able to fix this later on with something like yarn2nix # Hopefully we'll be able to fix this later on with something like yarn2nix
nix-shell ${shellArgs[@]} --run "scripts/prepare-for-desktop-platform.sh" || exit nix-shell ${shellArgs[@]} --run "scripts/prepare-for-desktop-platform.sh" || exit
fi fi

View File

@ -1,67 +0,0 @@
#!/usr/bin/env bash
set -Eeo pipefail
GIT_ROOT=$(cd "${BASH_SOURCE%/*}" && git rev-parse --show-toplevel)
CURRENT_DIR="$( cd "$( dirname "$0" )" && pwd )"
. "$CURRENT_DIR/lib/setup/path-support.sh"
source_lib "properties.sh"
source_lib "platform.sh"
STORE_FILE=$(property_gradle 'STATUS_RELEASE_STORE_FILE')
STORE_FILE="${STORE_FILE/#\~/$HOME}"
function cleanup() {
trap - EXIT ERR INT QUIT
if [ -n "$nixResultPath" ]; then
echo "Deleting derivations from Nix store..."
. ~/.nix-profile/etc/profile.d/nix.sh
releaseDrv=$(nix-instantiate --quiet $nixOpts)
if [ -n "$releaseDrv" ]; then
local releaseSrcPath=$(nix-store -q --binding src $releaseDrv)
local releaseOutPath=$(nix-store -q --outputs $releaseDrv)
local releaseRefs=( $(nix-store -q --references $releaseDrv) )
local prodBuildDrv=$(printf -- '%s\n' "${releaseRefs[@]}" | grep -e "jsbundle-android.drv")
local prodBuildSrcPath=$(nix-store -q --binding src $prodBuildDrv)
local prodBuildOutPath=$(nix-store -q --outputs $prodBuildDrv)
nix-store --delete $prodBuildDrv $prodBuildSrcPath $prodBuildOutPath $releaseDrv $releaseSrcPath $releaseOutPath 2> /dev/null
fi
fi
}
trap "cleanup" EXIT ERR INT QUIT
[ -z "$BUILD_TYPE" ] && BUILD_TYPE='nightly'
exportedEnv=()
if [ -n "$NDK_ABI_FILTERS" ]; then
exportedEnv+=( "NDK_ABI_FILTERS=''${NDK_ABI_FILTERS}'';" ) # NOTE: Do not include spaces in the Nix attribute set, otherwise it'll create issues with automatic bash quoting
fi
exportedEnvFlag=''
if [ ${#exportedEnv[@]} -ne 0 ]; then
exportedEnvFlag="--arg env {${exportedEnv[@]}}"
fi
nixOpts="--option extra-sandbox-paths ${STORE_FILE} \
--argstr target-os ${TARGET_OS} \
--argstr build-type ${BUILD_TYPE} \
--argstr keystore-file ${STORE_FILE} \
--show-trace \
${exportedEnvFlag} \
-A targets.mobile.${TARGET_OS}.release"
# Run the build
outType='release'
if [ "$BUILD_TYPE" != "release" ] && [ "$BUILD_TYPE" != "nightly" ]; then
outType="pr"
fi
nixResultPath=$(. ~/.nix-profile/etc/profile.d/nix.sh && nix-build --pure --fallback --no-out-link $nixOpts)
if [ -n "$${nixResultPath}" ]; then
targetPath="android/app/build/outputs/apk/${outType}/app-${outType}.apk"
cpFlags='-v'
is_linux && cpFlags='-fv --no-preserve=mode'
mkdir -p android/app/build/outputs/apk/${outType} && \
cp ${cpFlags} "${nixResultPath}/app.apk" "${targetPath}" && \
chmod u+w ${targetPath}
fi