about summary refs log tree commit diff
path: root/nix/buildLisp
diff options
context:
space:
mode:
authorVincent Ambo <Vincent Ambo>2020-01-09T03·32+0000
committerVincent Ambo <Vincent Ambo>2020-01-09T03·32+0000
commit09720e2da267c22f3e135c2cb3843a269c53a65b (patch)
treebf8e9bca4b809652aa5ce9a7949731c94a554910 /nix/buildLisp
parent44820827d191b9a7bec152b5a51d101661e8f4a5 (diff)
fix(buildLisp): Wrap executables to set load paths correctly r/365
I can not currently find a way to set the CFFI variables correctly to
get it to load libraries from Nix.

In the absence of that feature, a wrapper also does the trick.
Diffstat (limited to 'nix/buildLisp')
-rw-r--r--nix/buildLisp/default.nix24
-rw-r--r--nix/buildLisp/example/main.lisp2
2 files changed, 10 insertions, 16 deletions
diff --git a/nix/buildLisp/default.nix b/nix/buildLisp/default.nix
index 15dc5f73e4..66de386631 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 runCommandNoCC writeText writeShellScriptBin sbcl;
+  inherit (pkgs.third_party) lib runCommandNoCC makeWrapper writeText writeShellScriptBin sbcl;
 
   #
   # Internal helper definitions
@@ -77,15 +77,6 @@ let
     lib.flatten (native ++ (map (d: d.lispNativeDeps) deps))
   );
 
-  # 'pushLibDirs' generates forms that push all native library paths
-  # onto the variable `CFFI:*FOREIGN-LIBRARY-DIRECTORIES*` which is
-  # required for any runtime loading of libraries via CFFI.
-  pushLibDirs = deps: lib.concatStringsSep "\n" (
-    map (l: "(push \"${
-      lib.getLib l
-    }/lib\" cffi:*foreign-library-directories*)") (allNative [] deps)
-  );
-
   # 'genDumpLisp' generates a Lisp file that instructs SBCL to dump
   # the currently loaded image as an executable to $out/bin/$name.
   #
@@ -96,10 +87,6 @@ let
 
     ${genLoadLisp deps}
 
-    ;; Push library directories if CFFI is in use.
-    (when (boundp 'cffi:*foreign-library-directories*)
-      ${pushLibDirs deps})
-
     (let* ((bindir (concatenate 'string (sb-posix:getenv "out") "/bin"))
            (outpath (make-pathname :name "${name}"
                                    :directory bindir)))
@@ -150,15 +137,22 @@ let
   program = { name, main ? "${name}:main", srcs, deps ? [], native ? [] }:
   let
     lispDeps = allDeps deps;
+    libPath = lib.makeLibraryPath (allNative native lispDeps);
     selfLib = library {
       inherit name srcs native;
       deps = lispDeps;
     };
-  in runCommandNoCC "${name}" {} ''
+  in runCommandNoCC "${name}" {
+    nativeBuildInputs = [ makeWrapper ];
+    LD_LIBRARY_PATH = libPath;
+  } ''
     mkdir -p $out/bin
+
     ${sbcl}/bin/sbcl --script ${
       genDumpLisp name main ([ selfLib ] ++ lispDeps)
     }
+
+    wrapProgram $out/bin/${name} --prefix LD_LIBRARY_PATH : "${libPath}"
   '';
 
   # 'sbclWith' creates an image with the specified libraries /
diff --git a/nix/buildLisp/example/main.lisp b/nix/buildLisp/example/main.lisp
index f98bb8409a..a29390cf4d 100644
--- a/nix/buildLisp/example/main.lisp
+++ b/nix/buildLisp/example/main.lisp
@@ -4,4 +4,4 @@
 (in-package :example)
 
 (defun main ()
-  (format t "i <3 ~S" (who)))
+  (format t "i <3 ~A~%" (who)))