Fork me on GitHub
#clj-on-windows
<
2022-09-26
>
respatialized14:09:28

I have a emacs/WSL question. As far as I understand it, most people using Clojure on WSL launch their REPLs inside the WSL environment, because that's where emacs is usually running. I've been trying to launch my Clojure REPL from within Windows via pwsh and then use cider-connect to attach to it from emacs under WSL using the Windows IP and REPL port. Even though I can ping and curl the WSL IP (so at least some of my firewall settings are working properly), cider-connect always times out. Has anyone successfully connected to a Windows Clojure process from within WSL? What do I need to look out for?

chucklehead00:09:42

starting nREPL process on Windows side:

clj -Sdeps '{:deps {cider/cider-nrepl {:mvn/version ""0.28.5""}}}' -m nrepl.cmdline --middleware "[cider.nrepl/cider-middleware]" -b 0.0.0.0 -p 51248
in WSL, cat /etc/resolv.conf and look at the IP for the nameserver, that's the IP you want to use for cider-connect In my case I can cider-connect from WSL to 127.21.192.1 port 51248 to connect to the Windows REPL.

1
chucklehead00:09:56

my guess is however you're starting the repl in Windows is binding to localhost and you need to bind it to 0.0.0.0 instead

chucklehead00:09:54

you can access WSL localhost services from Windows, but not Windows localhost services from WSL

respatialized12:09:02

I was able to get this working by binding to 0.0.0.0 - thanks for the pointer. There's actually an easier way from WSL to get the Windows address (at least in WSL2 which has some DNS convenience stuff) - you can just run $(hostname).local and use that address for cider-connect. However, establishing the connection is extremely slow (upwards of 2 minutes to connect for the first time). Ordinary REPL commands seem to work fine without much latency once the connection is open, but it's still slow enough to be a major hassle when initializing a project. I'm not quite sure how to go about diagnosing that, but at least I know this method works.