gclient2nix: add importGclientDeps & gclientUnpackHook

This commit is contained in:
Yureka 2025-04-04 16:07:52 +02:00
parent 082d26cd46
commit 0e730af47a
2 changed files with 72 additions and 0 deletions

View File

@ -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

View File

@ -6,9 +6,49 @@
path, path,
fetchgit, fetchgit,
nurl, nurl,
writers,
callPackage,
fetchFromGitiles,
fetchFromGitHub,
}: }:
let 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 ( python = python3.withPackages (
ps: with ps; [ ps: with ps; [
joblib joblib
@ -32,6 +72,10 @@ runCommand "gclient2nix"
rev = "452fe3be37f78fbecefa1b4b0d359531bcd70d0d"; rev = "452fe3be37f78fbecefa1b4b0d359531bcd70d0d";
hash = "sha256-8IiJOm0FLa/u1Vd96tb33Ruj4IUTCeYgBpTk88znhPw="; hash = "sha256-8IiJOm0FLa/u1Vd96tb33Ruj4IUTCeYgBpTk88znhPw=";
}; };
passthru = {
inherit fetchers importGclientDeps gclientUnpackHook;
};
} }
'' ''
mkdir -p $out/bin mkdir -p $out/bin