Skip to content

Commit

Permalink
support adding leiningen profiles for downloading deps
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnnyJayJay committed Oct 10, 2024
1 parent 8775f94 commit 062c3e4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
3 changes: 3 additions & 0 deletions docs/lock-file.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 10 additions & 7 deletions src/cljnix/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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}]
Expand Down Expand Up @@ -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}]
Expand All @@ -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
Expand Down Expand Up @@ -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 []
Expand Down

0 comments on commit 062c3e4

Please sign in to comment.