jlesquembre / clj-nix

Nix helpers for Clojure projects
https://jlesquembre.github.io/clj-nix/
Eclipse Public License 2.0
146 stars 22 forks source link

Support for aliases/alternative `create-basis` #32

Open thenonameguy opened 1 year ago

thenonameguy commented 1 year ago

This might be possible today, but I have yet to figure it out how it would be doable: I want to build 2 uberjars from my application code.

  1. the "normal" one, just using deps.edn with no aliaes whatsoever.
  2. a custom dev-specific one, just with AOT'd code. This way FE devs are not compiling every single day the whole classpath including :test and :dev aliases from scratch.

Use-case 1. works perfectly. For 2. I tried defining a custom buildCommand with a build.clj that calls create-basis with the necessary aliases. This didn't work as it tried resolving the maven dependency ranges during sandboxed build-time (network calls). https://github.com/clojure/tools.deps.alpha/blob/master/src/main/clojure/clojure/tools/deps/alpha/extensions/maven.clj#L79-L80

From a preliminary look https://github.com/bevuta/clojure-nix-locker seems to be able to solve this problem using it's design, but I much prefer clj-nix conceptually and don't want to switch away for this reason. Is this a solveable problem using the current lock-file layout?

jlesquembre commented 1 year ago

hi, if I understood it, in theory you should be able to do that (use any aliases in a custom buildCommand)

But there are some corner cases with maven I wasn't able to solve yet. Specifically, if one of your dependencies uses version ranges, sometime maven hits the network. What is the dependency giving you problems?

I remember in clojure-lsp, maven insisted on downloading a dependency even if it was excluded:

https://github.com/jlesquembre/clojure-lsp/blob/58947e43f51641b571682918a63e4e1e6b54bc4a/cli/deps.edn#L6-L7

The solution was hacky, I added a file to the maven cache, so maven thought that the dependency was there: https://github.com/jlesquembre/clojure-lsp/blob/58947e43f51641b571682918a63e4e1e6b54bc4a/flake.nix#L36-L49

Can you share the problematic dependency to check if it's the same issue? I'd like to have a proper solution for this case, but unfortunately I didn't have too much time to work onclj-nix lately.

One last question, are you sure that https://github.com/bevuta/clojure-nix-locker will work on your case? My understanding is that clojure-nix-locker should face the same issue. If not, I'll take a look again to see how they fixed it.