From d1442b306ac20d63c82e8bf4cc51d99f79542b11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Soko=C5=82owski?= Date: Fri, 13 Oct 2023 14:18:40 +0200 Subject: [PATCH] nix: stop downloading POMs for Clojure dependencies MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- nix/deps/clojure/README.md | 5 +++-- nix/deps/clojure/default.nix | 22 +++------------------- nix/deps/clojure/generate.sh | 9 --------- 3 files changed, 6 insertions(+), 30 deletions(-) diff --git a/nix/deps/clojure/README.md b/nix/deps/clojure/README.md index 7f048904a9..5e532669f6 100644 --- a/nix/deps/clojure/README.md +++ b/nix/deps/clojure/README.md @@ -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: diff --git a/nix/deps/clojure/default.nix b/nix/deps/clojure/default.nix index 0b08a6bb30..9bea02a99a 100644 --- a/nix/deps/clojure/default.nix +++ b/nix/deps/clojure/default.nix @@ -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" diff --git a/nix/deps/clojure/generate.sh b/nix/deps/clojure/generate.sh index f2dca2397b..42d34f73a7 100755 --- a/nix/deps/clojure/generate.sh +++ b/nix/deps/clojure/generate.sh @@ -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}\"