diff options
Diffstat (limited to 'nix')
-rw-r--r-- | nix/buildLisp/default.nix | 34 |
1 files changed, 30 insertions, 4 deletions
diff --git a/nix/buildLisp/default.nix b/nix/buildLisp/default.nix index 9d96b66d595c..641a9a8c4ed7 100644 --- a/nix/buildLisp/default.nix +++ b/nix/buildLisp/default.nix @@ -61,10 +61,25 @@ let lib.unique (lib.flatten (deps ++ (map (d: d.lispDeps) deps))) ); - - # - # Public API functions + # 'genDumpLisp' generates a Lisp file that instructs SBCL to dump + # the currently loaded image as an executable to $out/bin/$name. # + # TODO(tazjin): Compression is currently unsupported because the + # SBCL in nixpkgs is, by default, not compiled with zlib support. + genDumpLisp = name: main: deps: writeText "dump.lisp" '' + (require 'sb-posix) + + ${genLoadLisp deps} + + (let* ((bindir (concatenate 'string (sb-posix:getenv "out") "/bin")) + (outpath (make-pathname :name "${name}" + :directory bindir))) + (save-lisp-and-die outpath + :executable t + :toplevel (function ${main}) + :purify t)) + ;; + ''; # Add an `overrideLisp` attribute to a function result that works # similar to `overrideAttrs`, but is used specifically for the @@ -73,6 +88,10 @@ let overrideLisp = new: makeOverridable f (orig // (new orig)); }; + # + # Public API functions + # + # 'library' builds a list of Common Lisp files into a single FASL # which can then be loaded into SBCL. library = { name, srcs, deps ? [] }: runCommandNoCC "${name}-cllib" {} '' @@ -85,7 +104,14 @@ let # 'program' creates an executable containing a dumped image of the # specified sources and dependencies. - program = {}; + program = { name, main ? "${name}:main", srcs, deps ? [] }: runCommandNoCC "${name}" {} '' + mkdir -p $out/bin + ${sbcl}/bin/sbcl --script ${ + genDumpLisp name main (lib.singleton (library { + inherit name srcs deps; + })) + } + ''; # 'sbclWith' creates an image with the specified libraries / # programs loaded. |