Skip to content

Commit 4e21c04

Browse files
authored
Merge pull request nix-community#274 from Atemu/2024
flake: bump to 2024
2 parents 9c72f8b + bbfb136 commit 4e21c04

File tree

8 files changed

+108
-67
lines changed

8 files changed

+108
-67
lines changed

flake.lock

Lines changed: 5 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@
22
description = "Build Android (AOSP) using Nix";
33

44
inputs = {
5-
nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11";
6-
nixpkgs-unstable.url = "github:NixOS/nixpkgs/nixos-unstable";
5+
nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.11";
76

87
androidPkgs.url = "github:tadfisher/android-nixpkgs/stable";
98

109
flake-compat.url = "github:nix-community/flake-compat";
1110
};
1211

13-
outputs = { self, nixpkgs, nixpkgs-unstable, androidPkgs, flake-compat, ... }@inputs: let
12+
outputs = { self, nixpkgs, androidPkgs, flake-compat, ... }@inputs: let
1413
pkgs = import ./pkgs/default.nix { inherit inputs; };
1514
in {
1615
# robotnixSystem evaluates a robotnix configuration
@@ -43,7 +42,7 @@
4342

4443
# For chromium updater script
4544
# python2
46-
cipd git
45+
# cipd git
4746

4847
cachix
4948
];

pkgs/fetchgit/builder.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,19 @@
22
# - no revision specified and remote has a HEAD which is used
33
# - revision specified and remote has a HEAD
44
# - revision specified and remote without HEAD
5+
#
6+
if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi
57
source $stdenv/setup
68

7-
header "exporting $url (rev $rev) into $out"
9+
echo "exporting $url (rev $rev) into $out"
810

911
$SHELL $fetcher --builder --url "$url" --out "$out" --rev "$rev" \
1012
${leaveDotGit:+--leave-dotGit} \
1113
${fetchLFS:+--fetch-lfs} \
1214
${deepClone:+--deepClone} \
1315
${fetchSubmodules:+--fetch-submodules} \
16+
${sparseCheckout:+--sparse-checkout "$sparseCheckout"} \
17+
${nonConeMode:+--non-cone-mode} \
1418
${branchName:+--branch-name "$branchName"}
1519

1620
runHook postFetch
17-
stopNest

pkgs/fetchgit/default.nix

Lines changed: 57 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,22 @@
77

88
short = builtins.substring 0 7 rev;
99

10-
appendShort = if (builtins.match "[a-f0-9]*" rev) != null
11-
then "-${short}"
12-
else "";
10+
appendShort = lib.optionalString ((builtins.match "[a-f0-9]*" rev) != null) "-${short}";
1311
in "${if matched == null then base else builtins.head matched}${appendShort}";
1412
in
15-
{ url, rev ? "HEAD", md5 ? "", sha256 ? "", hash ? "", leaveDotGit ? deepClone
13+
lib.makeOverridable (lib.fetchers.withNormalizedHash { } (
14+
# NOTE Please document parameter additions or changes in
15+
# doc/build-helpers/fetchers.chapter.md
16+
{ url
17+
, tag ? null
18+
, rev ? null
19+
, leaveDotGit ? deepClone
20+
, outputHash ? lib.fakeHash, outputHashAlgo ? null
1621
, fetchSubmodules ? true, deepClone ? false
1722
, branchName ? null
18-
, name ? urlToName url rev
23+
, sparseCheckout ? []
24+
, nonConeMode ? false
25+
, name ? null
1926
, # Shell code executed after the file has been fetched
2027
# successfully. This can do things like check or transform the file.
2128
postFetch ? ""
@@ -26,11 +33,13 @@ in
2633
, # Impure env vars (https://nixos.org/nix/manual/#sec-advanced-attributes)
2734
# needed for netrcPhase
2835
netrcImpureEnvVars ? []
36+
, meta ? {}
37+
, allowedRequisites ? null
2938
}:
3039

3140
/* NOTE:
3241
fetchgit has one problem: git fetch only works for refs.
33-
This is because fetching arbitrary (maybe dangling) commits may be a security risk
42+
This is because fetching arbitrary (maybe dangling) commits creates garbage collection risks
3443
and checking whether a commit belongs to a ref is expensive. This may
3544
change in the future when some caching is added to git (?)
3645
Usually refs are either tags (refs/tags/*) or branches (refs/heads/*)
@@ -51,44 +60,67 @@ in
5160
*/
5261

5362
assert deepClone -> leaveDotGit;
63+
assert nonConeMode -> (sparseCheckout != []);
64+
65+
let
66+
revWithTag =
67+
let
68+
warningMsg = "fetchgit requires one of either `rev` or `tag` to be provided (not both).";
69+
otherIsNull = other: lib.assertMsg (other == null) warningMsg;
70+
in
71+
if tag != null then
72+
assert (otherIsNull rev);
73+
"refs/tags/${tag}"
74+
else if rev != null then
75+
assert (otherIsNull tag);
76+
rev
77+
else
78+
# FIXME fetching HEAD if no rev or tag is provided is problematic at best
79+
"HEAD";
80+
in
5481

55-
if md5 != "" then
56-
throw "fetchgit does not support md5 anymore, please use sha256"
57-
else if hash != "" && sha256 != "" then
58-
throw "Only one of sha256 or hash can be set"
82+
if builtins.isString sparseCheckout then
83+
# Changed to throw on 2023-06-04
84+
throw "Please provide directories/patterns for sparse checkout as a list of strings. Passing a (multi-line) string is not supported any more."
5985
else
6086
stdenvNoCC.mkDerivation {
61-
inherit name;
87+
name = if name != null then name else urlToName url revWithTag;
88+
6289
builder = ./builder.sh;
63-
fetcher = ./nix-prefetch-git; # This must be a string to ensure it's called with bash.
90+
fetcher = ./nix-prefetch-git;
6491

65-
nativeBuildInputs = [ git ]
92+
nativeBuildInputs = [ git cacert ]
6693
++ lib.optionals fetchLFS [ git-lfs ];
6794

68-
outputHashAlgo = if hash != "" then null else "sha256";
95+
inherit outputHash outputHashAlgo;
6996
outputHashMode = "recursive";
70-
outputHash = if hash != "" then
71-
hash
72-
else if sha256 != "" then
73-
sha256
74-
else
75-
lib.fakeSha256;
7697

77-
inherit url rev leaveDotGit fetchLFS fetchSubmodules deepClone branchName postFetch;
98+
# git-sparse-checkout(1) says:
99+
# > When the --stdin option is provided, the directories or patterns are read
100+
# > from standard in as a newline-delimited list instead of from the arguments.
101+
sparseCheckout = builtins.concatStringsSep "\n" sparseCheckout;
102+
103+
inherit url leaveDotGit fetchLFS fetchSubmodules deepClone branchName nonConeMode postFetch;
104+
rev = revWithTag;
78105

79106
postHook = if netrcPhase == null then null else ''
80107
${netrcPhase}
81108
# required that git uses the netrc file
82109
mv {,.}netrc
110+
export NETRC=$PWD/.netrc
83111
export HOME=$PWD
84112
'';
85113

86-
GIT_SSL_CAINFO = "${cacert}/etc/ssl/certs/ca-bundle.crt";
87-
88114
impureEnvVars = lib.fetchers.proxyImpureEnvVars ++ netrcImpureEnvVars ++ [
89115
"GIT_PROXY_COMMAND" "NIX_GIT_SSL_CAINFO" "SOCKS_SERVER"
90-
"ROBOTNIX_GIT_MIRRORS"
91116
];
92117

93-
inherit preferLocalBuild;
118+
119+
inherit preferLocalBuild meta allowedRequisites;
120+
121+
passthru = {
122+
gitRepoUrl = url;
123+
inherit tag;
124+
};
94125
}
126+
))

pkgs/fetchgit/nix-prefetch-git

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ branchName=$NIX_PREFETCH_GIT_BRANCH_NAME
1717
out=${out:-}
1818
http_proxy=${http_proxy:-}
1919

20-
# allow overwriting cacert's ca-bundle.crt with a custom one
21-
# this can be done by setting NIX_GIT_SSL_CAINFO and NIX_SSL_CERT_FILE environment variables for the nix-daemon
22-
GIT_SSL_CAINFO=${NIX_GIT_SSL_CAINFO:-$GIT_SSL_CAINFO}
20+
# NOTE: use of NIX_GIT_SSL_CAINFO is for backwards compatibility; NIX_SSL_CERT_FILE is preferred
21+
# as of PR#303307
22+
GIT_SSL_CAINFO=${NIX_GIT_SSL_CAINFO:-$NIX_SSL_CERT_FILE}
2323

2424
# populated by clone_user_rev()
2525
fullRev=
@@ -171,7 +171,7 @@ checkout_hash(){
171171
clean_git fetch -t ${builder:+--progress} origin || return 1
172172

173173
local object_type=$(git cat-file -t "$hash")
174-
if [[ "$object_type" == "commit" ]]; then
174+
if [[ "$object_type" == "commit" || "$object_type" == "tag" ]]; then
175175
clean_git checkout -b "$branchName" "$hash" || return 1
176176
elif [[ "$object_type" == "tree" ]]; then
177177
clean_git config user.email "nix-prefetch-git@localhost"
@@ -417,6 +417,7 @@ remove_tmpPath() {
417417
}
418418

419419
remove_tmpHomePath() {
420+
chmod -R u+w "$tmpHomePath"
420421
rm -rf "$tmpHomePath"
421422
}
422423

@@ -457,8 +458,9 @@ else
457458
# If we don't know the hash or a path with that hash doesn't exist,
458459
# download the file and add it to the store.
459460
if test -z "$finalPath"; then
460-
461-
tmpPath="$(mktemp -d "${TMPDIR:-/tmp}/git-checkout-tmp-XXXXXXXX")"
461+
# nix>=2.20 rejects adding symlinked paths to the store, so use realpath
462+
# to resolve to a physical path. https://github.com/NixOS/nix/issues/11941
463+
tmpPath="$(realpath "$(mktemp -d --tmpdir git-checkout-tmp-XXXXXXXX)")"
462464
exit_handlers+=(remove_tmpPath)
463465

464466
tmpFile="$tmpPath/$(url_to_name "$url" "$rev")"

pkgs/gitRepo/default.nix

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1-
{ lib, inputs, fetchFromGitHub, rsync, git, gnupg, less, openssh, ... }:
1+
{ lib, gitRepo, fetchFromGitHub, fetchpatch2, rsync, git, gnupg, less, openssh, ... }:
22
let
3-
inherit (inputs) nixpkgs-unstable;
4-
5-
unstablePkgs = nixpkgs-unstable.legacyPackages.x86_64-linux;
3+
git-patched = git.overrideAttrs (old: {
4+
patches = old.patches or [ ] ++ [
5+
./ignore_dubious_ownership.patch
6+
];
7+
# Likely won't succeed with the patch and we don't care.
8+
doCheck = false;
9+
doInstallCheck = false;
10+
});
611
in
7-
unstablePkgs.gitRepo.overrideAttrs(oldAttrs: rec {
12+
gitRepo.overrideAttrs(oldAttrs: rec {
813
version = "2.45";
914

1015
src = fetchFromGitHub {
@@ -14,7 +19,7 @@ in
1419
hash = "sha256-f765TcOHL8wdPa9qSmGegofjCXx1tF/K5bRQnYQcYVc=";
1520
};
1621

17-
nativeBuildInputs = (oldAttrs.nativeBuildInputs or []) ++ [ rsync git ];
22+
nativeBuildInputs = (oldAttrs.nativeBuildInputs or []) ++ [ rsync git-patched ];
1823

1924
repo2nixPatches = ./patches;
2025

@@ -65,6 +70,10 @@ in
6570
wrapProgram "$out/bin/repo" \
6671
--set REPO_URL "file://$out/var/repo" \
6772
--set REPO_REV "$(cat ./COMMITED_REPO_REV)" \
68-
--prefix PATH ":" "${ lib.makeBinPath [ git gnupg less openssh ] }"
73+
--prefix PATH ":" "${ lib.makeBinPath [ git-patched gnupg less openssh ] }"
6974
'';
75+
76+
passthru = {
77+
inherit git-patched;
78+
};
7079
})
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
diff --git a/setup.c b/setup.c
2+
--- a/setup.c
3+
+++ b/setup.c
4+
@@ -1332,6 +1332,7 @@
5+
void die_upon_dubious_ownership(const char *gitfile, const char *worktree,
6+
const char *gitdir)
7+
{
8+
+ return; // Stubbed
9+
struct strbuf report = STRBUF_INIT, quoted = STRBUF_INIT;
10+
const char *path;
11+

pkgs/overlay.nix

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ self: super: {
3434
});
3535
nix-prefetch-git = super.callPackage ./fetchgit/nix-prefetch-git.nix {};
3636

37-
gitRepo = super.callPackage ./gitRepo { inherit inputs; };
37+
gitRepo = super.callPackage ./gitRepo {
38+
inherit (super) gitRepo;
39+
};
3840

3941
###
4042

0 commit comments

Comments
 (0)