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