How to build a lisp binary with nix build

I’m attempting to build a simple lisp binary with a nix flake. The issue is that after the image builds and dumps to an executable, when running it, it just says “Can’t find sbcl.core”. I need the derivation to create an executable, much like nyxt is, but the lisp-modules info in the nixpkgs manual doesn’t help me much with building an executable.

I have a minimal example here: Chris Cochrun / test-lisp-nix · GitLab

If you clone that and run nix build, you’ll get a result, but it won’t run. Any help would be hugely appreciated, I have been banging my head on this forever.

Looking at nixpkgs, it looks like most of the lisp packages it provides are built with build-asdf-system, which calls stdenv.mkDerivation with some fixed parameters. Specifically, it sets the dontStrip argument to mkDerivation to true, with a comment that this has “caused problems with SBCL save-lisp-and-die binaries in the past” — presumably, that there were problems when this was not set.

Simply adding dontStrip = true; fixed the build for me. You could also try using pkgs.sbcl.buildASDFSystem, which is the way in which build-asdf-system is made available outside of nixpkgs’ lisp build system. Note that you cannot use this with the sbcl' you’ve defined with serapeum — the buildASDFSystem attribute is not kept by sbcl.withPackages. If you need to add lisp dependencies, you should do that by adding a lispLibs attribute to the argument of sbcl.buildASDFSystem.

That was perfect!! So, switching from stdenv.mkDerivation to pkgs.sbcl.buildASDFSystem makes sure that everything is done right, and specifically that don'tStrip marker. Ok, so I’ll need to switch to using the lispLibs but other than that, it works as intended! Thank you!