summaryrefslogtreecommitdiff
path: root/pkgs/development/compilers/flutter/engine/source.nix
blob: e95828c0b8ab6c6b5bf2fe275645817832a04454 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
{
  lib,
  callPackage,
  curlMinimal,
  pkg-config,
  gitMinimal,
  python312,
  runCommand,
  writeText,
  cacert,
  flutterVersion,
  version,
  hashes,
  url,
  hostPlatform,
  targetPlatform,
  buildPlatform,
  ...
}@pkgs:
let
  target-constants = callPackage ./constants.nix { platform = targetPlatform; };
  build-constants = callPackage ./constants.nix { platform = buildPlatform; };
  tools = pkgs.tools or (callPackage ./tools.nix { inherit hostPlatform buildPlatform; });

  boolOption = value: if value then "True" else "False";

  gclient = writeText "flutter-${version}.gclient" ''
    solutions = [{
      "managed": False,
      "name": ".",
      "url": "${url}",
      "custom_vars": {
        "download_fuchsia_deps": False,
        "download_android_deps": False,
        "download_linux_deps": ${boolOption targetPlatform.isLinux},
        "setup_githooks": False,
        "download_esbuild": False,
        "download_dart_sdk": True,
        "host_cpu": "${build-constants.alt-arch}",
        "host_os": "${build-constants.alt-os}",
      },
    }]

    target_os_only = True
    target_os = [
      "${target-constants.alt-os}"
    ]

    target_cpu_only = True
    target_cpu = [
      "${target-constants.alt-arch}"
    ]
  '';
in
runCommand "flutter-engine-source-${version}-${buildPlatform.system}-${targetPlatform.system}"
  {
    pname = "flutter-engine-source";
    inherit version;

    nativeBuildInputs = [
      curlMinimal
      pkg-config
      gitMinimal
      tools.cipd
      (python312.withPackages (
        ps: with ps; [
          httplib2
          six
        ]
      ))
    ];

    env = {
      NIX_SSL_CERT_FILE = "${cacert}/etc/ssl/certs/ca-bundle.crt";
      GIT_SSL_CAINFO = "${cacert}/etc/ssl/certs/ca-bundle.crt";
      SSL_CERT_FILE = "${cacert}/etc/ssl/certs/ca-bundle.crt";
      DEPOT_TOOLS_UPDATE = "0";
      DEPOT_TOOLS_COLLECT_METRICS = "0";
      PYTHONDONTWRITEBYTECODE = "1";
    };

    outputHashAlgo = "sha256";
    outputHashMode = "recursive";
    outputHash =
      (hashes."${buildPlatform.system}" or { })."${targetPlatform.system}"
        or (throw "Hash not set for ${targetPlatform.system} on ${buildPlatform.system}");
  }
  ''
    source ${../../../../build-support/fetchgit/deterministic-git}
    export -f clean_git
    export -f make_deterministic_repo

    mkdir --parents flutter
    cp ${gclient} flutter/.gclient
    cd flutter
    export PATH=$PATH:${tools.depot_tools}
    python3 ${tools.depot_tools}/gclient.py sync --no-history --shallow --nohooks -j $NIX_BUILD_CORES
    mv engine $out

    find $out -name '.git' -exec rm --recursive --force {} \; || true

    rm --recursive $out/src/flutter/{buildtools,prebuilts,third_party/swiftshader,third_party/gn/.versions,third_party/dart/tools/sdks/dart-sdk}
  ''