at 25.11-pre 208 lines 6.7 kB view raw
1{ 2 useNixpkgsEngine ? false, 3 version, 4 engineVersion, 5 engineHashes ? { }, 6 engineUrl ? 7 if lib.versionAtLeast version "3.29" then 8 "https://github.com/flutter/flutter.git@${engineVersion}" 9 else 10 "https://github.com/flutter/engine.git@${engineVersion}", 11 enginePatches ? [ ], 12 engineRuntimeModes ? [ 13 "release" 14 "debug" 15 ], 16 engineSwiftShaderHash, 17 engineSwiftShaderRev, 18 patches, 19 channel, 20 dart, 21 src, 22 pubspecLock, 23 artifactHashes ? null, 24 lib, 25 stdenv, 26 callPackage, 27 makeWrapper, 28 darwin, 29 gitMinimal, 30 which, 31 jq, 32 flutterTools ? null, 33}@args: 34 35let 36 engine = 37 if args.useNixpkgsEngine or false then 38 callPackage ./engine/default.nix { 39 inherit (args) dart; 40 dartSdkVersion = args.dart.version; 41 flutterVersion = version; 42 swiftshaderRev = engineSwiftShaderRev; 43 swiftshaderHash = engineSwiftShaderHash; 44 version = engineVersion; 45 hashes = engineHashes; 46 url = engineUrl; 47 patches = enginePatches; 48 runtimeModes = engineRuntimeModes; 49 } 50 else 51 null; 52 53 dart = if args.useNixpkgsEngine or false then engine.dart else args.dart; 54 55 flutterTools = 56 args.flutterTools or (callPackage ./flutter-tools.nix { 57 inherit dart version; 58 flutterSrc = src; 59 inherit patches; 60 inherit pubspecLock; 61 systemPlatform = stdenv.hostPlatform.system; 62 }); 63 64 unwrapped = stdenv.mkDerivation { 65 name = "flutter-${version}-unwrapped"; 66 inherit src patches version; 67 68 nativeBuildInputs = [ 69 makeWrapper 70 jq 71 gitMinimal 72 ] ++ lib.optionals stdenv.hostPlatform.isDarwin [ darwin.DarwinTools ]; 73 strictDeps = true; 74 75 preConfigure = '' 76 if [ "$(< bin/internal/engine.version)" != '${engineVersion}' ]; then 77 echo 1>&2 "The given engine version (${engineVersion}) does not match the version required by the Flutter SDK ($(< bin/internal/engine.version))." 78 exit 1 79 fi 80 ''; 81 82 postPatch = '' 83 patchShebangs --build ./bin/ 84 patchShebangs packages/flutter_tools/bin 85 ''; 86 87 buildPhase = '' 88 # The flutter_tools package tries to run many Git commands. In most 89 # cases, unexpected output is handled gracefully, but commands are never 90 # expected to fail completely. A blank repository needs to be created. 91 rm -rf .git # Remove any existing Git directory 92 git init -b nixpkgs 93 GIT_AUTHOR_NAME=Nixpkgs GIT_COMMITTER_NAME=Nixpkgs \ 94 GIT_AUTHOR_EMAIL= GIT_COMMITTER_EMAIL= \ 95 GIT_AUTHOR_DATE='1/1/1970 00:00:00 +0000' GIT_COMMITTER_DATE='1/1/1970 00:00:00 +0000' \ 96 git commit --allow-empty -m "Initial commit" 97 (. '${../../../build-support/fetchgit/deterministic-git}'; make_deterministic_repo .) 98 99 mkdir -p bin/cache 100 101 # Add a flutter_tools artifact stamp, and build a snapshot. 102 # This is the Flutter CLI application. 103 echo "$(git rev-parse HEAD)" > bin/cache/flutter_tools.stamp 104 ln -s '${flutterTools}/share/flutter_tools.snapshot' bin/cache/flutter_tools.snapshot 105 106 # Some of flutter_tools's dependencies contain static assets. The 107 # application attempts to read its own package_config.json to find these 108 # assets at runtime. 109 mkdir -p packages/flutter_tools/.dart_tool 110 ln -s '${flutterTools.pubcache}/package_config.json' packages/flutter_tools/.dart_tool/package_config.json 111 112 echo -n "${version}" > version 113 cat <<EOF > bin/cache/flutter.version.json 114 { 115 "devToolsVersion": "$(cat "${dart}/bin/resources/devtools/version.json" | jq -r .version)", 116 "flutterVersion": "${version}", 117 "frameworkVersion": "${version}", 118 "channel": "${channel}", 119 "repositoryUrl": "https://github.com/flutter/flutter.git", 120 "frameworkRevision": "nixpkgs000000000000000000000000000000000", 121 "frameworkCommitDate": "1970-01-01 00:00:00", 122 "engineRevision": "${engineVersion}", 123 "dartSdkVersion": "${dart.version}" 124 } 125 EOF 126 127 # Suppress a small error now that `.gradle`'s location changed. 128 # Location changed because of the patch "gradle-flutter-tools-wrapper.patch". 129 mkdir -p "$out/packages/flutter_tools/gradle/.gradle" 130 ''; 131 132 installPhase = '' 133 runHook preInstall 134 135 mkdir -p $out 136 cp -r . $out 137 rm -rf $out/bin/cache/dart-sdk 138 ln -sf ${dart} $out/bin/cache/dart-sdk 139 140 # The regular launchers are designed to download/build/update SDK 141 # components, and are not very useful in Nix. 142 # Replace them with simple links and wrappers. 143 rm "$out/bin"/{dart,flutter} 144 ln -s "$out/bin/cache/dart-sdk/bin/dart" "$out/bin/dart" 145 makeShellWrapper "$out/bin/dart" "$out/bin/flutter" \ 146 --set-default FLUTTER_ROOT "$out" \ 147 --set FLUTTER_ALREADY_LOCKED true \ 148 --add-flags "--disable-dart-dev --packages='${flutterTools.pubcache}/package_config.json' \$NIX_FLUTTER_TOOLS_VM_OPTIONS $out/bin/cache/flutter_tools.snapshot" 149 150 runHook postInstall 151 ''; 152 153 doInstallCheck = true; 154 nativeInstallCheckInputs = [ 155 which 156 ] ++ lib.optionals stdenv.hostPlatform.isDarwin [ darwin.DarwinTools ]; 157 installCheckPhase = '' 158 runHook preInstallCheck 159 160 export HOME="$(mktemp -d)" 161 $out/bin/flutter config --android-studio-dir $HOME 162 $out/bin/flutter config --android-sdk $HOME 163 $out/bin/flutter --version | fgrep -q '${builtins.substring 0 10 engineVersion}' 164 165 runHook postInstallCheck 166 ''; 167 168 passthru = 169 { 170 # TODO: rely on engine.version instead of engineVersion 171 inherit 172 dart 173 engineVersion 174 artifactHashes 175 channel 176 ; 177 tools = flutterTools; 178 # The derivation containing the original Flutter SDK files. 179 # When other derivations wrap this one, any unmodified files 180 # found here should be included as-is, for tooling compatibility. 181 sdk = unwrapped; 182 } 183 // lib.optionalAttrs (engine != null) { 184 inherit engine; 185 }; 186 187 meta = with lib; { 188 description = "Flutter is Google's SDK for building mobile, web and desktop with Dart"; 189 longDescription = '' 190 Flutter is Googles UI toolkit for building beautiful, 191 natively compiled applications for mobile, web, and desktop from a single codebase. 192 ''; 193 homepage = "https://flutter.dev"; 194 license = licenses.bsd3; 195 platforms = [ 196 "x86_64-linux" 197 "aarch64-linux" 198 "x86_64-darwin" 199 "aarch64-darwin" 200 ]; 201 maintainers = with maintainers; [ 202 ericdallo 203 ]; 204 teams = [ teams.flutter ]; 205 }; 206 }; 207in 208unwrapped