2019-11-29 10:20:08 +00:00
{ config , stdenv , callPackage , mkShell , mergeSh , buildGoPackage , go ,
fetchFromGitHub , mkFilter , openjdk , androidPkgs , xcodeWrapper } :
2019-03-25 16:35:01 +00:00
let
2019-10-22 11:56:13 +00:00
inherit ( stdenv . lib )
catAttrs concatStrings fileContents importJSON makeBinPath
2019-11-29 10:20:08 +00:00
optional optionalString strings attrValues mapAttrs attrByPath
2019-11-13 13:12:02 +00:00
traceValFn ;
2019-11-29 10:20:08 +00:00
utils = callPackage ./utils.nix { inherit xcodeWrapper ; } ;
gomobile = callPackage ./gomobile { inherit ( androidPkgs ) platform-tools ; inherit xcodeWrapper utils buildGoPackage ; } ;
2019-05-17 08:55:24 +00:00
buildStatusGoDesktopLib = callPackage ./build-desktop-status-go.nix { inherit buildGoPackage go xcodeWrapper utils ; } ;
buildStatusGoMobileLib = callPackage ./build-mobile-status-go.nix { inherit buildGoPackage go gomobile xcodeWrapper utils ; } ;
2019-11-13 13:12:02 +00:00
srcData =
2020-01-13 14:28:40 +00:00
# If config.status-im.status-go.src-override is defined, instruct Nix to use that path to build status-go
if ( attrByPath [ " s t a t u s - i m " " s t a t u s - g o " " s r c - o v e r r i d e " ] " " config ) != " " then rec {
2019-11-13 13:12:02 +00:00
owner = " s t a t u s - i m " ;
repo = " s t a t u s - g o " ;
rev = " u n k n o w n " ;
shortRev = " u n k n o w n " ;
2019-11-29 10:20:08 +00:00
rawVersion = " d e v e l o p " ;
cleanVersion = rawVersion ;
goPackagePath = " g i t h u b . c o m / ${ owner } / ${ repo } " ;
2019-11-25 09:17:28 +00:00
src =
2020-01-13 14:28:40 +00:00
let path = traceValFn ( path : " U s i n g l o c a l ${ repo } s o u r c e s f r o m ${ path } \n " ) config . status-im . status-go . src-override ;
2019-11-25 09:17:28 +00:00
in builtins . path { # We use builtins.path so that we can name the resulting derivation, otherwise the name would be taken from the checkout directory, which is outside of our control
inherit path ;
name = " ${ repo } - s o u r c e - ${ shortRev } " ;
filter =
# Keep this filter as restrictive as possible in order to avoid unnecessary rebuilds and limit closure size
mkFilter {
dirRootsToInclude = [ ] ;
2019-12-06 09:53:09 +00:00
dirsToExclude = [ " . g i t " " . s v n " " C V S " " . h g " " . v s c o d e " " . d e p e n d a b o t " " . g i t h u b " " . e t h e r e u m t e s t " " b u i l d " ] ;
2019-11-25 09:17:28 +00:00
filesToInclude = [ " M a k e f i l e " " g o . m o d " " g o . s u m " " V E R S I O N " ] ;
root = path ;
} ;
} ;
2019-11-13 13:12:02 +00:00
} else
# Otherwise grab it from the location defined by status-go-version.json
let
versionJSON = importJSON ../../status-go-version.json ; # TODO: Simplify this path search with lib.locateDominatingFile
sha256 = versionJSON . src-sha256 ;
in rec {
inherit ( versionJSON ) owner repo version ;
rev = versionJSON . commit-sha1 ;
shortRev = strings . substring 0 7 rev ;
2019-11-29 10:20:08 +00:00
rawVersion = versionJSON . version ;
cleanVersion = utils . sanitizeVersion versionJSON . version ;
goPackagePath = " g i t h u b . c o m / ${ owner } / ${ repo } " ;
2019-11-13 13:12:02 +00:00
src = fetchFromGitHub { inherit rev owner repo sha256 ; name = " ${ repo } - ${ srcData . shortRev } - s o u r c e " ; } ;
} ;
2019-05-02 18:13:16 +00:00
2019-04-09 20:04:45 +00:00
mobileConfigs = {
android = {
name = " a n d r o i d " ;
2019-11-13 13:12:02 +00:00
outputFileName = " s t a t u s - g o - ${ srcData . shortRev } . a a r " ;
2019-05-02 18:13:16 +00:00
envVars = [
" A N D R O I D _ H O M E = ${ androidPkgs . androidsdk } / l i b e x e c / a n d r o i d - s d k "
" A N D R O I D _ N D K _ H O M E = ${ androidPkgs . ndk-bundle } / l i b e x e c / a n d r o i d - s d k / n d k - b u n d l e "
2019-06-04 16:50:29 +00:00
" P A T H = ${ makeBinPath [ openjdk ] } : $ P A T H "
2019-05-02 18:13:16 +00:00
] ;
2019-08-07 10:08:36 +00:00
gomobileExtraFlags = [ " - a n d r o i d a p i 1 8 " ] ;
2019-04-09 20:04:45 +00:00
} ;
ios = {
name = " i o s " ;
outputFileName = " S t a t u s g o . f r a m e w o r k " ;
2019-05-02 18:13:16 +00:00
envVars = [ ] ;
gomobileExtraFlags = [ " - i o s v e r s i o n = 8 . 0 " ] ;
2019-04-09 20:04:45 +00:00
} ;
} ;
hostConfigs = {
darwin = {
2019-05-02 18:13:16 +00:00
name = " m a c o s " ;
allTargets = [ status-go-packages . desktop status-go-packages . ios status-go-packages . android ] ;
2019-04-09 20:04:45 +00:00
} ;
linux = {
2019-05-02 18:13:16 +00:00
name = " l i n u x " ;
allTargets = [ status-go-packages . desktop status-go-packages . android ] ;
2019-04-09 20:04:45 +00:00
} ;
} ;
2019-06-04 16:50:29 +00:00
currentHostConfig = if stdenv . isDarwin then hostConfigs . darwin else hostConfigs . linux ;
2019-05-02 18:13:16 +00:00
2019-04-09 20:04:45 +00:00
goBuildFlags = " - v " ;
2019-10-22 11:56:13 +00:00
# status-go params to be set at build time, important for About section and metrics
goBuildParams = {
2019-11-13 13:12:02 +00:00
GitCommit = srcData . rev ;
2019-11-29 10:20:08 +00:00
Version = srcData . cleanVersion ;
2019-10-22 11:56:13 +00:00
} ;
# These are necessary for status-go to show correct version
paramsLdFlags = attrValues ( mapAttrs ( name : value :
" - X g i t h u b . c o m / s t a t u s - i m / s t a t u s - g o / p a r a m s . ${ name } = ${ value } "
) goBuildParams ) ;
goBuildLdFlags = paramsLdFlags ++ [
" - s " # -s disabled symbol table
" - w " # -w disables DWARF debugging information
] ;
2019-03-25 16:35:01 +00:00
2019-11-29 10:20:08 +00:00
statusGoArgs = { inherit ( srcData ) src owner repo rev cleanVersion goPackagePath ; inherit goBuildFlags goBuildLdFlags ; } ;
2019-05-02 18:13:16 +00:00
status-go-packages = {
desktop = buildStatusGoDesktopLib ( statusGoArgs // {
outputFileName = " l i b s t a t u s . a " ;
2019-06-04 16:50:29 +00:00
hostSystem = stdenv . hostPlatform . system ;
2019-05-02 18:13:16 +00:00
host = currentHostConfig . name ;
} ) ;
android = buildStatusGoMobileLib ( statusGoArgs // {
host = mobileConfigs . android . name ;
2020-01-13 14:28:40 +00:00
targetConfig = mobileConfigs . android ;
2019-05-02 18:13:16 +00:00
} ) ;
ios = buildStatusGoMobileLib ( statusGoArgs // {
host = mobileConfigs . ios . name ;
2020-01-13 14:28:40 +00:00
targetConfig = mobileConfigs . ios ;
2019-05-02 18:13:16 +00:00
} ) ;
2019-03-25 16:35:01 +00:00
} ;
2019-04-12 07:38:08 +00:00
2019-11-29 10:20:08 +00:00
android = rec {
buildInputs = [ status-go-packages . android ] ;
shell = mkShell {
inherit buildInputs ;
shellHook = ''
2019-06-04 16:50:29 +00:00
# These variables are used by the Status Android Gradle build script in android/build.gradle
export STATUS_GO_ANDROID_LIBDIR = $ { status-go-packages . android } /lib
'' ;
2019-11-29 10:20:08 +00:00
} ;
2019-06-04 16:50:29 +00:00
} ;
2019-11-29 10:20:08 +00:00
ios = rec {
buildInputs = [ status-go-packages . ios ] ;
shell = mkShell {
inherit buildInputs ;
shellHook = ''
2019-06-04 16:50:29 +00:00
# These variables are used by the iOS build preparation section in nix/mobile/ios/default.nix
2020-01-08 14:41:07 +00:00
export STATUS_GO_IOS_LIBDIR = $ { status-go-packages . ios } /lib/Statusgo.framework
2019-06-04 16:50:29 +00:00
'' ;
2019-11-29 10:20:08 +00:00
} ;
2019-06-04 16:50:29 +00:00
} ;
2019-11-29 10:20:08 +00:00
desktop = rec {
buildInputs = [ status-go-packages . desktop ] ;
shell = mkShell {
inherit buildInputs ;
shellHook = ''
2019-06-04 16:50:29 +00:00
# These variables are used by the Status Desktop CMake build script in modules/react-native-status/desktop/CMakeLists.txt
export STATUS_GO_DESKTOP_INCLUDEDIR = $ { status-go-packages . desktop } /include
export STATUS_GO_DESKTOP_LIBDIR = $ { status-go-packages . desktop } /lib
'' ;
2019-11-29 10:20:08 +00:00
} ;
2019-06-04 16:50:29 +00:00
} ;
platforms = [ android ios desktop ] ;
2019-05-02 18:13:16 +00:00
2019-04-12 07:38:08 +00:00
in {
2019-11-29 10:20:08 +00:00
shell = mergeSh mkShell { } ( catAttrs " s h e l l " platforms ) ;
2019-05-02 18:13:16 +00:00
2019-06-04 16:50:29 +00:00
# CHILD DERIVATIONS
inherit android ios desktop ;
2019-03-25 16:35:01 +00:00
}