summaryrefslogtreecommitdiffstats
path: root/pkgs/by-name/gc/gclient2nix/package.nix
blob: 9275ea0f9a748dee95300b4d61503614707db5db (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
{
  lib,
  python3,
  runCommand,
  makeWrapper,
  fetchgit,
  nurl,
  writers,
  callPackage,
  fetchFromGitiles,
  fetchFromGitHub,
  buildPackages,
}:

let
  fetchers = {
    inherit fetchgit fetchFromGitiles fetchFromGitHub;
  };

  importGclientDeps =
    depsAttrsOrFile:
    let
      depsAttrs = if lib.isAttrs depsAttrsOrFile then depsAttrsOrFile else lib.importJSON depsAttrsOrFile;
      fetchdep = dep: fetchers.${dep.fetcher} dep.args;
      fetchedDeps = lib.mapAttrs (_name: fetchdep) depsAttrs;
      manifestContents = lib.mapAttrs (_: dep: {
        path = dep;
      }) fetchedDeps;
      manifest = writers.writeJSON "gclient-manifest.json" manifestContents;
    in
    manifestContents
    // {
      inherit manifest;
      __toString = _: manifest;
    };

  gclientUnpackHook = callPackage (
    {
      lib,
      makeSetupHook,
      jq,
    }:

    makeSetupHook {
      name = "gclient-unpack-hook";
      substitutions = {
        jq = lib.getExe buildPackages.jq;
      };
      meta.license = lib.licenses.mit;
    } ./gclient-unpack-hook.sh
  ) { };

  python = python3.withPackages (
    ps: with ps; [
      joblib
      platformdirs
      click
      click-log
    ]
  );

in

runCommand "gclient2nix"
  {
    nativeBuildInputs = [ makeWrapper ];
    buildInputs = [ python ];

    # substitutions
    depot_tools_checkout = fetchgit {
      url = "https://chromium.googlesource.com/chromium/tools/depot_tools";
      rev = "604a436d8af23ca0b9fd3d1d8be193fc9a4679f6";
      hash = "sha256-tNJq/a4j0AHmn2FS4zbwkWeEMYlp4uXDcpPzP9D3ULE=";
    };

    passthru = {
      inherit fetchers importGclientDeps gclientUnpackHook;
    };
  }
  ''
    mkdir -p $out/bin
    substituteAll ${./gclient2nix.py} $out/bin/gclient2nix
    chmod u+x $out/bin/gclient2nix
    patchShebangs $out/bin/gclient2nix
    wrapProgram $out/bin/gclient2nix --set PATH "${lib.makeBinPath [ nurl ]}"
  ''