Skip to content

Commit 9ed6761

Browse files
jaenAtemu
authored andcommitted
git-repo: update to 2.45, patch to run locally
The `repo` tool derivation by default includes only the main wrapper script which fetches the actual tool sources from the internet. We modify the derivation to provide default local sources patched with support for repo2nix, unless specified otherwise with CLI parameters. Flake compat was updated and nixpkgs-unstable re-introduced to facilitate this change.
1 parent 40ec5a1 commit 9ed6761

24 files changed

+1005
-20
lines changed

flake.lock

Lines changed: 34 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@
33

44
inputs = {
55
nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11";
6+
nixpkgs-unstable.url = "github:NixOS/nixpkgs/nixos-unstable";
7+
68
androidPkgs.url = "github:tadfisher/android-nixpkgs/stable";
9+
10+
flake-compat.url = "github:nix-community/flake-compat";
711
};
812

9-
outputs = { self, nixpkgs, androidPkgs, ... }@inputs: let
13+
outputs = { self, nixpkgs, nixpkgs-unstable, androidPkgs, flake-compat, ... }@inputs: let
1014
pkgs = import ./pkgs/default.nix { inherit inputs; };
1115
in {
1216
# robotnixSystem evaluates a robotnix configuration
@@ -24,6 +28,7 @@
2428

2529
packages.x86_64-linux = {
2630
manual = (import ./docs { inherit pkgs; }).manual;
31+
gitRepo = pkgs.gitRepo;
2732
};
2833

2934
devShell.x86_64-linux = pkgs.mkShell {

flake/compat.nix

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{ system ? builtins.currentSystem }:
2+
let
3+
lock = builtins.fromJSON (builtins.readFile ./../flake.lock);
4+
flake-compat-entry = lock.nodes.root.inputs.flake-compat;
5+
6+
inherit (lock.nodes."${ flake-compat-entry }".locked) owner repo narHash;
7+
8+
flake-compat = builtins.fetchTarball {
9+
url = "https://github.com/${ owner }/${ repo }/archive/${ lock.nodes.flake-compat.locked.rev }.tar.gz";
10+
sha256 = narHash;
11+
};
12+
in
13+
import flake-compat {
14+
inherit system;
15+
16+
src = ./..;
17+
}

pkgs/default.nix

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
# SPDX-FileCopyrightText: 2020 Daniel Fullmer and robotnix contributors
22
# SPDX-License-Identifier: MIT
33

4-
{ inputs ? (import (
5-
fetchTarball {
6-
url = "https://github.com/edolstra/flake-compat/archive/12c64ca55c1014cdc1b16ed5a804aa8576601ff2.tar.gz";
7-
sha256 = "0jm6nzb83wa6ai17ly9fzpqc40wg1viib8klq8lby54agpl213w5"; }
8-
) {
9-
src = ../.;
10-
}).defaultNix.inputs,
11-
... }@args:
4+
{
5+
system ? builtins.currentSystem,
6+
inputs ? (import ../flake/compat.nix { inherit system; }).defaultNix.inputs,
7+
...
8+
}@args:
129

1310
let
1411
inherit (inputs) nixpkgs androidPkgs;
@@ -17,5 +14,5 @@ in nixpkgs.legacyPackages.x86_64-linux.appendOverlays [
1714
androidPkgs.packages = androidPkgs.packages.x86_64-linux;
1815
androidPkgs.sdk = androidPkgs.sdk.x86_64-linux;
1916
})
20-
(import ./overlay.nix)
17+
(import ./overlay.nix { inherit inputs; })
2118
]

pkgs/gitRepo/default.nix

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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+
})
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
From 8fe8a2efaa6bcd404c256a29d1dc5ed4ae241a08 Mon Sep 17 00:00:00 2001
2+
From: ajs124 <git@ajs124.de>
3+
Date: Tue, 26 Feb 2019 04:48:13 +0100
4+
Subject: [PATCH 01/16] add initial (hacky) version of "repo2nix"
5+
6+
now with less impurities
7+
---
8+
project.py | 4 +-
9+
subcmds/nix.py | 100 +++++++++++++++++++++++++++++++++++++++++++++++++
10+
2 files changed, 102 insertions(+), 2 deletions(-)
11+
create mode 100644 subcmds/nix.py
12+
13+
diff --git a/project.py b/project.py
14+
index 1f5e4c3..c3c3384 100644
15+
--- a/project.py
16+
+++ b/project.py
17+
@@ -2887,8 +2887,8 @@ class Project:
18+
)
19+
20+
def _LsRemote(self, refs):
21+
- cmd = ["ls-remote", self.remote.name, refs]
22+
- p = GitCommand(self, cmd, capture_stdout=True)
23+
+ cmd = ["ls-remote", self.remote.url, refs]
24+
+ p = GitCommand(self, cmd, cwd="/", capture_stdout=True)
25+
if p.Wait() == 0:
26+
return p.stdout
27+
return None
28+
diff --git a/subcmds/nix.py b/subcmds/nix.py
29+
new file mode 100644
30+
index 0000000..f113ede
31+
--- /dev/null
32+
+++ b/subcmds/nix.py
33+
@@ -0,0 +1,100 @@
34+
+#
35+
+# Copyright (C) 2008 The Android Open Source Project
36+
+#
37+
+# Licensed under the Apache License, Version 2.0 (the "License");
38+
+# you may not use this file except in compliance with the License.
39+
+# You may obtain a copy of the License at
40+
+#
41+
+# http://www.apache.org/licenses/LICENSE-2.0
42+
+#
43+
+# Unless required by applicable law or agreed to in writing, software
44+
+# distributed under the License is distributed on an "AS IS" BASIS,
45+
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
46+
+# See the License for the specific language governing permissions and
47+
+# limitations under the License.
48+
+
49+
+from __future__ import print_function
50+
+
51+
+from pyversion import is_python3
52+
+if is_python3():
53+
+ import http.cookiejar as cookielib
54+
+ import urllib.error
55+
+ import urllib.parse
56+
+ import urllib.request
57+
+ import xmlrpc.client
58+
+else:
59+
+ import imp
60+
+ import urllib2
61+
+ import urlparse
62+
+ import xmlrpclib
63+
+ urllib = imp.new_module('urllib')
64+
+ urllib.error = urllib2
65+
+ urllib.parse = urlparse
66+
+ urllib.request = urllib2
67+
+ xmlrpc = imp.new_module('xmlrpc')
68+
+ xmlrpc.client = xmlrpclib
69+
+
70+
+try:
71+
+ import threading as _threading
72+
+except ImportError:
73+
+ import dummy_threading as _threading
74+
+
75+
+try:
76+
+ import resource
77+
+ def _rlimit_nofile():
78+
+ return resource.getrlimit(resource.RLIMIT_NOFILE)
79+
+except ImportError:
80+
+ def _rlimit_nofile():
81+
+ return (256, 256)
82+
+
83+
+try:
84+
+ import multiprocessing
85+
+except ImportError:
86+
+ multiprocessing = None
87+
+
88+
+from command import Command, MirrorSafeCommand
89+
+
90+
+class Nix(Command, MirrorSafeCommand):
91+
+ common = True
92+
+ helpSummary = "Export nix file with sources"
93+
+ helpUsage = """
94+
+%prog [<project>...]
95+
+"""
96+
+ helpDescription = """
97+
+"""
98+
+
99+
+ def Execute(self, opt, args):
100+
+ all_projects = self.GetProjects(args, missing_ok=True, submodules_ok=False)
101+
+
102+
+ oS = '{\n'
103+
+ oS += "unpackPhase = ''\n" \
104+
+ 'echo "reassembling source tree from git source store paths"\n' \
105+
+ 'mkdir src; cd src\n' \
106+
+ 'for src in $srcs; do\n' \
107+
+ " dest_folder=$(stripHash $src); dest_folder=''${dest_folder//=//}\n" \
108+
+ ' echo "$src -> $dest_folder"\n' \
109+
+ ' mkdir -p "$dest_folder"\n' \
110+
+ ' cp --reflink=auto --no-preserve=ownership --no-dereference --preserve=links --recursive "$src/." "$dest_folder/"\n' \
111+
+ ' chmod -R u+w "$dest_folder"\n' \
112+
+ 'done\n' \
113+
+ 'echo "creating symlinks and copies as specified in repo manifest(s)"\n'
114+
+ for p in all_projects:
115+
+ for f in p.linkfiles:
116+
+ oS += 'ln -s ' + f.src_rel_to_dest + ' ' + f.dest + '\n'
117+
+ for c in p.copyfiles:
118+
+ oS += 'cp --reflink=auto ' + p.relpath + '/' + c.src + ' ' + c.dest + '\n'
119+
+ oS += "'';\n"
120+
+
121+
+ oS += 'sources = [\n'
122+
+ for p in all_projects:
123+
+ oS += ' (builtins.fetchGit {\n'
124+
+ oS += ' url = "' + p.remote.url + '";\n'
125+
+ if 'refs/heads' in p.revisionExpr:
126+
+ oS += ' ref = "' + p.revisionExpr.split('/')[-1] + '";\n'
127+
+ else:
128+
+ oS += ' ref = "' + p.revisionExpr + '";\n'
129+
+ oS += ' rev = "' + p._LsRemote(p.revisionExpr).split('\t')[0] + '";\n'
130+
+ oS += ' name = "' + p.relpath.replace('/', '=') + '";\n'
131+
+ oS += ' })\n'
132+
+ oS += '];\n}'
133+
+ print(oS)
134+
\ No newline at end of file
135+
--
136+
2.44.0
137+

0 commit comments

Comments
 (0)