2023-04-29 16:46:19 +00:00
{ lib
, stdenv
, hostPlatform
, engineVersion
2023-07-15 17:15:38 +00:00
, fetchurl
2023-04-29 16:46:19 +00:00
, fetchzip
, autoPatchelfHook
, gtk3
2023-08-22 20:05:09 +00:00
, flutterVersion
2023-07-15 17:15:38 +00:00
, unzip
2023-08-22 20:05:09 +00:00
, stdenvNoCC
2023-04-29 16:46:19 +00:00
} :
let
hashes = ( import ./hashes.nix ) . ${ engineVersion } or
( throw " T h e r e a r e n o k n o w n a r t i f a c t h a s h e s f o r F l u t t e r e n g i n e v e r s i o n ${ engineVersion } . " ) ;
2023-08-22 20:05:09 +00:00
noticeText = stdenvNoCC . mkDerivation ( finalAttrs : {
pname = " f l u t t e r - n o t i c e " ;
version = engineVersion ;
dontUnpack = true ;
src = fetchurl {
pname = " f l u t t e r - s k y _ e n g i n e - L I C E N S E " ;
version = engineVersion ;
url = " h t t p s : / / r a w . g i t h u b u s e r c o n t e n t . c o m / f l u t t e r / e n g i n e / ${ engineVersion } / s k y / p a c k a g e s / s k y _ e n g i n e / L I C E N S E " ;
sha256 = hashes . skyNotice ;
} ;
flutterNotice = fetchurl {
pname = " f l u t t e r - L I C E N S E " ;
version = engineVersion ;
url = " h t t p s : / / r a w . g i t h u b u s e r c o n t e n t . c o m / f l u t t e r / f l u t t e r / ${ flutterVersion } / L I C E N S E " ;
sha256 = hashes . flutterNotice ;
} ;
installPhase =
''
SRC_TEXT = " $ ( c a t $ s r c ) "
FLUTTER_NOTICE_TEXT = " $ ( c a t $ f l u t t e r N o t i c e ) "
cat < < EOF > $ out
This artifact is from the Flutter SDK's engine .
This file carries third-party notices for its dependencies .
See also other files , that have LICENSE in the name , in the artifact directory .
Appendix 1/2 : merged sky_engine LICENSE file ( also found at $ { finalAttrs . src . url } )
$ SRC_TEXT
2023-04-29 16:46:19 +00:00
2023-08-22 20:05:09 +00:00
Appendix 2/2 : Flutter license ( also found at $ { finalAttrs . flutterNotice . url } )
$ FLUTTER_NOTICE_TEXT
EOF
'' ;
} ) ;
2023-04-29 16:46:19 +00:00
artifacts =
{
common = {
flutter_patched_sdk = { archive = " f l u t t e r _ p a t c h e d _ s d k . z i p " ; } ;
flutter_patched_sdk_product = { archive = " f l u t t e r _ p a t c h e d _ s d k _ p r o d u c t . z i p " ; } ;
} ;
platform = {
android =
( lib . genAttrs
[ " a r m " " a r m 6 4 " " x 6 4 " ]
( arch :
{
base = [
{ archive = " a r t i f a c t s . z i p " ; }
] ;
variants = lib . genAttrs [ " p r o f i l e " " r e l e a s e " ]
( variant : [
{ archive = " a r t i f a c t s . z i p " ; }
2023-05-24 13:37:59 +00:00
{ subdirectory = true ; archive = " ${ lib . toLower hostPlatform . uname . system } - x 6 4 . z i p " ; }
2023-04-29 16:46:19 +00:00
] ) ;
} ) ) //
{
" x 8 6 " = {
base = [
{ archive = " a r t i f a c t s . z i p " ; }
] ;
variants . jit-release = [
{ archive = " a r t i f a c t s . z i p " ; }
] ;
} ;
} ;
2023-07-15 17:15:38 +00:00
darwin = {
" a r m 6 4 " = {
base = [
{ archive = " a r t i f a c t s . z i p " ; }
{ archive = " f o n t - s u b s e t . z i p " ; }
] ;
variants = lib . genAttrs [ " p r o f i l e " " r e l e a s e " ]
( variant : [
{ archive = " a r t i f a c t s . z i p " ; }
] ) ;
} ;
" x 6 4 " = {
base = [
{ archive = " F l u t t e r E m b e d d e r . f r a m e w o r k . z i p " ; }
{ archive = " F l u t t e r M a c O S . f r a m e w o r k . z i p " ; }
{ archive = " a r t i f a c t s . z i p " ; }
{ archive = " f o n t - s u b s e t . z i p " ; }
{ archive = " g e n _ s n a p s h o t . z i p " ; }
] ;
variants . profile = [
{ archive = " F l u t t e r M a c O S . f r a m e w o r k . z i p " ; }
{ archive = " a r t i f a c t s . z i p " ; }
{ archive = " g e n _ s n a p s h o t . z i p " ; }
] ;
variants . release = [
{ archive = " F l u t t e r M a c O S . d S Y M . z i p " ; }
{ archive = " F l u t t e r M a c O S . f r a m e w o r k . z i p " ; }
{ archive = " a r t i f a c t s . z i p " ; }
{ archive = " g e n _ s n a p s h o t . z i p " ; }
] ;
} ;
} ;
ios =
( lib . genAttrs
[ " " ]
( arch :
{
base = [
{ archive = " a r t i f a c t s . z i p " ; }
] ;
variants . profile = [
{ archive = " a r t i f a c t s . z i p " ; }
] ;
variants . release = [
{ archive = " a r t i f a c t s . z i p " ; }
{ archive = " F l u t t e r . d S Y M . z i p " ; }
] ;
} ) ) ;
2023-04-29 16:46:19 +00:00
linux = lib . genAttrs
[ " a r m 6 4 " " x 6 4 " ]
( arch :
let
linux-flutter-gtk = {
archive = " l i n u x - ${ arch } - f l u t t e r - g t k . z i p " ;
buildInputs = [ gtk3 ] ;
} ;
in
{
base = [
( { archive = " a r t i f a c t s . z i p " ; } // lib . optionalAttrs ( arch == " a r m 6 4 " ) {
2023-05-24 13:37:59 +00:00
# For some reason, the arm64 artifacts are missing shader code in Flutter < 3.10.0.
2023-04-29 16:46:19 +00:00
postPatch = ''
2023-05-24 13:37:59 +00:00
if [ ! - d shader_lib ] ; then
ln - s $ { lib . findSingle
( pkg : lib . getName pkg == " f l u t t e r - a r t i f a c t - l i n u x - x 6 4 - a r t i f a c t s " )
( throw " C o u l d n o t f i n d t h e x 6 4 a r t i f a c t a r c h i v e . " )
( throw " C o u l d n o t f i n d t h e c o r r e c t x 6 4 a r t i f a c t a r c h i v e . " )
artifactDerivations . platform . linux . x64 . base
} /shader_lib .
2023-04-29 16:46:19 +00:00
fi
'' ;
} )
{ archive = " f o n t - s u b s e t . z i p " ; }
2023-05-24 13:37:59 +00:00
( linux-flutter-gtk // {
# https://github.com/flutter/flutter/commit/9d94a51b607600a39c14470c35c676eb3e30eed6
variant = " d e b u g " ;
} )
2023-04-29 16:46:19 +00:00
] ;
variants = lib . genAttrs [ " d e b u g " " p r o f i l e " " r e l e a s e " ] ( variant : [
linux-flutter-gtk
] ) ;
} ) ;
} ;
} ;
2023-05-24 13:37:59 +00:00
mkArtifactDerivation = { platform ? null , variant ? null , subdirectory ? null , archive , . . . } @ args :
2023-04-29 16:46:19 +00:00
let
artifactDirectory = if platform == null then null else " ${ platform } ${ lib . optionalString ( variant != null ) " - ${ variant } " } " ;
archiveBasename = lib . removeSuffix " . ${ ( lib . last ( lib . splitString " . " archive ) ) } " archive ;
2023-07-15 17:15:38 +00:00
overrideUnpackCmd = builtins . elem archive [ " F l u t t e r E m b e d d e r . f r a m e w o r k . z i p " " F l u t t e r M a c O S . f r a m e w o r k . z i p " ] ;
2023-04-29 16:46:19 +00:00
in
stdenv . mkDerivation ( {
pname = " f l u t t e r - a r t i f a c t ${ lib . optionalString ( platform != null ) " - ${ artifactDirectory } " } - ${ archiveBasename } " ;
version = engineVersion ;
2023-07-15 17:15:38 +00:00
nativeBuildInputs = [ unzip ]
++ lib . optionals stdenv . hostPlatform . isLinux [ autoPatchelfHook ] ;
src =
if overrideUnpackCmd then
( fetchurl {
url = " h t t p s : / / s t o r a g e . g o o g l e a p i s . c o m / f l u t t e r _ i n f r a _ r e l e a s e / f l u t t e r / ${ engineVersion } ${ lib . optionalString ( platform != null ) " / ${ artifactDirectory } " } / ${ archive } " ;
hash = ( if artifactDirectory == null then hashes else hashes . ${ artifactDirectory } ) . ${ archive } ;
} ) else
( fetchzip {
url = " h t t p s : / / s t o r a g e . g o o g l e a p i s . c o m / f l u t t e r _ i n f r a _ r e l e a s e / f l u t t e r / ${ engineVersion } ${ lib . optionalString ( platform != null ) " / ${ artifactDirectory } " } / ${ archive } " ;
stripRoot = false ;
hash = ( if artifactDirectory == null then hashes else hashes . ${ artifactDirectory } ) . ${ archive } ;
} ) ;
2023-04-29 16:46:19 +00:00
2023-10-09 19:29:22 +00:00
sourceRoot = if overrideUnpackCmd then " . " else null ;
2023-07-15 17:15:38 +00:00
unpackCmd = if overrideUnpackCmd then " u n z i p - o $ s r c - d $ o u t " else null ;
2023-04-29 16:46:19 +00:00
2023-05-24 13:37:59 +00:00
installPhase =
let
destination = " $ o u t / ${ if subdirectory == true then archiveBasename else if subdirectory != null then subdirectory else " . " } " ;
in
''
2023-08-22 20:05:09 +00:00
# ship the notice near all artifacts. if the artifact directory is / multiple directories are nested in $src, link it there. If there isn't a directory, link it in root
# this *isn't the same as the subdirectory variable above*
DIR_CNT = " $ ( e c h o * / | w c - w ) "
if [ [ " $ D I R _ C N T " == 0 ] ] ; then
ln - s $ { noticeText } LICENSE . README
else
for dir in * /
do
ln - s $ { noticeText } " $ d i r / L I C E N S E . R E A D M E "
done
fi
2023-05-24 13:37:59 +00:00
mkdir - p " ${ destination } "
cp - r . " ${ destination } "
'' ;
2023-04-29 16:46:19 +00:00
} // args ) ;
artifactDerivations = {
common = builtins . mapAttrs ( name : mkArtifactDerivation ) artifacts . common ;
platform =
builtins . mapAttrs
( os : architectures :
builtins . mapAttrs
( architecture : variants : {
base = map
( args : mkArtifactDerivation ( {
2023-07-15 17:15:38 +00:00
platform = " ${ os } ${ lib . optionalString ( architecture != " " ) " - ${ architecture } " } " ;
2023-04-29 16:46:19 +00:00
} // args ) )
variants . base ;
variants = builtins . mapAttrs
( variant : variantArtifacts : map
( args : mkArtifactDerivation ( {
2023-07-15 17:15:38 +00:00
platform = " ${ os } ${ lib . optionalString ( architecture != " " ) " - ${ architecture } " } " ;
2023-04-29 16:46:19 +00:00
inherit variant ;
} // args ) )
variantArtifacts )
variants . variants ;
} )
architectures )
artifacts . platform ;
} ;
in
artifactDerivations