2019-11-13 13:12:02 +00:00
{ target-os , config , stdenv , callPackage ,
2019-11-25 09:17:28 +00:00
buildGoPackage , go , fetchFromGitHub , mkFilter , openjdk ,
2019-06-04 16:50:29 +00:00
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-13 13:12:02 +00:00
optional optionalString removePrefix strings attrValues mapAttrs attrByPath
traceValFn ;
2019-05-17 08:55:24 +00:00
platform = callPackage ../platform.nix { inherit target-os ; } ;
utils = callPackage ../utils.nix { inherit xcodeWrapper ; } ;
2019-06-04 16:50:29 +00:00
gomobile = callPackage ./gomobile { inherit ( androidPkgs ) platform-tools ; inherit target-os 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 =
# If config.status_go.src_override is defined, instruct Nix to use that path to build status-go
if ( attrByPath [ " s t a t u s _ g o " " s r c _ o v e r r i d e " ] " " config ) != " " then rec {
owner = " s t a t u s - i m " ;
repo = " s t a t u s - g o " ;
version = " d e v e l o p " ;
goPackagePath = " g i t h u b . c o m / ${ owner } / ${ repo } " ;
rev = " u n k n o w n " ;
shortRev = " u n k n o w n " ;
versionName = " d e v e l o p " ;
2019-11-25 09:17:28 +00:00
src =
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_go . src_override ;
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 = [ ] ;
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 " " e t h - n o d e " " p r o t o c o l " ] ;
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
versionRegex = " ^ v ? [ [ : d i g i t : ] ] + \. [ [ : d i g i t : ] ] + \. [ [ : d i g i t : ] ] + ( - [ [ : a l n u m : ] . ] + ) $ " ;
sha256 = versionJSON . src-sha256 ;
2019-11-28 16:43:28 +00:00
sanitizeVersion = builtins . replaceStrings
[ " / " ]
[ " _ " ] ;
2019-11-13 13:12:02 +00:00
in rec {
inherit ( versionJSON ) owner repo version ;
2019-11-28 16:43:28 +00:00
sanitizedVersion = sanitizeVersion versionJSON . version ;
2019-11-13 13:12:02 +00:00
goPackagePath = " g i t h u b . c o m / ${ owner } / ${ repo } " ;
rev = versionJSON . commit-sha1 ;
shortRev = strings . substring 0 7 rev ;
2019-11-28 16:43:28 +00:00
versionName = if ( builtins . match versionRegex sanitizedVersion ) != null
then removePrefix " v " sanitizedVersion # Geth forces a 'v' prefix
2019-11-13 13:12:02 +00:00
else " d e v e l o p " ; # to reduce metrics cardinality in Prometheus
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 ;
Version = srcData . versionName ;
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-28 16:43:28 +00:00
statusGoArgs = { inherit ( srcData ) src owner repo rev version sanitizedVersion 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 ;
config = mobileConfigs . android ;
} ) ;
ios = buildStatusGoMobileLib ( statusGoArgs // {
host = mobileConfigs . ios . name ;
config = mobileConfigs . ios ;
} ) ;
2019-03-25 16:35:01 +00:00
} ;
2019-04-12 07:38:08 +00:00
2019-07-29 08:33:35 +00:00
buildInputs = if target-os == " a n d r o i d " then
android . buildInputs
else if target-os == " i o s " then
ios . buildInputs
else if target-os == " a l l " then
currentHostConfig . allTargets
else if platform . targetDesktop then
desktop . buildInputs
else
throw " U n e x p e c t e d t a r g e t p l a t f o r m ${ target-os } " ;
2019-06-04 16:50:29 +00:00
android = {
buildInputs = optional platform . targetAndroid [ status-go-packages . android ] ;
shellHook =
optionalString platform . targetAndroid ''
# 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
'' ;
} ;
ios = {
buildInputs = optional platform . targetIOS [ status-go-packages . ios ] ;
shellHook =
optionalString platform . targetIOS ''
# These variables are used by the iOS build preparation section in nix/mobile/ios/default.nix
export RCTSTATUS_FILEPATH = $ { status-go-packages . ios } /lib/Statusgo.framework
'' ;
} ;
desktop = {
buildInputs = optional platform . targetDesktop [ status-go-packages . desktop ] ;
shellHook =
optionalString platform . targetDesktop ''
# 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
'' ;
} ;
platforms = [ android ios desktop ] ;
2019-05-02 18:13:16 +00:00
2019-04-12 07:38:08 +00:00
in {
2019-05-13 09:22:29 +00:00
inherit buildInputs ;
2019-06-04 16:50:29 +00:00
shellHook = concatStrings ( catAttrs " s h e l l H o o k " 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
}