nix: stop downloading POMs for Clojure dependencies

Clojure dependencies require only JARs to work. Downloading POMs is both
a waste of time, space, and bandwidth. In addition POMs create edge
cases that we would have to handle, an would rather avoid.

For example, the `guice` package which shows up in the classpath
includes a JAR named `guice-4.2.2-no_aop.jar`. The issue with that is
that there is no corresponding POM in the directory:
https://repo1.maven.org/maven2/com/google/inject/guice/4.2.2/

Either we have to make a special case for such packages, or we can just
skip POMs entirely and avoid the mess.

Signed-off-by: Jakub Sokołowski <jakub@status.im>
This commit is contained in:
Jakub Sokołowski 2023-10-13 14:18:40 +02:00
parent a2794a120a
commit d1442b306a
No known key found for this signature in database
GPG Key ID: FE65CD384D5BF7B4
3 changed files with 6 additions and 30 deletions

View File

@ -12,12 +12,13 @@ By using the following command:
```sh
shadow-cljs classpath --force-spawn
```
We both download the necessary JARs and POMs into `~/.m2` folder, but also get the classpath printed into standard output.
We download the necessary JARs into `~/.m2` folder, but also get the classpath printed into standard output.
We skip POM files since they are not necessary, and add edge cases we don't want to handle.
We then use the classpath in combination with contents of `~/.m2` folder to generate the following files:
* `deps.list` - List of JARs relative to the `~/.m2` cache folder.
* `deps.json` - Full list of JARs and POMs including their SHAs.
* `deps.json` - Full list of JARs including their SHAs.
The `deps.list` file is just intermediate and for debugging purposes.
The `deps.json` is loaded by the derivation in [`default.nix`](./default.nix) and used to produce a derivation that contains all the necessary dependencies:

View File

@ -8,9 +8,6 @@ let
# load dependencies
deps = importJSON ./deps.json;
# some .jar files have an `-aot` suffix that doesn't work for .pom files
getPOM = jarUrl: "${removeSuffix "-aot" jarUrl}.pom";
script = writeShellScriptBin "create-local-maven-repo" (''
mkdir -p $out
cd $out
@ -18,18 +15,11 @@ let
(concatMapStrings (dep:
let
url = "${dep.host}/${dep.path}";
pom = {
sha1 = attrByPath [ "pom" "sha1" ] "" dep;
sha256 = attrByPath [ "pom" "sha256" ] "" dep;
};
pom-download = optionalString (pom.sha256 != "") (
fetchurl { url = getPOM url; inherit (pom) sha256; }
);
jar = {
sha1 = attrByPath [ "jar" "sha1" ] "" dep;
sha256 = attrByPath [ "jar" "sha256" ] "" dep;
};
jar-download = optionalString (jar.sha256 != "") (
jarFile = optionalString (jar.sha256 != "") (
fetchurl { url = "${url}.jar"; inherit (jar) sha256; }
);
fileName = last (splitString "/" dep.path);
@ -38,14 +28,8 @@ let
''
mkdir -p ${directory}
${optionalString (pom-download != "") ''
ln -s "${pom-download}" "${getPOM dep.path}"
''}
${optionalString (pom.sha1 != "") ''
echo "${pom.sha1}" > "${getPOM dep.path}.sha1"
''}
${optionalString (jar-download != "") ''
ln -s "${jar-download}" "${dep.path}.jar"
${optionalString (jarFile != "") ''
ln -s "${jarFile}" "${dep.path}.jar"
''}
${optionalString (jar.sha1 != "") ''
echo "${jar.sha1}" > "${dep.path}.jar.sha1"

View File

@ -53,8 +53,6 @@ function nix_entry_from_jar() {
JAR_PATH="${MAVEN_CACHE_PATH}/${JAR_REL_PATH}"
JAR_NAME=$(basename "${JAR_PATH}")
JAR_DIR=$(dirname "${JAR_PATH}")
# POM might have a slightly different name
POM_PATH=$(echo ${JAR_DIR}/*.pom)
REPO_NAME=$(get_repo_for_dir "${JAR_DIR}")
REPO_URL=${REPOS[${REPO_NAME}]}
@ -62,18 +60,11 @@ function nix_entry_from_jar() {
JAR_SHA1=$(cat "${JAR_PATH}.sha1")
JAR_SHA256=$(get_nix_sha "${JAR_PATH}")
POM_SHA1=$(cat "${POM_PATH}.sha1")
POM_SHA256=$(get_nix_sha "${POM_PATH}")
# Format into a Nix attrset entry
echo -n "
{
\"path\": \"${JAR_REL_NAME}\",
\"host\": \"${REPO_URL}\",
\"pom\": {
\"sha1\": \"${POM_SHA1}\",
\"sha256\": \"${POM_SHA256}\"
},
\"jar\": {
\"sha1\": \"${JAR_SHA1}\",
\"sha256\": \"${JAR_SHA256}\"