Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve/fix Leiningen usage #145

Merged
merged 4 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
3 changes: 2 additions & 1 deletion helpers.nix
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ in
);

assert (pkgs'.lib.assertMsg
(cfg.withLeiningen == true -> cfg.compileCljOpts == false && cfg.javacOpts == false)
(cfg.withLeiningen == true -> isNull cfg.compileCljOpts && isNull cfg.javacOpts)
"Leiningen is incompatible with Clojure tools.build options (compileCljOpts and javacOpts)"
);

Expand All @@ -73,6 +73,7 @@ in
inherit (cfg) projectSrc name version main-ns buildCommand
lockfile java-opts compileCljOpts javacOpts
builder-extra-inputs builder-java-opts builder-preBuild builder-postBuild;
enableLeiningen = cfg.withLeiningen;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 that was the idea, thanks!

};
in

Expand Down
19 changes: 11 additions & 8 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 "," (cons "user" 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 All @@ -466,7 +469,7 @@
[]
(println "deps-lock usage:\n")
(println (cli/format-opts {:spec cli-spec
:order [:deps-include :deps-exclude :alias-include :alias-exclude :bb :lein :help]})))
:order [:deps-include :deps-exclude :alias-include :alias-exclude :bb :lein :lein-profiles :help]})))

(defn- cli-parse-options
[args]
Expand Down