Getting kit-clj to work on FreeBSD with Emacs

A few days back, yogthos announced a new web framework for Clojure called Kit. Getting it to work properly with my current tools proved a bit tricky, so I’m writing down my notes here.

Kit on FreeBSD

Note: This is no longer necessary. The bug I reported has now been fixed.

If you try running Kit according to the instructions on FreeBSD, it will fail with an error. To be precise, running clojure -X, e.g. clojure -X:deps help/doc :ns help, will display:

Execution error (FileNotFoundException) at clojure.main/main (main.java:40).
Could not locate clojure/run/exec__init.class, clojure/run/exec.clj or clojure/run/exec.cljc on classpath.

This means the exec.jar file included with clojure-tools is not present in the appropriate directory. On FreeBSD, this directory is /usr/local/share/clojure/libexec.

To fix this problem, download clojure-tools-1.10.3.1020.tar.gz for Linux from the clojure website, extract it, and copy exec.jar to /usr/local/share/clojure/libexec.

I reported this as a bug, and I see there’s an upcoming package upgrade that will fix it.

Kit with Emacs

Note: This is no longer necessary. You can now run nREPL with the CIDER middleware by running clj -M:dev:cider.

By default, Kit does not use nREPL, which makes it impossible to connect to with CIDER (or Clojure Sublimed). I’m looking into fixing this, but for now my workaround is:

  1. Add nREPL to your ~/.clojure/deps.edn (or ~/.config/clojure/deps.edn - depending on your OS) as described here. Essentially, my :aliases section looks like this:
  :aliases {
    :new {:extra-deps {com.github.seancorfield/clj-new {:mvn/version "1.2.362"}}
        :exec-fn clj-new/create
        :exec-args {:template "app"}}

    :nREPL
          {:extra-deps
           {nrepl/nrepl {:mvn/version "0.9.0"}
            cider/piggieback {:mvn/version "0.4.2"}}}
  }
  1. Run your Kit project with clj -M:dev:nREPL to force Clojure to load the extra dependencies. That feels easier that making such changes locally to every new project you create. nREPL should now be loaded as an additional dependency in your project.
  2. In the Clojure app that you just launched, embed the nREPL server in your project by running the commands described here:
=> (require '[nrepl.server :refer [start-server stop-server]])
nil
=> (defonce server (start-server :port 7888))
='user/server
  1. In Emacs, run cider-connect and connect to port 7888.
  2. From the new CIDER window, issue the (go) command to launch the Kit application.