1{
2 symlinkJoin,
3 makeWrapper,
4}:
5flutter:
6
7let
8 self = symlinkJoin {
9 name = "${flutter.name}-sdk-links";
10 paths = [
11 flutter
12 flutter.cacheDir
13 flutter.sdk
14 ];
15
16 nativeBuildInputs = [ makeWrapper ];
17 postBuild = ''
18 wrapProgram "$out/bin/flutter" \
19 --set-default FLUTTER_ROOT "$out"
20
21 # symlinkJoin seems to be missing the .git directory for some reason.
22 if [ -d '${flutter.sdk}/.git' ]; then
23 ln -s '${flutter.sdk}/.git' "$out"
24 fi
25
26 # For iOS/macOS builds, *.xcframework/'s from the pre-built
27 # artifacts are copied into each built app. However, the symlinkJoin
28 # means that the *.xcframework's contain symlinks into the nix store,
29 # which causes issues when actually running the apps.
30 #
31 # We'll fix this by only linking to an outer *.xcframework dir instead
32 # of trying to symlinkJoin the files inside the *.xcframework.
33 artifactsDir="$out/bin/cache/artifacts/engine"
34 shopt -s globstar
35 for file in "$artifactsDir"/**/*.xcframework/Info.plist; do
36 # Get the unwrapped path from the Info.plist inside each .xcframework
37 origFile="$(readlink -f "$file")"
38 origFrameworkDir="$(dirname "$origFile")"
39
40 # Remove the symlinkJoin .xcframework dir and replace it with a symlink
41 # to the unwrapped .xcframework dir.
42 frameworkDir="$(dirname "$file")"
43 rm -r "$frameworkDir"
44 ln -s "$origFrameworkDir" "$frameworkDir"
45 done
46 shopt -u globstar
47 '';
48
49 passthru = flutter.passthru // {
50 # Update the SDK attribute.
51 # This allows any modified SDK files to be included
52 # in future invocations.
53 sdk = self;
54 };
55
56 meta = flutter.meta // {
57 longDescription = ''
58 ${flutter.meta.longDescription}
59 Modified binaries are linked into the original SDK directory for use with tools that use the whole SDK.
60 '';
61 };
62 };
63in
64self