Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at flake-libs 83 lines 2.2 kB view raw
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 '' 30 popd 31 '' 32 # Use arm64 instead of arm64e. 33 + lib.optionalString stdenv.hostPlatform.isDarwin '' 34 substituteInPlace lib/src/ios/xcodeproj.dart \ 35 --replace-fail arm64e arm64 36 ''; 37 38 # When the JIT snapshot is being built, the application needs to run. 39 # It attempts to generate configuration files, and relies on a few external 40 # tools. 41 nativeBuildInputs = [ 42 git 43 which 44 ]; 45 preConfigure = '' 46 export HOME=. 47 export FLUTTER_ROOT="$NIX_BUILD_TOP/source" 48 mkdir -p "$FLUTTER_ROOT/bin/cache" 49 ln -s '${dart}' "$FLUTTER_ROOT/bin/cache/dart-sdk" 50 ''; 51 52 dartEntryPoints."flutter_tools.snapshot" = "bin/flutter_tools.dart"; 53 dartCompileFlags = [ "--define=NIX_FLUTTER_HOST_PLATFORM=${systemPlatform}" ]; 54 55 # The Dart wrapper launchers are useless for the Flutter tool - it is designed 56 # to be launched from a snapshot by the SDK. 57 postInstall = '' 58 pushd "$out" 59 rm ${builtins.concatStringsSep " " (builtins.attrNames dartEntryPoints)} 60 popd 61 ''; 62 63 sdkSourceBuilders = { 64 # https://github.com/dart-lang/pub/blob/e1fbda73d1ac597474b82882ee0bf6ecea5df108/lib/src/sdk/dart.dart#L80 65 "dart" = 66 name: 67 runCommand "dart-sdk-${name}" { passthru.packageRoot = "."; } '' 68 for path in '${dart}/pkg/${name}'; do 69 if [ -d "$path" ]; then 70 ln -s "$path" "$out" 71 break 72 fi 73 done 74 75 if [ ! -e "$out" ]; then 76 echo 1>&2 'The Dart SDK does not contain the requested package: ${name}!' 77 exit 1 78 fi 79 ''; 80 }; 81 82 inherit pubspecLock; 83}