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