diff --git a/pkgs/by-name/gc/gclient2nix/gclient-unpack-hook.sh b/pkgs/by-name/gc/gclient2nix/gclient-unpack-hook.sh new file mode 100644 index 000000000000..6dac91b9e25a --- /dev/null +++ b/pkgs/by-name/gc/gclient2nix/gclient-unpack-hook.sh @@ -0,0 +1,28 @@ +# shellcheck shell=bash + +gclientUnpackHook() { + echo "Executing gclientUnpackHook" + + runHook preUnpack + + if [ -z "${gclientDeps-}" ]; then + echo "gclientDeps missing" + exit 1 + fi + + for dep in $(@jq@ -c "to_entries[]" "$gclientDeps") + do + local name="$(echo "$dep" | @jq@ -r .key)" + echo "copying $name..." + local path="$(echo "$dep" | @jq@ -r .value.path)" + mkdir -p $(dirname "$name") + cp -r "$path/." "$name" + chmod u+w -R "$name" + done + + runHook postUnpack +} + +if [ -z "${dontGclientUnpack-}" ] && [ -z "${unpackPhase-}" ]; then + unpackPhase=(gclientUnpackHook) +fi diff --git a/pkgs/by-name/gc/gclient2nix/package.nix b/pkgs/by-name/gc/gclient2nix/package.nix index 17662ab5d714..ee7251b9ffa7 100644 --- a/pkgs/by-name/gc/gclient2nix/package.nix +++ b/pkgs/by-name/gc/gclient2nix/package.nix @@ -6,9 +6,49 @@ path, fetchgit, nurl, + writers, + callPackage, + fetchFromGitiles, + fetchFromGitHub, }: 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 jq; + }; + } ./gclient-unpack-hook.sh + ) { }; + python = python3.withPackages ( ps: with ps; [ joblib @@ -32,6 +72,10 @@ runCommand "gclient2nix" rev = "452fe3be37f78fbecefa1b4b0d359531bcd70d0d"; hash = "sha256-8IiJOm0FLa/u1Vd96tb33Ruj4IUTCeYgBpTk88znhPw="; }; + + passthru = { + inherit fetchers importGclientDeps gclientUnpackHook; + }; } '' mkdir -p $out/bin