Frederick's Aerie

Running a Swank Server Within a Guix Shell

by Frederick M. Muriithi -- Sat 21 May 2022

Steps

First off, add the sbcl-slime-swank package to your manifest. In case you do not want to add it to the manifest that will be used for the production system, you could create a new dev-manifest.scm and "import" the production manifest.


	 ;; dev-manifest.scm
	 (use-modules (guix profiles))

	 (define %runtime-manifest (load "./prod-manifest.scm"))

	 (concatenate-manifests
	  (list %runtime-manifest
		(specifications->manifest
		 (list "sbcl-slime-swank"))))
	 

The next step is to declare that your project depends on swank within your project's .asd file


	 ;; the-awesome-project.asd
	 (asdf:defsystem #:awesome-project
			 :description "An awesome project"
			 :author "Me <my@ema.il>"
			 :license  "MIT"
			 :version "0.0.1"
			 :serial t
			 :pathname "src"
			 :depends-on (...
  				      ...
				      #:swank)
			 :components ((:file ...)))

Now you can launch the shell: guix shell --container --network --manifest=dev-manifest.scm

Within the shell in the container, you can now start the lisp image and launch the swank server.

Launch your CL implementation and load the application definitions


		$ sbcl
		  * (require 'asdf)
		  < some output ... >
		  * (asdf:load-asd (merge-pathnames "qc-uploads.asd" (uiop/os:getcwd)))
		  < some output ... >
		  * (asdf:load-system :qc-uploads)
		  < possibly a lot of output as files are compiled ... >
		  * (swank:create-server)
		  ;; Swank started at port: 4005.
		  4005

And now you have a swank server running within a guix shell container, that, thanks to the --network option, can be accessed on you host system.

On your emacs, you can connect to the swank server with M-x slime-connect, set your host as "localhost" (without the quotes) and the port to the port selected when starting the swank server (default 4005).

Now go forth and embrace the parens!!!

Context and Motivation

I found myself working on a Common Lisp project to do a few minor fixes.

The first thing I tried was to run the thing within a guix shell, and immediately caught a number of issues, among which were the fact that you can't really run quicklisp within a guix shell container guix shell --container.

This is my attempt to make this easier for the next person who might need it.