Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
1{ 2 lib, 3 stdenv, 4 systemPlatform, 5 buildDartApplication, 6 runCommand, 7 git, 8 which, 9 dart, 10 version, 11 flutterSrc, 12 patches ? [ ], 13 pubspecLock, 14}: 15 16buildDartApplication.override { inherit dart; } rec { 17 pname = "flutter-tools"; 18 inherit version; 19 dartOutputType = "jit-snapshot"; 20 21 src = flutterSrc; 22 sourceRoot = "${src.name}/packages/flutter_tools"; 23 postUnpack = ''chmod -R u+w "$NIX_BUILD_TOP/source"''; 24 25 inherit patches; 26 # The given patches are made for the entire SDK source tree. 27 prePatch = ''pushd "$NIX_BUILD_TOP/source"''; 28 postPatch = '' 29 popd 30 '' 31 # Use arm64 instead of arm64e. 32 + lib.optionalString stdenv.hostPlatform.isDarwin '' 33 substituteInPlace lib/src/ios/xcodeproj.dart \ 34 --replace-fail arm64e arm64 35 ''; 36 37 # When the JIT snapshot is being built, the application needs to run. 38 # It attempts to generate configuration files, and relies on a few external 39 # tools. 40 nativeBuildInputs = [ 41 git 42 which 43 ]; 44 preConfigure = '' 45 export HOME=. 46 export FLUTTER_ROOT="$NIX_BUILD_TOP/source" 47 mkdir -p "$FLUTTER_ROOT/bin/cache" 48 ln -s '${dart}' "$FLUTTER_ROOT/bin/cache/dart-sdk" 49 ''; 50 51 dartEntryPoints."flutter_tools.snapshot" = "bin/flutter_tools.dart"; 52 dartCompileFlags = [ "--define=NIX_FLUTTER_HOST_PLATFORM=${systemPlatform}" ]; 53 54 # The Dart wrapper launchers are useless for the Flutter tool - it is designed 55 # to be launched from a snapshot by the SDK. 56 postInstall = '' 57 pushd "$out" 58 rm ${builtins.concatStringsSep " " (builtins.attrNames dartEntryPoints)} 59 popd 60 ''; 61 62 sdkSourceBuilders = { 63 # https://github.com/dart-lang/pub/blob/e1fbda73d1ac597474b82882ee0bf6ecea5df108/lib/src/sdk/dart.dart#L80 64 "dart" = 65 name: 66 runCommand "dart-sdk-${name}" { passthru.packageRoot = "."; } '' 67 for path in '${dart}/pkg/${name}'; do 68 if [ -d "$path" ]; then 69 ln -s "$path" "$out" 70 break 71 fi 72 done 73 74 if [ ! -e "$out" ]; then 75 echo 1>&2 'The Dart SDK does not contain the requested package: ${name}!' 76 exit 1 77 fi 78 ''; 79 }; 80 81 inherit pubspecLock; 82}