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 relative paths in `:local/root` #129

Closed volisoft closed 1 month ago

volisoft commented 2 months ago

Seems like relative paths in :local/root are not supported. Here's an example project. Here's the error indicating that local library at ../../components/liba cannot be found:

       last 10 log lines:
       > no configure script, doing nothing
       > Running phase: preBuildPhase
       > Running phase: buildPhase
       > Picked up JAVA_TOOL_OPTIONS: -Duser.home=/nix/store/33qbkrdp0hij5x5iq0xljqw6i36zgld4-clj-cache
       > check com.demo.liba.interface for :gen-class
       > Execution error (ExceptionInfo) at clojure.tools.deps.extensions.local/ensure-file (local.clj:41).
       > Local lib com.demo/liba not found: /components/liba

Such relative paths are supported by Clojure deps and are common in polylith projects.

Originally posted by @volisoft in https://github.com/jlesquembre/clj-nix/issues/7#issuecomment-2282244478

jlesquembre commented 1 month ago

thanks for the example project, looks like a bug, I'll take a look

jlesquembre commented 1 month ago

I was playing with polylith, and the way to build an uberjar is a bit different, it doesn't work with the default clj-nix builder, but that has nothing to do with :local/root (which are supported by clj-nix) As an example, you can see how to build a polylith project with clj-nix here:

https://github.com/jlesquembre/usermanager-example

Run:

nix build .
result/bin/main

Take a look at the flake.nix file: https://github.com/jlesquembre/usermanager-example/commit/e4a71afbd3a86092d9b9ee8500d61fc20b9b4715

Notice that flake.nix needs to be at the root of the project, and that we need a custom build.clj file.

Maybe we could try to add support for polylith, to avoid the need for a custom build.clj file.

volisoft commented 1 month ago

Thank you for taking a look. Is it possible to keep flake.nix in the projects directory?

In my actual repository there's already a flake.nix in the project's root, which sets up development tools. Also, potentially, there can be multiple separate projects under projects directory, each with it's own assets and build process.

jlesquembre commented 1 month ago

Is it possible to keep flake.nix in the projects directory?

It is, but instead of doing that, I'd create multiple packages within the flake, something like this:

packages = {
        webapp = clj-nix.lib.mkCljApp ...;
        cliapp = clj-nix.lib.mkCljApp ...;
};

if your repository is open source, could you share a link to it?

volisoft commented 1 month ago

That looks interesting. Will each project require a separate deps.lock file? If so, should the lock files be placed in the appropriate project's directory?

I'm afraid the repository I'm working with is private, so I cannot share it. However, it's a typical Polylith mono-repository. I can add another sub-project to the demo project if you need something for testing.

jlesquembre commented 1 month ago

You only need one deps.lock file. clj-nix looks for all deps.edn files in the repository. You can include/exclude certain files and aliases. For details, see: https://jlesquembre.github.io/clj-nix/lock-file/

volisoft commented 1 month ago

That works. Thank you for your help!

jlesquembre commented 1 month ago

@volisoft I'd like to play around with Polylith, and maybe add support for it in clj-nix. However, given the flexibility of Polylith, it might be more practical to provide a custom build.clj.

volisoft commented 1 month ago

I believe build.clj is a suitable solution. Since others may encounter this situation as well, adding a hint in the documentation pointing to this solution could be very helpful.