charleso / sbt2nix

Generate Nix build instructions from a SBT project
MIT License
38 stars 7 forks source link

Add Nix resolver to SBT #7

Open charleso opened 10 years ago

charleso commented 10 years ago

So we can take advantage of all the goodies that SBT has, and in particular incremental compilation. Without this the initial dev experience is going to suffer in Nix (I suspect).

It's probably a good idea to look at how cabal2nix solves this with with nix-shell. It maybe easier than I think, but I'm not sure.

The sooner we get this the better (and more useful) this plugin is going to be!

charleso commented 10 years ago

So cabal2nix basically wraps the ghci command with a script that dynamically adds the relevant -package-db flags based on the current $PATH which includes anything with .installedconf. See wrapper.nix.

I don't think doing this for SBT is going to be quite as simple. A few options come to mind:

  1. Write a specific Nix SBT resolver that looks in the surrounding environment and resolves packages appropriately.
  2. Generate a separate build.sbt on-the-fly with the relevant details. I really don't like this option as it's very prone to breakage between SBT versions.
  3. Generate a separate/temporary repository by symlinking to nix artifacts and then set the -Dsbt.override.build.repos=true and -Dsbt.repository.config flags.

http://www.scala-sbt.org/0.13/docs/Proxy-Repositories.html

Regardless of these options we would almost certainly need to keep a copy of the relevant ivy file (or equivalent) for each dependency to make the connection between Nix artifact and org/module/version.

Suggestions welcome.

puffnfresh commented 9 years ago

Generate a heap of symlinks under the unmanaged jars directory. Skip Ivy.

coreyoconnor commented 8 years ago

I was reading through the coursier resolver docs and source

This has similar aspects that might be usable. In particular the cache only mode. From what I can read, Coursier uses this to implement a sandbox mode: isolated dependencies tree without requiring network access.

At least "chances are" that's what it enables: "If all your dependencies are in cache, chances are coursier will not even try to connect to remote repositories"

The layout of cache directory is a fairly obvious map of upstream / package / version. A quick hack might be:

charleso commented 8 years ago

@coreyoconnor Thanks for the suggestion. However, I feel like that would be more complicated than just generating the unmanaged jar symlinks like Brian suggested. Nix is doing the rest anyway.

That said, it's not like I'm actually actively doing anything on this project, so feel free to ignore me. :)

cessationoftime commented 7 years ago

https://github.com/teozkr/Sbtix currently has an implementation that makes use of https://github.com/alexarchambault/coursier and pretty nearly does what coreyoconnor suggests. The coursier cache directory isn't populated with dependencies directly, instead sbt is given access to a local repo of dependencies which have been found by coursier and cached by nix-prefetch-url.