Common lisp on guix

Table of Contents

1. Loading systems

The package cl-asdf is patched (see gnu/packages/patches/cl-asdf-config-directories.patch) to make asdf look for "source registry" configurations under common-lisp/source-registry.conf.d/ in each path specified in then environment variable XDG_CONFIG_DIRS. And when a common lisp package is installed, a corresponding configuration file is added. Which means that by default, asdf on guix should be able to load common lisp packages installed with guix.

2. Package variants

Most common lisp packages in guix comes in 3 variants:

  • plain: just the source files and system definitions, e.g. cl-asdf
  • pre-compiled for sbcl: sbcl-cl-asdf
  • pre-compiled for ecl: ecl-cl-asdf

3. Version of asdf

sbcl "notoriously" does not come with the latest version of asdf, but guix's package for sbcl is patched it so that it does ship with the latest version of asdf.

4. Prevent asdf from trying to write to guix's store

When mixing systems from guix or nix (which are immutable) and systems from quicklisp (which are mutable), sometimes, asdf might try to (re)compile systems that are immutable and will try to write files in the store (which is not writable).

Here's a function that iterates over all available systems and tell asdf that they are immutable if they're located under the directory /gnu/store.

(defun mark-guix-packages-as-immutable ()
  (asdf:map-systems
   (lambda (system)
     (when (and (asdf:system-source-file system)
                (= (length #1="/gnu/store")
                   (mismatch #1#
                             (namestring (asdf:system-source-file system)))))
       (format *debug-io* "~&System ~a is located in guix's store.~%" system)
       (asdf:register-immutable-system system)))))

I have this function in my ~/.sbclrc.

I also bound it to the keyword :asdf-guix because it's much more convenient to type (binding functions to keywords is not possible on all common lisp implementation, IIRC, lispworks doesn't like it, but sbcl is totally fine with it).

Futhermore, I've added (pushnew 'mark-guix-packages-as-immutable asdf/driver:*clear-configuration-hook*) so that I don't have to actually worry about calling this manually. When asdf fails to load a system, it provides a restart to "clear configuration and retry", so this will effectively mark as immutable the systems that needs to be marked as such and will retry to load the system.

5. Related notes

6. Backlinks

Created: 2025-03-20 Thu 01:16