about summary refs log tree commit diff
path: root/nix
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@google.com>2020-01-08T18·40+0000
committerVincent Ambo <tazjin@google.com>2020-01-08T18·40+0000
commitca199a57d9b06130f6149a50742bba6c1c75a009 (patch)
tree1770935a7b786ba5d7bf258334453b5468fc841e /nix
parent1297afec4b5d4d343b055e48e0e6961377054ebc (diff)
feat(buildLisp): Implement dependency loading & propagation r/346
Similar to buildGo.nix, the library derivations carry information
about their dependencies which is merged when a load file is
instantiated.

The load files are created when compiling libraries, but will in the
future also be created when wrapping SBCL and dumping images.
Diffstat (limited to 'nix')
-rw-r--r--nix/buildLisp/default.nix20
1 files changed, 16 insertions, 4 deletions
diff --git a/nix/buildLisp/default.nix b/nix/buildLisp/default.nix
index 5a2b7853dcdb..99106315a56a 100644
--- a/nix/buildLisp/default.nix
+++ b/nix/buildLisp/default.nix
@@ -9,7 +9,7 @@
 
 let
   inherit (builtins) map elemAt match;
-  inherit (pkgs.third_party) lib runCommand writeText sbcl;
+  inherit (pkgs.third_party) lib runCommandNoCC writeText sbcl;
 
   #
   # Internal helper definitions
@@ -44,6 +44,18 @@ let
       )
     '';
 
+  # 'allDeps' flattens the list of dependencies (and their
+  # dependencies) into one list of unique deps.
+  allDeps = deps: lib.unique (lib.flatten (deps ++ (map (d: d.lispDeps) deps)));
+
+  # 'genLoadLisp' generates a Lisp file that instructs a Lisp to load
+  # all the provided Lisp libraries.
+  genLoadLisp = deps: writeText "load.lisp" (
+    lib.concatStringsSep "\n" (map (lib: "(load \"${lib}/${lib.lispName}.fasl\")") (allDeps deps))
+  );
+
+  insertLibraryLoads = deps: if deps == [] then "" else "--load ${genLoadLisp deps}";
+
   #
   # Public API functions
   #
@@ -57,13 +69,13 @@ let
 
   # 'library' builds a list of Common Lisp files into a single FASL
   # which can then be loaded into SBCL.
-  library = { name, srcs, deps ? [] }: runCommand "${name}-cllib" {} ''
-    ${sbcl}/bin/sbcl --script ${genCompileLisp srcs}
+  library = { name, srcs, deps ? [] }: runCommandNoCC "${name}-cllib" {} ''
+    ${sbcl}/bin/sbcl ${insertLibraryLoads deps} --script ${genCompileLisp srcs}
 
     # FASL files can be combined by simply concatenating them together:
     mkdir $out
     cat ./*.fasl > $out/${name}.fasl
-  '';
+  '' // { lispName = name; lispDeps = deps; };
 
   # 'program' creates an executable containing a dumped image of the
   # specified sources and dependencies.