flutter: Reorganize the wrapper code

+50 -33
+50 -33
pkgs/development/compilers/flutter/wrapper.nix
··· 23 }: 24 25 let 26 - linuxDesktopRuntimeDeps = [ 27 atk 28 cairo 29 gdk-pixbuf ··· 36 (callPackage ./packages/libdeflate { }) 37 ]; 38 39 - linuxDesktopBuildDeps = let 40 - # https://discourse.nixos.org/t/handling-transitive-c-dependencies/5942/3 41 - deps = pkg: builtins.filter lib.isDerivation ((pkg.buildInputs or [ ]) ++ (pkg.propagatedBuildInputs or [ ])); 42 - collect = pkg: lib.unique ([ pkg ] ++ deps pkg ++ builtins.concatMap collect (deps pkg)); 43 - in builtins.concatMap collect linuxDesktopRuntimeDeps; 44 in 45 runCommandLocal "flutter" 46 { 47 - flutterWithCorrectedCache = writeShellScript "flutter_corrected_cache" '' 48 - export PUB_CACHE=''${PUB_CACHE:-"$HOME/.pub-cache"} 49 - ${flutter}/bin/flutter "$@" 50 - ''; 51 - 52 buildInputs = [ makeWrapper ]; 53 54 passthru = flutter.passthru // { ··· 62 mkdir -p $out/bin/cache/ 63 ln -sf ${flutter.dart} $out/bin/cache/dart-sdk 64 65 - makeWrapper "$flutterWithCorrectedCache" $out/bin/flutter \ 66 - --set-default ANDROID_EMULATOR_USE_SYSTEM_LIBS 1 \ 67 - --prefix PATH : '${lib.makeBinPath (lib.optionals supportsLinuxDesktop [ 68 - pkg-config 69 - cmake 70 - ninja 71 - clang 72 - ])}' \ 73 - --prefix PKG_CONFIG_PATH : '${ 74 - let 75 - makePkgConfigSearchPath = pkgs: builtins.concatStringsSep ":" (builtins.filter builtins.pathExists (builtins.concatMap (pkg: map (dir: "${lib.getOutput "dev" pkg}/${dir}/pkgconfig") [ "lib" "share" ]) pkgs)); 76 - in makePkgConfigSearchPath linuxDesktopBuildDeps}' \ 77 - --prefix CXXFLAGS "''\t" '${lib.optionalString supportsLinuxDesktop "-isystem ${libX11.dev}/include -isystem ${xorgproto}/include"}' \ 78 - ${let linkerFlags = map (pkg: "-rpath,${lib.getOutput "lib" pkg}/lib") (lib.optionals supportsLinuxDesktop linuxDesktopRuntimeDeps); in '' 79 - --prefix LDFLAGS "''\t" '${builtins.concatStringsSep " " (map (flag: "-Wl,${flag}") linkerFlags)}' \ 80 - ''} \ 81 - --suffix LD_LIBRARY_PATH : '${lib.optionalString supportsLinuxDesktop (lib.makeLibraryPath [ 82 - # The prebuilt flutter_linux_gtk library shipped in the Flutter SDK does not have an appropriate RUNPATH. 83 - # Its dependencies must be added here. 84 - libepoxy 85 - ])}' \ 86 - --add-flags --no-version-check 87 ''
··· 23 }: 24 25 let 26 + # By default, Flutter stores downloaded files (such as the Pub cache) in the SDK directory. 27 + # Wrap it to ensure that it does not do that, preferring home directories instead. 28 + immutableFlutter = writeShellScript "flutter_immutable" '' 29 + export PUB_CACHE=''${PUB_CACHE:-"$HOME/.pub-cache"} 30 + ${flutter}/bin/flutter --no-version-check "$@" 31 + ''; 32 + 33 + # Libraries that Flutter apps depend on at runtime. 34 + appRuntimeDeps = lib.optionals supportsLinuxDesktop [ 35 atk 36 cairo 37 gdk-pixbuf ··· 44 (callPackage ./packages/libdeflate { }) 45 ]; 46 47 + # Development packages required for compilation. 48 + appBuildDeps = 49 + let 50 + # https://discourse.nixos.org/t/handling-transitive-c-dependencies/5942/3 51 + deps = pkg: builtins.filter lib.isDerivation ((pkg.buildInputs or [ ]) ++ (pkg.propagatedBuildInputs or [ ])); 52 + collect = pkg: lib.unique ([ pkg ] ++ deps pkg ++ builtins.concatMap collect (deps pkg)); 53 + in 54 + builtins.concatMap collect appRuntimeDeps; 55 + 56 + # Some header files are not properly located by the Flutter SDK. 57 + # They must be manually included. 58 + appStaticBuildDeps = lib.optionals supportsLinuxDesktop [ libX11 xorgproto ]; 59 + 60 + # Some runtime components are prebuilt, and do not know where to find their dependencies. 61 + # Ideally, these prebuilt components would be patched by the SDK derivation, but this 62 + # is tricky as they are tyically downloaded from Google on-demand. 63 + # Building the Engine manually should solve this issue: https://github.com/NixOS/nixpkgs/issues/201574 64 + appPrebuiltDeps = lib.optionals supportsLinuxDesktop [ 65 + # flutter_linux_gtk.so 66 + libepoxy 67 + ]; 68 + 69 + # Tools used by the Flutter SDK to compile applications. 70 + buildTools = lib.optionals supportsLinuxDesktop [ 71 + pkg-config 72 + cmake 73 + ninja 74 + clang 75 + ]; 76 + 77 + # Nix-specific compiler configuration. 78 + pkgConfigDirectories = builtins.filter builtins.pathExists (builtins.concatMap (pkg: map (dir: "${lib.getOutput "dev" pkg}/${dir}/pkgconfig") [ "lib" "share" ]) appBuildDeps); 79 + cppFlags = map (pkg: "-isystem ${lib.getOutput "dev" pkg}/include") appStaticBuildDeps; 80 + linkerFlags = map (pkg: "-rpath,${lib.getOutput "lib" pkg}/lib") appRuntimeDeps; 81 in 82 runCommandLocal "flutter" 83 { 84 buildInputs = [ makeWrapper ]; 85 86 passthru = flutter.passthru // { ··· 94 mkdir -p $out/bin/cache/ 95 ln -sf ${flutter.dart} $out/bin/cache/dart-sdk 96 97 + makeWrapper '${immutableFlutter}' $out/bin/flutter \ 98 + --set-default ANDROID_EMULATOR_USE_SYSTEM_LIBS 1 \ 99 + --prefix PATH : '${lib.makeBinPath buildTools}' \ 100 + --prefix PKG_CONFIG_PATH : '${builtins.concatStringsSep ":" pkgConfigDirectories}' \ 101 + --prefix CXXFLAGS "''\t" '${builtins.concatStringsSep " " cppFlags}' \ 102 + --prefix LDFLAGS "''\t" '${builtins.concatStringsSep " " (map (flag: "-Wl,${flag}") linkerFlags)}' \ 103 + --suffix LD_LIBRARY_PATH : '${lib.makeLibraryPath appPrebuiltDeps}' 104 ''