Skip to content

bevuta/clojure-nix-locker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

clojure-nix-locker

Simple and flexible tool to build clojure projects with Nix.

Usage

The example/ directory has a small clojure program and the nix code required to build it.

Stable non-flake way

To generate/update the lockfile:

nix-shell --run clojure-nix-locker

To build:

nix-build -A uberjar

With flakes

You can generate a flake example with:

mkdir play-with-clojure-nix-locker && cd play-with-clojure-nix-locker && nix flake init -t github:bevuta/clojure-nix-locker

The example README has some next steps.

Why another tool?

There are two existing projects with a similar goal already, clj2nix and clj-nix. Both of these are designed to be used roughly like this:

  • At lock-time, call into clojure.tools.deps to resolve all dependencies, then generate a lockfile from this.
  • At nix-eval-time, use the information from the lockfile to compute the classpath.
  • At build-time, invoke clojure and pass it the precomputed classpath.

By contrast, clojure-nix-locker is designed around letting classpath computation happen later, at build-time. It works roughly like this:

  • At lock-time, call arbitrary user-provided commands (like clojure -P) to pre-populate the caches in .m2 and .gitlibs, then crawl those to generate the lockfile.
  • At nix-eval-time, use the information from the lockfile to recreate these caches in a way that's "close enough" to the real thing.
  • At build-time, invoke clojure as normal. If the prefetching was done correctly, it will resolve its dependencies just fine without hitting the network.

This approach results in a pretty simple implementation and loose coupling to the clojure tooling. As a consequence, things like aliases "just work" without requiring clojure-nix-locker to know about them.

Of course, this has its downsides too:

  • If the directory layout of these caches changes, this tool breaks.
  • Whatever classpath(s) your clojure tools compute at build-time will only work for the duration of that build.

License

Distributed under the GNU General Public License, Version 3. See LICENSE for more details.

About

Simple and flexible tool to build clojure projects with Nix

Topics

Resources

License

Stars

Watchers

Forks

Contributors 5