about summary refs log tree commit diff
path: root/services
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@google.com>2019-09-02T01·14+0100
committerVincent Ambo <tazjin@google.com>2019-09-02T01·14+0100
commit4411eea11f799e01d2343ed017e360faf3daef3a (patch)
tree16592d5348670619e61bf6f3c15d6366a46e2697 /services
parentb43e5529f770818710fffd2458e320f49272d26f (diff)
fix(gemma): Fix build process in Nix r/70
Diffstat (limited to 'services')
-rw-r--r--services/gemma/build.lisp26
-rw-r--r--services/gemma/default.nix53
2 files changed, 28 insertions, 51 deletions
diff --git a/services/gemma/build.lisp b/services/gemma/build.lisp
index ce67a91f6585..e935ce25fde4 100644
--- a/services/gemma/build.lisp
+++ b/services/gemma/build.lisp
@@ -1,31 +1,5 @@
-;; Build script for use within Nix.
-
 (require :asdf)
 (require :sb-posix)
-(require :cffi)
 
 (push (format nil "~A/" (sb-posix:getcwd)) asdf:*central-registry*)
-
-;; Quicklisp is configured in the Nix build script
-(let ((quicklisp-init (merge-pathnames "quicklisp/setup.lisp"
-                                       (user-homedir-pathname))))
-  (when (probe-file quicklisp-init)
-    (load quicklisp-init)))
-
-;; OpenSSL linking requires pkg_config on NixOS.
-(ql:quickload "inferior-shell")
-
-(defun pkg-config-lib-path (lib)
-  "Look up the location of a library using pkg-config."
-  (let ((flag (inferior-shell:run `("pkg-config" "--libs-only-L" ,lib)
-                                  :output '(:string :stripped t))))
-    (concatenate 'string (subseq flag 2) "/")))
-
-(pushnew (pathname (pkg-config-lib-path "openssl"))
-         cffi:*foreign-library-directories*
-         :test #'equal)
-
-;; cl-prevalence is not in the current Quicklisp -> Nix snapshot
-(ql:quickload "cl-prevalence")
-
 (asdf:operate 'asdf:program-op :gemma)
diff --git a/services/gemma/default.nix b/services/gemma/default.nix
index 537875b62534..c4ed62dbdea0 100644
--- a/services/gemma/default.nix
+++ b/services/gemma/default.nix
@@ -1,38 +1,45 @@
-{ stdenv, sbcl, lispPackages, elmPackages, pkgconfig }:
+{ stdenv, sbcl, lispPackages, elmPackages, makeWrapper, openssl }:
 
-stdenv.mkDerivation rec {
+let frontend = stdenv.mkDerivation {
+  name = "gemma-frontend";
+  src = ./frontend;
+  buildInputs = [ elmPackages.elm ];
+
+  phases = [ "unpackPhase" "buildPhase" ];
+  buildPhase = ''
+    mkdir .home && export HOME="$PWD/.home"
+    mkdir -p $out
+    ls -lh
+    elm-make --yes Main.elm --output $out/index.html
+  '';
+};
+in stdenv.mkDerivation rec {
   name = "gemma";
   src = ./.;
 
-  buildInputs = with lispPackages; [
+  nativeBuildInputs = with lispPackages; [
     sbcl
-    quicklisp
     hunchentoot
     cl-json
+    cffi
+    cl-prevalence
     local-time
-    elmPackages.elm
-    pkgconfig
+    makeWrapper
   ];
 
-  # The build phase has three distinct things it needs to do:
-  #
-  # 1. "Compile" the Elm source into something useful to browsers.
-  #
-  # 2. Configure the Lisp part of the application to serve the compiled Elm
-  #
-  # 3. Build (and don't strip!) an executable out of the Lisp backend.
   buildPhase = ''
     mkdir -p $out/share/gemma $out/bin
-    mkdir .home && export HOME="$PWD/.home"
 
-    # Build Elm
-    cd frontend
-    elm-make --yes Main.elm --output $out/share/gemma/index.html
-
-    # Build Lisp
+    # Build Lisp using the Nix-provided wrapper which sets the load
+    # paths correctly.
     cd $src
-    quicklisp init
-    env GEMMA_BIN_TARGET=$out/bin/gemma sbcl --load build.lisp
+    env GEMMA_BIN_TARGET=$out/bin/gemma common-lisp.sh --load build.lisp
+
+    # Wrap gemma to find OpenSSL at runtime:
+    wrapProgram $out/bin/gemma --prefix LD_LIBRARY_PATH : "${openssl.out}/lib"
+
+    # and finally copy the frontend to the appropriate spot
+    cp ${frontend}/index.html $out/share/gemma/index.html
   '';
 
   installPhase = "true";
@@ -44,9 +51,5 @@ stdenv.mkDerivation rec {
     description = "Tool for tracking recurring tasks";
     homepage    = "https://github.com/tazjin/gemma";
     license     = licenses.gpl3;
-
-    # For the time being, Gemma can not be built because the Lisp build process
-    # broke in some way I haven't had time to debug.
-    broken = true;
   };
 }