From 062c3e4438ad3c2a20b80abe2c1df9d5a0df317b Mon Sep 17 00:00:00 2001 From: JohnnyJayJay Date: Thu, 10 Oct 2024 19:39:52 +0200 Subject: [PATCH] support adding leiningen profiles for downloading deps --- docs/lock-file.md | 3 +++ src/cljnix/core.clj | 17 ++++++++++------- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/docs/lock-file.md b/docs/lock-file.md index 21a68f5..5c621ca 100644 --- a/docs/lock-file.md +++ b/docs/lock-file.md @@ -87,6 +87,9 @@ ignored files: nix run github:jlesquembre/clj-nix#deps-lock -- --lein ``` +By default, all custom profiles (if any) are merged to download the dependencies. +This can be customized with the `--lein-profiles` option. + Keep in mind that `deps-lock` command is not optimized for Leiningen projects, it will download all the maven dependencies every time we generate the lock file. For that reason, it is recommended to add a `deps.edn` file with the same diff --git a/src/cljnix/core.clj b/src/cljnix/core.clj index 9b384e5..f62e7e8 100644 --- a/src/cljnix/core.clj +++ b/src/cljnix/core.clj @@ -297,19 +297,18 @@ "uberjar" "update" "offline" - "debug"}) - (string/join ","))) + "debug"}))) (defn- download-lein-deps - [cache-dir] + [cache-dir profiles] (let [lein-home (str (fs/path cache-dir "lein"))] (fs/create-dir lein-home) (spit (str (fs/path lein-home "profiles.clj")) {:user {:local-repo (str (fs/path cache-dir mvn-cache-subdir))}}) - (let [profiles (lein-project-profiles)] + (let [profiles (or (seq profiles) (lein-project-profiles))] (if (empty? profiles) (sh/sh "lein" "deps" :env {"LEIN_HOME" lein-home}) - (sh/sh "lein" "with-profiles" profiles "deps" :env {"LEIN_HOME" lein-home}))))) + (sh/sh "lein" "with-profiles" (string/join "," profiles) "deps" :env {"LEIN_HOME" lein-home}))))) (defn- add-to-nix-store! [{:keys [local-path lib rev] :as dep}] @@ -374,7 +373,7 @@ ([project-dir] (lock-file project-dir {})) ([project-dir {:keys [extra-mvn extra-git - lein?] + lein? lein-profiles] :or {extra-mvn [] extra-git []} :as opts}] @@ -392,7 +391,7 @@ (update :git into git))) (fn [{:keys [mvn git mvn-repos]}] (when lein? - (download-lein-deps cache-dir)) + (download-lein-deps cache-dir lein-profiles)) (sorted-map-by map-comparator :lock-version LOCK-VERSION @@ -444,6 +443,10 @@ {:desc "Include Leiningen dependecies." :validate {:pred boolean?}} + :lein-profiles + {:desc "If Leiningen dependencies are included, the Leiningen profiles to use. If not given, all custom profiles are used." + :coerce []} + :deps-include {:desc "List of 'deps.edn' files to parse. All files are included by default." :coerce []