Skip to content

Commit 6f45ad5

Browse files
author
Patrick Widmer
committed
wip
1 parent 1521b76 commit 6f45ad5

File tree

5 files changed

+44
-13
lines changed

5 files changed

+44
-13
lines changed

buildGradleApplication/default.nix

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@
1515
buildInputs ? [],
1616
nativeBuildInputs ? [],
1717
dependencyFilter ? depSpec: true,
18+
privateRepository ? null,
1819
repositories ? ["https://plugins.gradle.org/m2/" "https://repo1.maven.org/maven2/"],
1920
verificationFile ? "gradle/verification-metadata.xml",
2021
buildTask ? ":installDist",
2122
installLocation ? "build/install/*/",
2223
}: let
2324
m2Repository = mkM2Repository {
24-
inherit pname version src dependencyFilter repositories verificationFile;
25+
inherit pname version src dependencyFilter privateRepository repositories verificationFile;
2526
};
2627

2728
# Prepare a script that will replace that jars with references into the NIX store.

buildGradleApplication/mkM2Repository.nix

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
version,
99
src,
1010
dependencyFilter ? depSpec: true,
11+
privateRepository ? null,
1112
repositories ? ["https://plugins.gradle.org/m2/" "https://repo1.maven.org/maven2/"],
1213
verificationFile ? "gradle/verification-metadata.xml",
1314
}: let
@@ -20,13 +21,16 @@
2021
# Read all build and runtime dependencies from the verification-metadata XML
2122
builtins.fromJSON (builtins.readFile (
2223
runCommandNoCC "depSpecs" {buildInputs = [python3];}
23-
"python ${./parse.py} ${filteredSrc}/${verificationFile} ${builtins.toString (builtins.map lib.escapeShellArg repositories)}> $out"
24+
"python ${./parse.py} -f ${filteredSrc}/${verificationFile} -r ${builtins.toString (builtins.map lib.escapeShellArg repositories)}"
25+
+ lib.strings.optionalString (privateRepository != null) " -p ${lib.escapeShellArg privateRepository}"
26+
+ " > $out"
2427
))
2528
);
26-
mkDep = depSpec: {
29+
mkDep = { privateUrl ? null, ... }@depSpec: {
2730
inherit (depSpec) urls path name hash component;
2831
jar = fetchArtifact {
2932
inherit (depSpec) urls hash name;
33+
inherit privateUrl;
3034
};
3135
};
3236
dependencies = builtins.map (depSpec: mkDep depSpec) depSpecs;

buildGradleApplication/parse.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import json
44
from dataclasses import dataclass
55
import base64
6+
import argparse
67

78
@dataclass
89
class Component:
@@ -25,8 +26,16 @@ def main():
2526
if len(sys.argv) <= 1:
2627
print("Missing verification.xml file")
2728
sys.exit(1)
28-
artifacts = parse(sys.argv[1])
29-
maven_repos = [repository.rstrip("/") for repository in sys.argv[2:]]
29+
30+
parser = argparse.ArgumentParser()
31+
parser.add_argument("-f", "--verification-file", required=True)
32+
parser.add_argument("-r", "--repository", dest="repositories", action="extend", nargs="+")
33+
parser.add_argument("-p", "--private-repository")
34+
args = parser.parse_args()
35+
36+
artifacts = parse(args.verification_file)
37+
maven_repos = [repository.rstrip("/") for repository in args.repositories]
38+
private_maven_repo = None if args.private_repository is None else args.private_repository.rstrip("/")
3039

3140
outputs = []
3241
for artifact in artifacts:
@@ -42,6 +51,8 @@ def main():
4251
},
4352
"hash": toSri(artifact.hash.algo, artifact.hash.value)
4453
}
54+
if private_maven_repo is not None:
55+
output["privateUrl"] = f"{private_maven_repo}/{path}/{artifact.name}"
4556
outputs.append(output)
4657
print(json.dumps(outputs))
4758

@@ -82,4 +93,4 @@ def parse(xml_file):
8293

8394

8495
if __name__ == "__main__":
85-
main()
96+
main()

fetchArtefact/builder.bash

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,14 @@ check_hash() {
2626
fi
2727
}
2828

29-
# expected variables to be set:
30-
name="${name:?}"
31-
out="${out:?}"
32-
urls="${urls:?}"
33-
hash="${hash:?}"
29+
fetch_url() {
30+
local url="$1"
31+
local nix_curl_flags=$2
3432

35-
for url in $urls; do
3633
echo "Downloading $name from $url"
3734

38-
if "${curl[@]}" --retry 0 --connect-timeout "${NIX_CONNECT_TIMEOUT:-15}" \
35+
if "${curl[@]}" $nix_curl_flags --retry 0 \
36+
--connect-timeout "${NIX_CONNECT_TIMEOUT:-15}" \
3937
--fail --silent --show-error --head "$url" \
4038
--write-out "%{http_code}" --output /dev/null > code 2> log; then
4139

@@ -59,6 +57,20 @@ for url in $urls; do
5957
echo "error checking the existence of $url:"
6058
cat log
6159
fi
60+
}
61+
62+
# expected variables to be set:
63+
name="${name:?}"
64+
out="${out:?}"
65+
urls="${urls:?}"
66+
hash="${hash:?}"
67+
68+
if [ -n "$private_url" ]; then
69+
fetch_url "$private_url" $NIX_CURL_FLAGS
70+
fi
71+
72+
for url in $urls; do
73+
fetch_url "$url"
6274
done
6375

6476
echo "File $name was not found with hash $hash on any of the given urls"

fetchArtefact/default.nix

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
nix,
55
cacert,
66
}: {
7+
privateUrl ? null,
78
# A list of URLs specifying alternative download locations. They are tried in order.
89
urls,
910
# SRI hash.
@@ -19,7 +20,9 @@ stdenvNoCC.mkDerivation {
1920
builder = ./builder.bash;
2021
nativeBuildInputs = [curl nix];
2122
SSL_CERT_FILE = "${cacert}/etc/ssl/certs/ca-bundle.crt";
23+
private_url = privateUrl;
2224
inherit urls;
25+
impureEnvVars = ["NIX_CURL_FLAGS"];
2326

2427
# Doing the download on a remote machine just duplicates network
2528
# traffic, so don't do that

0 commit comments

Comments
 (0)