at master 6.8 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 58 dart 59 engineVersion 60 patches 61 pubspecLock 62 version 63 ; 64 flutterSrc = src; 65 systemPlatform = stdenv.hostPlatform.system; 66 }); 67 68 unwrapped = stdenv.mkDerivation { 69 name = "flutter-${version}-unwrapped"; 70 inherit src patches version; 71 72 nativeBuildInputs = [ 73 makeWrapper 74 jq 75 gitMinimal 76 ] 77 ++ lib.optionals stdenv.hostPlatform.isDarwin [ darwin.DarwinTools ]; 78 strictDeps = true; 79 80 preConfigure = '' 81 if [ "$(< bin/internal/engine.version)" != '${engineVersion}' ]; then 82 echo 1>&2 "The given engine version (${engineVersion}) does not match the version required by the Flutter SDK ($(< bin/internal/engine.version))." 83 exit 1 84 fi 85 ''; 86 87 postPatch = '' 88 patchShebangs --build ./bin/ 89 patchShebangs packages/flutter_tools/bin 90 ''; 91 92 buildPhase = '' 93 # The flutter_tools package tries to run many Git commands. In most 94 # cases, unexpected output is handled gracefully, but commands are never 95 # expected to fail completely. A blank repository needs to be created. 96 rm -rf .git # Remove any existing Git directory 97 git init -b nixpkgs 98 GIT_AUTHOR_NAME=Nixpkgs GIT_COMMITTER_NAME=Nixpkgs \ 99 GIT_AUTHOR_EMAIL= GIT_COMMITTER_EMAIL= \ 100 GIT_AUTHOR_DATE='1/1/1970 00:00:00 +0000' GIT_COMMITTER_DATE='1/1/1970 00:00:00 +0000' \ 101 git commit --allow-empty -m "Initial commit" 102 (. '${../../../build-support/fetchgit/deterministic-git}'; make_deterministic_repo .) 103 104 mkdir -p bin/cache 105 106 # Add a flutter_tools artifact stamp, and build a snapshot. 107 # This is the Flutter CLI application. 108 echo "$(git rev-parse HEAD)" > bin/cache/flutter_tools.stamp 109 ln -s '${flutterTools}/share/flutter_tools.snapshot' bin/cache/flutter_tools.snapshot 110 111 # Some of flutter_tools's dependencies contain static assets. The 112 # application attempts to read its own package_config.json to find these 113 # assets at runtime. 114 mkdir -p packages/flutter_tools/.dart_tool 115 ln -s '${flutterTools.pubcache}/package_config.json' packages/flutter_tools/.dart_tool/package_config.json 116 117 echo -n "${version}" > version 118 cat <<EOF > bin/cache/flutter.version.json 119 { 120 "devToolsVersion": "$(cat "${dart}/bin/resources/devtools/version.json" | jq -r .version)", 121 "flutterVersion": "${version}", 122 "frameworkVersion": "${version}", 123 "channel": "${channel}", 124 "repositoryUrl": "https://github.com/flutter/flutter.git", 125 "frameworkRevision": "nixpkgs000000000000000000000000000000000", 126 "frameworkCommitDate": "1970-01-01 00:00:00", 127 "engineRevision": "${engineVersion}", 128 "dartSdkVersion": "${dart.version}" 129 } 130 EOF 131 132 # Suppress a small error now that `.gradle`'s location changed. 133 # Location changed because of the patch "gradle-flutter-tools-wrapper.patch". 134 mkdir -p "$out/packages/flutter_tools/gradle/.gradle" 135 ''; 136 137 installPhase = '' 138 runHook preInstall 139 140 mkdir -p $out 141 cp -r . $out 142 rm -rf $out/bin/cache/dart-sdk 143 ln -sf ${dart} $out/bin/cache/dart-sdk 144 145 # The regular launchers are designed to download/build/update SDK 146 # components, and are not very useful in Nix. 147 # Replace them with simple links and wrappers. 148 rm "$out/bin"/{dart,flutter} 149 ln -s "$out/bin/cache/dart-sdk/bin/dart" "$out/bin/dart" 150 makeShellWrapper "$out/bin/dart" "$out/bin/flutter" \ 151 --set-default FLUTTER_ROOT "$out" \ 152 --set FLUTTER_ALREADY_LOCKED true \ 153 --add-flags "--disable-dart-dev --packages='${flutterTools.pubcache}/package_config.json' \$NIX_FLUTTER_TOOLS_VM_OPTIONS $out/bin/cache/flutter_tools.snapshot" 154 155 runHook postInstall 156 ''; 157 158 doInstallCheck = true; 159 nativeInstallCheckInputs = [ 160 which 161 ] 162 ++ lib.optionals stdenv.hostPlatform.isDarwin [ darwin.DarwinTools ]; 163 installCheckPhase = '' 164 runHook preInstallCheck 165 166 export HOME="$(mktemp -d)" 167 $out/bin/flutter config --android-studio-dir $HOME 168 $out/bin/flutter config --android-sdk $HOME 169 $out/bin/flutter --version | fgrep -q '${builtins.substring 0 10 engineVersion}' 170 171 runHook postInstallCheck 172 ''; 173 174 passthru = { 175 # TODO: rely on engine.version instead of engineVersion 176 inherit 177 dart 178 engineVersion 179 artifactHashes 180 channel 181 ; 182 tools = flutterTools; 183 # The derivation containing the original Flutter SDK files. 184 # When other derivations wrap this one, any unmodified files 185 # found here should be included as-is, for tooling compatibility. 186 sdk = unwrapped; 187 } 188 // lib.optionalAttrs (engine != null) { 189 inherit engine; 190 }; 191 192 meta = { 193 broken = (lib.versionOlder version "3.32") && useNixpkgsEngine; 194 description = "Makes it easy and fast to build beautiful apps for mobile and beyond"; 195 longDescription = '' 196 Flutter is Google's SDK for crafting beautiful, 197 fast user experiences for mobile, web, and desktop from a single codebase. 198 ''; 199 homepage = "https://flutter.dev"; 200 license = lib.licenses.bsd3; 201 platforms = [ 202 "x86_64-linux" 203 "aarch64-linux" 204 "x86_64-darwin" 205 "aarch64-darwin" 206 ]; 207 mainProgram = "flutter"; 208 maintainers = with lib.maintainers; [ 209 ericdallo 210 ]; 211 teams = [ lib.teams.flutter ]; 212 }; 213 }; 214in 215unwrapped