|
| 1 | +{ lib, inputs, fetchFromGitHub, rsync, git, gnupg, less, openssh, ... }: |
| 2 | +let |
| 3 | + inherit (inputs) nixpkgs-unstable; |
| 4 | + |
| 5 | + unstablePkgs = nixpkgs-unstable.legacyPackages.x86_64-linux; |
| 6 | +in |
| 7 | + unstablePkgs.gitRepo.overrideAttrs(oldAttrs: rec { |
| 8 | + version = "2.45"; |
| 9 | + |
| 10 | + src = fetchFromGitHub { |
| 11 | + owner = "android"; |
| 12 | + repo = "tools_repo"; |
| 13 | + rev = "v${ version }"; |
| 14 | + hash = "sha256-f765TcOHL8wdPa9qSmGegofjCXx1tF/K5bRQnYQcYVc="; |
| 15 | + }; |
| 16 | + |
| 17 | + nativeBuildInputs = (oldAttrs.nativeBuildInputs or []) ++ [ rsync git ]; |
| 18 | + |
| 19 | + repo2nixPatches = ./patches; |
| 20 | + |
| 21 | + # NOTE: why `git apply` instead of relying on `patches`? For some reason when |
| 22 | + # using `patches` the source `rsync`ed into `var/repo` is missing those changes |
| 23 | + installPhase = '' |
| 24 | + runHook preInstall |
| 25 | +
|
| 26 | + mkdir -p var/repo |
| 27 | + rsync -a $src/ var/repo/ |
| 28 | +
|
| 29 | + ( |
| 30 | + export GIT_CONFIG_GLOBAL=$TMPDIR/.gitconfig |
| 31 | + export GIT_CONFIG_NOSYSTEM=true |
| 32 | +
|
| 33 | + cd var/repo |
| 34 | +
|
| 35 | + git config --global --add safe.directory "$PWD" |
| 36 | + git config --global user.email "nemo@nix" |
| 37 | + git config --global user.name "Nemo Nix" |
| 38 | +
|
| 39 | + chmod +w -R . |
| 40 | +
|
| 41 | + git init |
| 42 | + git add -A |
| 43 | + git commit -m "Upstream sources" |
| 44 | +
|
| 45 | + git am $repo2nixPatches/*.patch |
| 46 | +
|
| 47 | + git log -n 1 --format="%H" > ../../COMMITED_REPO_REV |
| 48 | + ) |
| 49 | +
|
| 50 | + mkdir -p $out/var/repo |
| 51 | + mkdir -p $out/bin |
| 52 | +
|
| 53 | + rsync -a var/repo/ $out/var/repo/ |
| 54 | +
|
| 55 | + # Copying instead of symlinking to the above directory is necessary, because otherwise |
| 56 | + # running `repo init` fails, as I assume the script gets confused by being located in |
| 57 | + # a git repo itself |
| 58 | + cp repo $out/bin/repo |
| 59 | +
|
| 60 | + runHook postInstall |
| 61 | + ''; |
| 62 | + |
| 63 | + # Specify the patched checkout as the default version of repo |
| 64 | + postFixup = '' |
| 65 | + wrapProgram "$out/bin/repo" \ |
| 66 | + --set REPO_URL "file://$out/var/repo" \ |
| 67 | + --set REPO_REV "$(cat ./COMMITED_REPO_REV)" \ |
| 68 | + --prefix PATH ":" "${ lib.makeBinPath [ git gnupg less openssh ] }" |
| 69 | + ''; |
| 70 | + }) |
0 commit comments