nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1# Schema:
2# ${flutterVersion}.${targetPlatform}.${hostPlatform}
3#
4# aarch64-darwin as a host is not yet supported.
5# https://github.com/flutter/flutter/issues/60118
6{
7 lib,
8 runCommand,
9 lndir,
10 cacert,
11 unzip,
12
13 flutterPlatform,
14 systemPlatform,
15 flutter,
16 hash,
17}:
18
19let
20 flutterPlatforms = [
21 "android"
22 "ios"
23 "web"
24 "linux"
25 "windows"
26 "macos"
27 "fuchsia"
28 "universal"
29 ];
30
31 flutter' = flutter.override {
32 # Use a version of Flutter with just enough capabilities to download
33 # artifacts.
34 supportedTargetFlutterPlatforms = [ ];
35
36 # Modify flutter-tool's system platform in order to get the desired platform's hashes.
37 flutter = flutter.unwrapped.override {
38 flutterTools = flutter.unwrapped.tools.override {
39 inherit systemPlatform;
40 };
41 };
42 };
43in
44runCommand "flutter-artifacts-${flutterPlatform}-${systemPlatform}"
45 {
46 nativeBuildInputs = [
47 lndir
48 flutter'
49 unzip
50 ];
51
52 NIX_FLUTTER_TOOLS_VM_OPTIONS = "--root-certs-file=${cacert}/etc/ssl/certs/ca-bundle.crt";
53 NIX_FLUTTER_OPERATING_SYSTEM =
54 {
55 "x86_64-linux" = "linux";
56 "aarch64-linux" = "linux";
57 "x86_64-darwin" = "macos";
58 "aarch64-darwin" = "macos";
59 }
60 .${systemPlatform};
61
62 outputHash = hash;
63 outputHashMode = "recursive";
64 outputHashAlgo = "sha256";
65
66 passthru = {
67 inherit flutterPlatform;
68 };
69 }
70 (
71 ''
72 export FLUTTER_ROOT="$NIX_BUILD_TOP"
73 lndir -silent '${flutter'}' "$FLUTTER_ROOT"
74 rm --recursive --force "$FLUTTER_ROOT/bin/cache"
75 mkdir "$FLUTTER_ROOT/bin/cache"
76 mkdir "$FLUTTER_ROOT/bin/cache/dart-sdk"
77 lndir -silent '${flutter'}/bin/cache/dart-sdk' "$FLUTTER_ROOT/bin/cache/dart-sdk"
78 ''
79 # Could not determine engine revision
80 + lib.optionalString (lib.versionAtLeast flutter'.version "3.32") ''
81 cp '${flutter'}/bin/internal/engine.version' "$FLUTTER_ROOT/bin/cache/engine.stamp"
82 ''
83 + ''
84
85 HOME="$(mktemp -d)" flutter precache ${
86 lib.optionalString (
87 flutter ? engine && flutter.engine.meta.available
88 ) "--local-engine ${flutter.engine.outName}"
89 } \
90 --verbose '--${flutterPlatform}' ${
91 builtins.concatStringsSep " " (map (p: "'--no-${p}'") (lib.remove flutterPlatform flutterPlatforms))
92 }
93
94 rm --recursive --force "$FLUTTER_ROOT/bin/cache/lockfile"
95 rm --recursive --force "$FLUTTER_ROOT/bin/cache/dart-sdk"
96 ''
97 + ''
98 find "$FLUTTER_ROOT" -type l -lname '${flutter'}/*' -delete
99
100 cp --recursive bin/cache "$out"
101 ''
102 )