From 3c6617c0f250f14bf6df7227e49bac33276a02c4 Mon Sep 17 00:00:00 2001 From: Johnny <39348311+JohnnyJayJay@users.noreply.github.com> Date: Thu, 10 Oct 2024 17:32:56 +0200 Subject: [PATCH 1/4] Fix unsatisfiable condition for withLeiningen --- helpers.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helpers.nix b/helpers.nix index 6da8dff..27ee4d5 100644 --- a/helpers.nix +++ b/helpers.nix @@ -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)" ); From 8775f9440bd46043683cea48c4805aa5df324c99 Mon Sep 17 00:00:00 2001 From: JohnnyJayJay Date: Thu, 10 Oct 2024 19:04:56 +0200 Subject: [PATCH 2/4] bind withLeiningen module option to enableLeiningen attribute --- helpers.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/helpers.nix b/helpers.nix index 27ee4d5..6725a0a 100644 --- a/helpers.nix +++ b/helpers.nix @@ -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; }; in From c80f6912152a5b5e367dfeceab11d16f2454491d Mon Sep 17 00:00:00 2001 From: JohnnyJayJay Date: Thu, 10 Oct 2024 19:39:52 +0200 Subject: [PATCH 3/4] support adding leiningen profiles for downloading deps --- docs/lock-file.md | 3 +++ src/cljnix/core.clj | 19 +++++++++++-------- 2 files changed, 14 insertions(+), 8 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..f4667a2 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 [] @@ -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] From 1a51ab78a808cef10f93f0c1d44caa7a731d42d1 Mon Sep 17 00:00:00 2001 From: JohnnyJayJay Date: Thu, 10 Oct 2024 23:28:42 +0200 Subject: [PATCH 4/4] fix: always add user profile when fetching leiningen deps --- src/cljnix/core.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cljnix/core.clj b/src/cljnix/core.clj index f4667a2..dbce589 100644 --- a/src/cljnix/core.clj +++ b/src/cljnix/core.clj @@ -308,7 +308,7 @@ (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" (string/join "," 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}]