Connect to Remote REPLλ︎
Using a remote REPL can provide a collaborative coding environment as well as a means for working within remote environments (docker images, cloud servers, etc).
Running a remote REPL can also provide longevity to the process, as many clients (editors, ssh terminals) can connect to the REPL over time, disconnecting from the running process without interrupting the process. This provides a very resilient way of running a REPL.
practicalli/clojure-deps-edn provides many aliases to configure a REPL to work with other community tools. These aliases are easier to manage when running a REPL outside of an editor which automatically injects its own configuration. This configuration can be installed into the remote environment and ideally added into the server build process.
Establish a remote environmentλ︎
A small Virtual Private Server (VPS) is enough for a remote Clojure environment.
Micro VPS on Google Cloud
- Install Clojure CLI tools and practicalli/clojure-deps-edn configuration
- Git Client
- SSH server
- Set up user account
- Generate a permissions file,
.pemfrom the server (TODO: how to generate .pem files)
|Google Cloud f1-micro VPS
|1 x 2.6GHz
Configure local SSH connectionλ︎
.pem file to
~/.ssh/ directory (or your preferred location).
~/.ssh/config file (create the file if needed) and add a host configuration for the remote server.
Add the IP address of the remote server to
LocalForward for the port used by the nREPL server.
Configure Emacs to listen to nREPL portλ︎
Connect to a Clojure REPL that was started with nREPL and Cider middleware, e.g.
Edit the Emacs
init.el file and add the following configuration.
Start REPL on remote serverλ︎
The majority of Clojure aware editors can connect to an external REPL using the nREPL protocol. Emacs CIDER, VSCode Calva and NeoVim Conjure all use nREPL and the Cider middleware.
practicalli/clojure-deps-edn defines the
:middleware/clj alias that includes several libraries required for the nREPL connection between CIDER and the REPL.
SSH into the remote server.
Clone an existing project with Git, or create a new project with
Change to a Clojure project
Start the REPL using the cider middleware on the same port as defined in
LocalForward in the SSH configuration, using the
-p to set the port number.
Open a terminal in the root directory of a Clojure project and run a non-interactive REPL process
The REPL will start along with an nREPL server, showing the connection details.
.nrepl-port file is created in the root of the Clojure project, containing the port number the nREPL server is listening upon.
Using a REPL terminal UI
For a rich terminal REPL experience, start the REPL with rebel readline as well as nREPL and CIDER libraries.
Connect via Trampλ︎
Tramp enables Spacemacs to be used to open remote files as if they were local files, using an SSH connection to the remote server.
SPC f f to open a file and enter an ssh address to access the Clojure project files on the remote server
, ' to call
sesman-start and choose
cider-connect-clj which should find the remote host and port
Confirm the host name, typically
localhost when running the REPL locally
Confirm the port number the nREPL server is listening too
Spacemacs is now connected to the REPL and Clojure code can be evaluated in the source code buffers.