nix: switch status-im config to env vars, cleanup

To help with #15595 changes, refactoring is required.
In this PR we switch from config to env vars.
Doing some cleanup meanwhile.
This commit is contained in:
Anton Iakimov 2023-06-27 13:45:21 +02:00
parent bc18e8aac5
commit d5c1ecc104
No known key found for this signature in database
GPG Key ID: DEA1FE58DD8BF7FA
34 changed files with 144 additions and 255 deletions

View File

@ -46,7 +46,10 @@ export NIX_USER_CONF_FILES = $(PWD)/nix/nix.conf
# Location of symlinks to derivations that should not be garbage collected # Location of symlinks to derivations that should not be garbage collected
export _NIX_GCROOTS = /nix/var/nix/gcroots/per-user/$(USER)/status-mobile export _NIX_GCROOTS = /nix/var/nix/gcroots/per-user/$(USER)/status-mobile
# Defines which variables will be kept for Nix pure shell, use semicolon as divider # Defines which variables will be kept for Nix pure shell, use semicolon as divider
export _NIX_KEEP ?= TMPDIR,BUILD_ENV,STATUS_GO_SRC_OVERRIDE export _NIX_KEEP ?= TMPDIR,BUILD_ENV,\
BUILD_TYPE,BUILD_NUMBER,COMMIT_HASH,\
ANDROID_GRADLE_OPTS,ANDROID_ABI_SPLIT,ANDROID_ABI_INCLUDE,\
STATUS_GO_SRC_OVERRIDE,STATUS_GO_IPFS_GATEWAY_URL
# Useful for Android release builds # Useful for Android release builds
TMP_BUILD_NUMBER := $(shell ./scripts/version/gen_build_no.sh | cut -c1-10) TMP_BUILD_NUMBER := $(shell ./scripts/version/gen_build_no.sh | cut -c1-10)

View File

@ -168,6 +168,7 @@ def getVersionCode = { ->
def getVersionName = { -> def getVersionName = { ->
new ByteArrayOutputStream().withStream { stdOut -> new ByteArrayOutputStream().withStream { stdOut ->
// TODO: probably not used, cleanup
if (project.hasProperty("releaseVersion")) { if (project.hasProperty("releaseVersion")) {
return project.releaseVersion return project.releaseVersion
} }

View File

@ -1,5 +1,5 @@
#!/usr/bin/env groovy #!/usr/bin/env groovy
library 'status-jenkins-lib@v1.7.10' library 'status-jenkins-lib@v1.7.12'
/* Options section can't access functions in objects. */ /* Options section can't access functions in objects. */
def isPRBuild = utils.isPRBuild() def isPRBuild = utils.isPRBuild()

View File

@ -1,5 +1,5 @@
#!/usr/bin/env groovy #!/usr/bin/env groovy
library 'status-jenkins-lib@v1.7.10' library 'status-jenkins-lib@v1.7.12'
pipeline { pipeline {
agent { label 'linux' } agent { label 'linux' }

View File

@ -1,5 +1,5 @@
#!/usr/bin/env groovy #!/usr/bin/env groovy
library 'status-jenkins-lib@v1.7.9' library 'status-jenkins-lib@v1.7.12'
pipeline { pipeline {
agent { label 'linux' } agent { label 'linux' }

View File

@ -1,5 +1,5 @@
#!/usr/bin/env groovy #!/usr/bin/env groovy
library 'status-jenkins-lib@v1.7.10' library 'status-jenkins-lib@v1.7.12'
/* Options section can't access functions in objects. */ /* Options section can't access functions in objects. */
def isPRBuild = utils.isPRBuild() def isPRBuild = utils.isPRBuild()

View File

@ -1,5 +1,5 @@
#!/usr/bin/env groovy #!/usr/bin/env groovy
library 'status-jenkins-lib@v1.7.10' library 'status-jenkins-lib@v1.7.12'
/* Options section can't access functions in objects. */ /* Options section can't access functions in objects. */
def isPRBuild = utils.isPRBuild() def isPRBuild = utils.isPRBuild()

View File

@ -1,5 +1,5 @@
#!/usr/bin/env groovy #!/usr/bin/env groovy
library 'status-jenkins-lib@v1.7.10' library 'status-jenkins-lib@v1.7.12'
pipeline { pipeline {

View File

@ -1,5 +1,5 @@
#!/usr/bin/env groovy #!/usr/bin/env groovy
library 'status-jenkins-lib@v1.7.9' library 'status-jenkins-lib@v1.7.12'
pipeline { pipeline {

View File

@ -1,5 +1,5 @@
#!/usr/bin/env groovy #!/usr/bin/env groovy
library 'status-jenkins-lib@v1.7.10' library 'status-jenkins-lib@v1.7.12'
pipeline { pipeline {

View File

@ -1,5 +1,5 @@
#!/usr/bin/env groovy #!/usr/bin/env groovy
library 'status-jenkins-lib@v1.7.10' library 'status-jenkins-lib@v1.7.12'
pipeline { pipeline {

View File

@ -1,5 +1,5 @@
#!/usr/bin/env groovy #!/usr/bin/env groovy
library 'status-jenkins-lib@v1.7.10' library 'status-jenkins-lib@v1.7.12'
pipeline { pipeline {
agent { label 'macos' } agent { label 'macos' }

View File

@ -1,5 +1,5 @@
#!/usr/bin/env groovy #!/usr/bin/env groovy
library 'status-jenkins-lib@v1.7.10' library 'status-jenkins-lib@v1.7.12'
pipeline { pipeline {
agent { label params.AGENT_LABEL } agent { label params.AGENT_LABEL }

View File

@ -1,5 +1,5 @@
#!/usr/bin/env groovy #!/usr/bin/env groovy
library 'status-jenkins-lib@v1.7.10' library 'status-jenkins-lib@v1.7.12'
pipeline { pipeline {
agent { label 'linux' } agent { label 'linux' }

View File

@ -1,5 +1,5 @@
#!/usr/bin/env groovy #!/usr/bin/env groovy
library 'status-jenkins-lib@v1.7.10' library 'status-jenkins-lib@v1.7.12'
pipeline { pipeline {
agent { agent {

View File

@ -23,7 +23,6 @@ There are a few main files that define the whole build environment:
* [`nix/shells.nix`](./shells.nix) - Definitions of other Nix shells used in builds * [`nix/shells.nix`](./shells.nix) - Definitions of other Nix shells used in builds
* [`nix/targets.nix`](./targets.nix) - Hierarchy of main build targets * [`nix/targets.nix`](./targets.nix) - Hierarchy of main build targets
* [`nix/pkgs.nix`](./pkgs.nix) - Definition of a custom `nixpkgs` repo * [`nix/pkgs.nix`](./pkgs.nix) - Definition of a custom `nixpkgs` repo
* [`nix/config.nix`](./config.nix) - Default config values for instantiating `nixpkgs`
* [`nix/overlay.nix`](./overlay.nix) - Overrides for `nixpkgs`, custom packages * [`nix/overlay.nix`](./overlay.nix) - Overrides for `nixpkgs`, custom packages
The [`default.nix`](../default.nix) and [`shell.nix`](../shell.nix) files at th repo root are just a gateway into the `nix` sub folder. The [`default.nix`](../default.nix) and [`shell.nix`](../shell.nix) files at th repo root are just a gateway into the `nix` sub folder.
@ -75,13 +74,6 @@ nix-build \
--attr targets.mobile.android.release \ --attr targets.mobile.android.release \
--argstr secrets-file '/tmp/tmp-status-mobile-559a3a441/tmp.xAnrPuNtAP' \ --argstr secrets-file '/tmp/tmp-status-mobile-559a3a441/tmp.xAnrPuNtAP' \
--option extra-sandbox-paths '/home/joe/.gradle/status-im.keystore /tmp/tmp-status-mobile-559a3a441/tmp.xAnrPuNtAP' \ --option extra-sandbox-paths '/home/joe/.gradle/status-im.keystore /tmp/tmp-status-mobile-559a3a441/tmp.xAnrPuNtAP' \
--arg config '{ \
status-im.build-type="nightly";
status-im.build-number="2020022418";
status-im.android.keystore-path="/home/joe/.gradle/status-im.keystore";
status-im.android.abi-split="false";
status-im.android.abi-include="armeabi-v7a;arm64-v8a;x86";
}' \
default.nix default.nix
``` ```
Some of those are required which is why just calling: Some of those are required which is why just calling:

View File

@ -8,27 +8,27 @@ The main config file is [`nix/nix.conf`](/nix/nix.conf) and its main purpose is
## Build arguments ## Build arguments
We leverage the `config` argument of standard `nixpkgs` for our own parameterization of the builds (e.g. to pass a build number or build type). We leverage the environment variables for parameterization of the builds (e.g. to pass a build number or build type).
Here is a sample structure of the `config` attribute set: Here is the list of variables you can use to override defaults:
```shell
```nix # Build type (influences which .env file gets used for feature flags)
{ export BUILD_TYPE="pr"
status-im = { # Used for versionCode and CFBundleVersion in Android and iOS respectively
build-type = "pr"; # Build type (influences which .env file gets used for feature flags) export BUILD_NUMBER=9999
build-number = 9999; # Used for versionCode and CFBundleVersion in Android and iOS respectively # Gradle options passed for Android builds
android = { export ANDROID_GRADLE_OPTS=""
gradle-opts = ""; # Gradle options passed for Android builds # If APKs should be split based on architectures
abi-split = false; # If APKs should be split based on architectures export ANDROID_ABI_SPLIT=false
abi-include = "x86"; # Android architectures to build for # Android architectures to build for
}; export ANDROID_ABI_INCLUDE="x86"
status-go = { # Local source override, see below
src-override = "$HOME/my/source/status-go"; # local source override export STATUS_GO_SRC_OVERRIDE="$HOME/my/source/status-go"
}; export STATUS_GO_IPFS_GATEWAY_URL="https://ipfs.status.im/"
};
}
``` ```
You can see the defaults in [`nix/config.nix`](./config.nix). You can see the defaults in code:
- [`nix/status-go/default.nix`](./status-go/default.nix)
- [`nix/mobile/android/release.nix`](./mobile/android/release.nix)
## Shell ## Shell

View File

@ -1,24 +0,0 @@
# Status defaults for config
{
status-im = {
build-type = "pr"; # Build type (influences which .env file gets used for feature flags)
build-number = 9999; # Used for versionCode and CFBundleVersion in Android and iOS respectively
commit-hash = "unknown"; # Included in APK Manifest for easier identification.
android = {
gradle-opts = null; # Gradle options passed for Android builds
apk-signed = true; # F-Droid builds aren't signed by us
abi-split = false; # If APKs should be split based on architectures
abi-include = "armeabi-v7a;arm64-v8a;x86"; # Android architectures to build for
};
status-go = {
src-override = null;
ipfs-gateway-url = "https://ipfs.status.im/";
};
};
# Android SDK requires an accepted license
android_sdk.accept_license = true;
allowUnfree = true;
}

View File

@ -1,8 +1,9 @@
{ lib, config }: { lib }:
{ {
getConfig = import ./getConfig.nix { inherit lib config; }; getEnvWithDefault = import ./getEnvWithDefault.nix;
mkFilter = import ./mkFilter.nix { inherit lib; }; mkFilter = import ./mkFilter.nix { inherit lib; };
mergeSh = import ./mergeSh.nix { inherit lib; }; mergeSh = import ./mergeSh.nix { inherit lib; };
checkEnvVarSet = import ./checkEnvVarSet.nix; checkEnvVarSet = import ./checkEnvVarSet.nix;
sanitizeVersion = import ./sanitizeVersion.nix { inherit lib; };
} }

View File

@ -1,11 +0,0 @@
# helper for getting status-im config values in a safe way
#
{ lib, config }:
let inherit (lib) splitString attrByPath;
in name: default:
let
path = [ "status-im" ] ++ (splitString "." name);
value = attrByPath path default config;
in if value != null then value else default

View File

@ -0,0 +1,8 @@
name: default: let
envOverride = builtins.getEnv name;
logEnvOverride = value:
builtins.trace "getEnvWithDefault ${name} (default: ${toString default}): ${value}" value;
in
if envOverride != ""
then logEnvOverride envOverride
else default

View File

@ -0,0 +1,14 @@
{ lib }:
version:
let
# paths don't like slashes in them
dropSlashes = builtins.replaceStrings [ "/" ] [ "_" ];
# if version doesn't match this it's probably a commit, it's lax semver
versionRegex = "^v?[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+[[:alnum:]+_.-]*$";
in
if (builtins.match versionRegex version) != null
# Geth forces a 'v' prefix for all versions
then lib.removePrefix "v" (dropSlashes version)
# reduce metrics cardinality in Prometheus
else lib.traceValFn (_: "WARNING: Marking build version as 'develop'!") "develop"

View File

@ -6,20 +6,30 @@
buildEnv ? "prod", buildEnv ? "prod",
# Path to the file containing secret environment variables # Path to the file containing secret environment variables
secretsFile ? "", secretsFile ? "",
# Build type (influences which .env file gets used for feature flags)
# TODO: pr or relase for default?
buildType ? lib.getEnvWithDefault "BUILD_TYPE" "release",
# Used for versionCode
buildNumber ? lib.getEnvWithDefault "BUILD_NUMBER" 9999,
# Included in APK Manifest for easier identification.
# TODO: or GIT_COMMIT from Jenkins?
commitHash ? lib.getEnvWithDefault "COMMIT_HASH" "unknown",
# Gradle options passed for Android builds
androidGradleOpts ? lib.getEnvWithDefault "ANDROID_GRADLE_OPTS" null,
statusGoSrcOverride ? lib.getEnvWithDefault "STATUS_GO_SRC_OVERRIDE" null,
# If APKs should be split based on architectures
androidAbiSplit ? lib.getEnvWithDefault "ANDROID_ABI_SPLIT" "false",
# Android architectures to build for
# Used to detect end-to-end builds
androidAbiInclude ? lib.getEnvWithDefault "ANDROID_ABI_INCLUDE" "armeabi-v7a;arm64-v8a;x86",
}: }:
let let
inherit (lib) toLower optionalString stringLength getConfig makeLibraryPath elem; inherit (lib) toLower optionalString stringLength makeLibraryPath elem;
# Pass secretsFile for POKT_TOKEN to jsbundle build # Pass secretsFile for POKT_TOKEN to jsbundle build
builtJsBundle = jsbundle { inherit secretsFile; }; builtJsBundle = jsbundle { inherit secretsFile; };
buildType = getConfig "build-type" "release";
buildNumber = getConfig "build-number" 9999;
commitHash = getConfig "commit-hash" "unknown";
gradleOpts = getConfig "android.gradle-opts" null;
# Used to detect end-to-end builds
androidAbiInclude = getConfig "android.abi-include" "armeabi-v7a;arm64-v8a;x86";
envFileName = envFileName =
if androidAbiInclude == "x86" then ".env.e2e" if androidAbiInclude == "x86" then ".env.e2e"
@ -63,9 +73,8 @@ in stdenv.mkDerivation rec {
# Used by Clojure at compile time to include JS modules # Used by Clojure at compile time to include JS modules
BUILD_ENV = buildEnv; BUILD_ENV = buildEnv;
# custom env variables derived from config STATUS_GO_SRC_OVERRIDE = statusGoSrcOverride;
STATUS_GO_SRC_OVERRIDE = getConfig "status-go.src-override" null; ANDROID_ABI_SPLIT = androidAbiSplit;
ANDROID_ABI_SPLIT = getConfig "android.abi-split" "false";
ANDROID_ABI_INCLUDE = androidAbiInclude; ANDROID_ABI_INCLUDE = androidAbiInclude;
# Android SDK/NDK for use by Gradle # Android SDK/NDK for use by Gradle
@ -122,17 +131,9 @@ in stdenv.mkDerivation rec {
buildPhase = let buildPhase = let
adhocEnvVars = optionalString stdenv.isLinux adhocEnvVars = optionalString stdenv.isLinux
"LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${makeLibraryPath [ pkgs.zlib ]}"; "LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${makeLibraryPath [ pkgs.zlib ]}";
in gradleCommand = ''
assert ANDROID_ABI_SPLIT != null && ANDROID_ABI_SPLIT != ""; ${pkgs.gradle}/bin/gradle \
assert stringLength ANDROID_ABI_INCLUDE > 0; ${toString androidGradleOpts} \
''
# Fixes issue with failing to load libnative-platform.so
export GRADLE_USER_HOME=$(mktemp -d)
export ANDROID_SDK_HOME=$(mktemp -d)
pushd ./android
${adhocEnvVars} ${pkgs.gradle}/bin/gradle \
${toString gradleOpts} \
--console=plain \ --console=plain \
--offline \ --offline \
--no-daemon \ --no-daemon \
@ -142,8 +143,21 @@ in stdenv.mkDerivation rec {
-Dmaven.repo.local='${deps.gradle}' \ -Dmaven.repo.local='${deps.gradle}' \
-PversionCode=${toString buildNumber} \ -PversionCode=${toString buildNumber} \
-PcommitHash=${commitHash} \ -PcommitHash=${commitHash} \
assemble${gradleBuildType} \ assemble${gradleBuildType}
|| exit 1 '';
in
assert ANDROID_ABI_SPLIT != null && ANDROID_ABI_SPLIT != "";
assert stringLength ANDROID_ABI_INCLUDE > 0;
''
# Fixes issue with failing to load libnative-platform.so
export GRADLE_USER_HOME=$(mktemp -d)
export ANDROID_SDK_HOME=$(mktemp -d)
echo "Adhoc ENV: ${adhocEnvVars}"
echo "Running: ${gradleCommand}"
pushd ./android
${adhocEnvVars} ${gradleCommand}
popd > /dev/null popd > /dev/null
''; '';
doCheck = true; doCheck = true;

View File

@ -13,11 +13,8 @@ in {
# Fix for MacOS # Fix for MacOS
mkShell = super.mkShell.override { stdenv = stdenvNoCC; }; mkShell = super.mkShell.override { stdenv = stdenvNoCC; };
# Various utilities
utils = callPackage ./tools/utils.nix { };
lib = (super.lib or { }) // (import ./lib { lib = (super.lib or { }) // (import ./lib {
inherit (super) lib; inherit (super) lib;
inherit (self) config;
}); });
# Project dependencies # Project dependencies
@ -29,9 +26,6 @@ in {
react-native = callPackage ./deps/react-native { }; react-native = callPackage ./deps/react-native { };
}; };
# For parsing gradle.properties into an attrset
gradlePropParser = callPackage ./tools/gradlePropParser.nix { };
# Fix for missing libarclite_macosx.a in Xcode 14.3. # Fix for missing libarclite_macosx.a in Xcode 14.3.
# https://github.com/ios-control/ios-deploy/issues/580 # https://github.com/ios-control/ios-deploy/issues/580
ios-deploy = super.darwin.ios-deploy.overrideAttrs (old: rec { ios-deploy = super.darwin.ios-deploy.overrideAttrs (old: rec {

View File

@ -13,7 +13,10 @@ let
}; };
# Status specific configuration defaults # Status specific configuration defaults
defaultConfig = import ./config.nix; defaultConfig = {
android_sdk.accept_license = true;
allowUnfree = true;
};
# Override some packages and utilities # Override some packages and utilities
pkgsOverlay = import ./overlay.nix; pkgsOverlay = import ./overlay.nix;

View File

@ -41,16 +41,6 @@ nixArgs=(
"--attr shells.${TARGET}" "--attr shells.${TARGET}"
) )
config=''
if [[ -n "${STATUS_GO_SRC_OVERRIDE}" ]]; then
config+="status-im.status-go.src-override=\"${STATUS_GO_SRC_OVERRIDE}\";"
fi
config+="status-im.build-type=\"${BUILD_TYPE}\";"
if [[ -n "$config" ]]; then
nixArgs+=("--arg config {$config}")
fi
# This variable allows specifying which env vars to keep for Nix pure shell # This variable allows specifying which env vars to keep for Nix pure shell
# The separator is a colon # The separator is a colon
if [[ -n "${_NIX_KEEP}" ]]; then if [[ -n "${_NIX_KEEP}" ]]; then

View File

@ -1,7 +1,7 @@
{ lib, callPackage, mkShell }: { lib, callPackage, mkShell }:
let let
inherit (lib) getConfig attrValues mapAttrs; inherit (lib) getEnvWithDefault attrValues mapAttrs;
# Metadata common to all builds of status-go # Metadata common to all builds of status-go
meta = { meta = {
@ -18,7 +18,7 @@ let
GitCommit = source.rev; GitCommit = source.rev;
Version = source.cleanVersion; Version = source.cleanVersion;
# FIXME: This should be moved to status-go config. # FIXME: This should be moved to status-go config.
IpfsGatewayURL = getConfig "status-go.ipfs-gateway-url" "https://ipfs.status.im/"; IpfsGatewayURL = getEnvWithDefault "STATUS_GO_IPFS_GATEWAY_URL" "https://ipfs.status.im/";
}; };
# These are necessary for status-go to show correct version # These are necessary for status-go to show correct version

View File

@ -1,4 +1,4 @@
{ lib, utils, buildGoPackage { callPackage, lib, buildGoPackage
, androidPkgs, openjdk, gomobile, xcodeWrapper, removeReferencesTo , androidPkgs, openjdk, gomobile, xcodeWrapper, removeReferencesTo
, meta , meta
, source , source
@ -13,6 +13,7 @@ let
inherit (lib) concatStringsSep optionalString optional; inherit (lib) concatStringsSep optionalString optional;
isIOS = platform == "ios"; isIOS = platform == "ios";
isAndroid = platform == "android"; isAndroid = platform == "android";
enforceXCodeAvailable = callPackage ./enforceXCodeAvailable.nix { };
in buildGoPackage { in buildGoPackage {
pname = source.repo; pname = source.repo;
@ -35,7 +36,7 @@ in buildGoPackage {
ANDROID_HOME = optionalString isAndroid androidPkgs.sdk; ANDROID_HOME = optionalString isAndroid androidPkgs.sdk;
# Ensure XCode is present for iOS, instead of failing at the end of the build. # Ensure XCode is present for iOS, instead of failing at the end of the build.
preConfigure = optionalString isIOS utils.enforceXCodeAvailable; preConfigure = optionalString isIOS enforceXCodeAvailable;
buildPhase = '' buildPhase = ''
runHook preBuild runHook preBuild

View File

@ -0,0 +1,30 @@
{ xcodeWrapper }:
let
RED = "\\033[0;31m";
GREEN = "\\033[0;32m";
NC = "\\033[0m";
_xcodeToolsTest = ''
xcode=0
iPhoneSDK=0
export PATH=${xcodeWrapper}/bin:$PATH
xcrun xcodebuild -version && xcode=1
[ $xcode -eq 1 ] && xcrun --sdk iphoneos --show-sdk-version > /dev/null && iPhoneSDK=1
'';
_xcodeToolReportScript = tool-name: ''[ $SELECTED -eq 0 ] && echo -e "${NC}- ${RED}[ ] ${tool-name}" || echo -e "${NC}- ${GREEN}[] ${tool-name}${RED}"'';
_xcodeToolsReportScript = ''
echo -e "${RED}There are some required tools missing in the system:"
export SELECTED=$xcode; ${_xcodeToolReportScript "Xcode ${_xcodeVersion}"}
export SELECTED=$iPhoneSDK; ${_xcodeToolReportScript "iPhone SDK"}
'';
_xcodeVersion = builtins.replaceStrings ["xcode-wrapper-"] [""] xcodeWrapper.name;
in
''
${_xcodeToolsTest}
if [ $xcode -eq 0 ]; then
${_xcodeToolsReportScript}
echo -e "Please install Xcode ${_xcodeVersion} from the App Store.${NC}"
exit 1
fi
''

View File

@ -1,9 +1,10 @@
{ utils, lib, fetchFromGitHub }: { lib, fetchFromGitHub }:
let let
inherit (lib) strings traceValFn importJSON getConfig; inherit (lib) strings traceValFn importJSON getEnvWithDefault;
srcOverride = getConfig "status-go.src-override" null; # TODO: move to default?
srcOverride = getEnvWithDefault "STATUS_GO_SRC_OVERRIDE" null;
# Warning message about using local sources # Warning message about using local sources
localSrcWarn = (path: "Using local status-go sources from ${path}"); localSrcWarn = (path: "Using local status-go sources from ${path}");
@ -43,7 +44,7 @@ let
rev = versionJSON.commit-sha1; rev = versionJSON.commit-sha1;
shortRev = strings.substring 0 7 rev; shortRev = strings.substring 0 7 rev;
rawVersion = versionJSON.version; rawVersion = versionJSON.version;
cleanVersion = utils.sanitizeVersion versionJSON.version; cleanVersion = lib.sanitizeVersion versionJSON.version;
# Need to pretend this is from status-im to let Go build it. # Need to pretend this is from status-im to let Go build it.
goPackagePath = "github.com/status-im/${repo}"; goPackagePath = "github.com/status-im/${repo}";
src = fetchFromGitHub { src = fetchFromGitHub {

View File

@ -1,35 +0,0 @@
# This Nix expression takes care of reading/parsing the correct .env configuration file and return it as an attr set
{ config, lib }:
let
inherit (builtins) listToAttrs head tail readFile;
inherit (lib) attrByPath filter hasPrefix nameValuePair splitString;
build-type = attrByPath ["status-im" "build-type"] "" config;
readLinesFromFile =
file:
let
lines = splitString "\n" (readFile file);
removeComments = filter (line: line != "" && !(hasPrefix "#" line));
meaningfulLines = removeComments lines;
in
meaningfulLines;
readFlagsFromFile =
file:
let
lines = readLinesFromFile file;
genAttrs = lines:
listToAttrs (map (line:
let flag = splitString "=" line;
in nameValuePair (head flag) (head (tail flag))) lines);
in
genAttrs lines;
envFileName =
if build-type == "release" then ../../.env.release else
if build-type == "nightly" then ../../.env.nightly else
if build-type == "e2e" then ../../.env.e2e else
if build-type == "pr" then ../../.env.jenkins else ../../.env;
flags = readFlagsFromFile envFileName; # TODO: Simplify this path search with lib.locateDominatingFile
in flags

View File

@ -1,20 +0,0 @@
# Parser for android/gradle.properties file.
# Returns an attrset with keys and values from it.
{ lib }:
gradlePropsFile:
let
inherit (lib) head last filter listToAttrs splitString nameValuePair hasPrefix readFile;
# Read lines
lines = splitString "\n" (readFile gradlePropsFile);
isKeyValueLine = line: line != "" && !hasPrefix "#" line;
cleanup = filter isKeyValueLine;
extractKeyValues = line:
let flag = splitString "=" line;
in nameValuePair (head flag) (last flag);
parseAttrs = lines: listToAttrs (map extractKeyValues lines);
in
parseAttrs (cleanup lines)

View File

@ -1,64 +0,0 @@
{ xcodeWrapper, lib }:
#
# This is a collection of various utilities used throught this repo.
#
let
RED = "\\033[0;31m";
GREEN = "\\033[0;32m";
NC = "\\033[0m";
_xcodeToolsTest = ''
xcode=0
iPhoneSDK=0
export PATH=${xcodeWrapper}/bin:$PATH
xcrun xcodebuild -version && xcode=1
[ $xcode -eq 1 ] && xcrun --sdk iphoneos --show-sdk-version > /dev/null && iPhoneSDK=1
'';
_xcodeToolReportScript = tool-name: ''[ $SELECTED -eq 0 ] && echo -e "${NC}- ${RED}[ ] ${tool-name}" || echo -e "${NC}- ${GREEN}[] ${tool-name}${RED}"'';
_xcodeToolsReportScript = ''
echo -e "${RED}There are some required tools missing in the system:"
export SELECTED=$xcode; ${_xcodeToolReportScript "Xcode ${_xcodeVersion}"}
export SELECTED=$iPhoneSDK; ${_xcodeToolReportScript "iPhone SDK"}
'';
_xcodeVersion = builtins.replaceStrings ["xcode-wrapper-"] [""] xcodeWrapper.name;
enforceXCodeAvailable = ''
${_xcodeToolsTest}
if [ $xcode -eq 0 ]; then
${_xcodeToolsReportScript}
echo -e "Please install Xcode ${_xcodeVersion} from the App Store.${NC}"
exit 1
fi
'';
enforceiPhoneSDKAvailable = ''
${_xcodeToolsTest}
if [ $iPhoneSDK -eq 0 ]; then
${_xcodeToolsReportScript}
if [ $xcode -eq 1 ]; then
echo -e "Please install the iPhone SDK in Xcode.${NC}""
else
echo -e "Please install Xcode ${_xcodeVersion} from the App Store, and then the iPhone SDK.${NC}""
fi
exit 1
fi
'';
# paths don't like slashes in them
dropSlashes = builtins.replaceStrings [ "/" ] [ "_" ];
# if version doesn't match this it's probably a commit, it's lax semver
versionRegex = "^v?[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+[[:alnum:]+_.-]*$";
sanitizeVersion = version:
if (builtins.match versionRegex version) != null
# Geth forces a 'v' prefix for all versions
then lib.removePrefix "v" (dropSlashes version)
# reduce metrics cardinality in Prometheus
else lib.traceValFn (_: "WARNING: Marking build version as 'develop'!") "develop";
in {
inherit sanitizeVersion
enforceXCodeAvailable
enforceiPhoneSDKAvailable;
}

View File

@ -22,15 +22,7 @@ function append_env_export() {
echo "export ${VAR_NAME}=\"${VAR_VALUE}\";" >> "${SECRETS_FILE_PATH}" echo "export ${VAR_NAME}=\"${VAR_VALUE}\";" >> "${SECRETS_FILE_PATH}"
} }
config='' export COMMIT_HASH="$(git rev-parse --verify HEAD)"
if [[ -n "${STATUS_GO_SRC_OVERRIDE}" ]]; then
config+="status-im.status-go.src-override=\"${STATUS_GO_SRC_OVERRIDE}\";"
fi
config+="status-im.commit-hash=\"$(git rev-parse --verify HEAD)\";"
config+="status-im.build-type=\"$(must_get_env BUILD_TYPE)\";"
config+="status-im.build-number=\"$(must_get_env BUILD_NUMBER)\";"
config+="status-im.android.abi-split=\"$(must_get_env ANDROID_ABI_SPLIT)\";"
config+="status-im.android.abi-include=\"$(must_get_env ANDROID_ABI_INCLUDE)\";"
nixOpts=() nixOpts=()
# We create if now so the trap knows its location # We create if now so the trap knows its location
@ -73,6 +65,5 @@ else
nixOpts+=("--option" "build-use-sandbox" "true") nixOpts+=("--option" "build-use-sandbox" "true")
fi fi
nixOpts+=("--arg" "config" "{${config}}")
"${GIT_ROOT}/nix/scripts/build.sh" targets.mobile.android.release "${nixOpts[@]}" "${GIT_ROOT}/nix/scripts/build.sh" targets.mobile.android.release "${nixOpts[@]}"