nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 lib,
3 callPackage,
4 curlMinimal,
5 pkg-config,
6 gitMinimal,
7 python312,
8 runCommand,
9 writeText,
10 cacert,
11 flutterVersion,
12 version,
13 hashes,
14 url,
15 hostPlatform,
16 targetPlatform,
17 buildPlatform,
18 ...
19}@pkgs:
20let
21 target-constants = callPackage ./constants.nix { platform = targetPlatform; };
22 build-constants = callPackage ./constants.nix { platform = buildPlatform; };
23 tools = pkgs.tools or (callPackage ./tools.nix { inherit hostPlatform buildPlatform; });
24
25 boolOption = value: if value then "True" else "False";
26
27 gclient = writeText "flutter-${version}.gclient" ''
28 solutions = [{
29 "managed": False,
30 "name": ".",
31 "url": "${url}",
32 "custom_vars": {
33 "download_fuchsia_deps": False,
34 "download_android_deps": False,
35 "download_linux_deps": ${boolOption targetPlatform.isLinux},
36 "setup_githooks": False,
37 "download_esbuild": False,
38 "download_dart_sdk": True,
39 "host_cpu": "${build-constants.alt-arch}",
40 "host_os": "${build-constants.alt-os}",
41 },
42 }]
43
44 target_os_only = True
45 target_os = [
46 "${target-constants.alt-os}"
47 ]
48
49 target_cpu_only = True
50 target_cpu = [
51 "${target-constants.alt-arch}"
52 ]
53 '';
54in
55runCommand "flutter-engine-source-${version}-${buildPlatform.system}-${targetPlatform.system}"
56 {
57 pname = "flutter-engine-source";
58 inherit version;
59
60 nativeBuildInputs = [
61 curlMinimal
62 pkg-config
63 gitMinimal
64 tools.cipd
65 (python312.withPackages (
66 ps: with ps; [
67 httplib2
68 six
69 ]
70 ))
71 ];
72
73 env = {
74 NIX_SSL_CERT_FILE = "${cacert}/etc/ssl/certs/ca-bundle.crt";
75 GIT_SSL_CAINFO = "${cacert}/etc/ssl/certs/ca-bundle.crt";
76 SSL_CERT_FILE = "${cacert}/etc/ssl/certs/ca-bundle.crt";
77 DEPOT_TOOLS_UPDATE = "0";
78 DEPOT_TOOLS_COLLECT_METRICS = "0";
79 PYTHONDONTWRITEBYTECODE = "1";
80 };
81
82 outputHashAlgo = "sha256";
83 outputHashMode = "recursive";
84 outputHash =
85 (hashes."${buildPlatform.system}" or { })."${targetPlatform.system}"
86 or (throw "Hash not set for ${targetPlatform.system} on ${buildPlatform.system}");
87 }
88 ''
89 source ${../../../../build-support/fetchgit/deterministic-git}
90 export -f clean_git
91 export -f make_deterministic_repo
92
93 mkdir --parents flutter
94 cp ${gclient} flutter/.gclient
95 cd flutter
96 export PATH=$PATH:${tools.depot_tools}
97 python3 ${tools.depot_tools}/gclient.py sync --no-history --shallow --nohooks -j $NIX_BUILD_CORES
98 mv engine $out
99
100 find $out -name '.git' -exec rm --recursive --force {} \; || true
101
102 rm --recursive $out/src/flutter/{buildtools,prebuilts,third_party/swiftshader,third_party/gn/.versions,third_party/dart/tools/sdks/dart-sdk}
103 ''