Skip to content

Commit

Permalink
flutter: prevent built iOS/macOS apps from containing links to nix store
Browse files Browse the repository at this point in the history
  • Loading branch information
phlip9 committed Sep 12, 2024
1 parent 492e603 commit 8ab57ce
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
4 changes: 2 additions & 2 deletions pkgs/development/compilers/flutter/default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ useNixpkgsEngine ? false, callPackage, fetchzip, fetchFromGitHub, dart, lib, stdenv }@args:
{ useNixpkgsEngine ? false, callPackage, fetchzip, fetchFromGitHub, dart, lib, stdenv }:
let
mkCustomFlutter = args: callPackage ./flutter.nix args;
wrapFlutter = flutter: callPackage ./wrapper.nix { inherit flutter; };
Expand All @@ -19,7 +19,7 @@ let
, pubspecLock
, artifactHashes
, channel
}@fargs:
}:
let
args = {
inherit version engineVersion engineSwiftShaderRev engineSwiftShaderHash engineHashes enginePatches patches pubspecLock artifactHashes useNixpkgsEngine channel;
Expand Down
22 changes: 22 additions & 0 deletions pkgs/development/compilers/flutter/sdk-symlink.nix
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,28 @@ let
if [ -d '${flutter.sdk}/.git' ]; then
ln -s '${flutter.sdk}/.git' "$out"
fi
# For iOS/macOS builds, *.xcframework/'s from the pre-built
# artifacts are copied into each built app. However, the symlinkJoin
# means that the *.xcframework's contain symlinks into the nix store,
# which causes issues when actually running the apps.
#
# We'll fix this by only linking to an outer *.xcframework dir instead
# of trying to symlinkJoin the files inside the *.xcframework.
artifactsDir="$out/bin/cache/artifacts/engine"
shopt -s globstar
for file in "$artifactsDir"/**/*.xcframework/Info.plist; do
# Get the unwrapped path from the Info.plist inside each .xcframework
origFile="$(readlink -f "$file")"
origFrameworkDir="$(dirname "$origFile")"
# Remove the symlinkJoin .xcframework dir and replace it with a symlink
# to the unwrapped .xcframework dir.
frameworkDir="$(dirname "$file")"
rm -r "$frameworkDir"
ln -s "$origFrameworkDir" "$frameworkDir"
done
shopt -u globstar
'';

passthru = flutter.passthru // {
Expand Down
4 changes: 1 addition & 3 deletions pkgs/development/compilers/flutter/wrapper.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
, extraCFlags ? [ ]
, extraLinkerFlags ? [ ]
, makeWrapper
, runCommandLocal
, writeShellScript
, wrapGAppsHook3
, git
Expand All @@ -39,7 +38,6 @@
, cmake
, ninja
, clang
, lndir
, symlinkJoin
}:

Expand All @@ -56,7 +54,7 @@ let
};
}));

cacheDir = symlinkJoin rec {
cacheDir = symlinkJoin {
name = "flutter-cache-dir";
paths = builtins.attrValues flutterPlatformArtifacts;
postBuild = ''
Expand Down

0 comments on commit 8ab57ce

Please sign in to comment.