about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--fun/gemma/build.lisp5
-rw-r--r--fun/gemma/default.nix71
-rw-r--r--fun/gemma/gemma.asd33
-rw-r--r--fun/gemma/src/gemma.lisp21
-rw-r--r--third_party/default.nix1
5 files changed, 40 insertions, 91 deletions
diff --git a/fun/gemma/build.lisp b/fun/gemma/build.lisp
deleted file mode 100644
index e935ce25fde4..000000000000
--- a/fun/gemma/build.lisp
+++ /dev/null
@@ -1,5 +0,0 @@
-(require :asdf)
-(require :sb-posix)
-
-(push (format nil "~A/" (sb-posix:getcwd)) asdf:*central-registry*)
-(asdf:operate 'asdf:program-op :gemma)
diff --git a/fun/gemma/default.nix b/fun/gemma/default.nix
index f48af489217a..53b47f7cb9fa 100644
--- a/fun/gemma/default.nix
+++ b/fun/gemma/default.nix
@@ -1,61 +1,50 @@
 { pkgs, ... }:
 
 let
-  inherit (pkgs) elmPackages lispPackages;
-  inherit (pkgs.third_party) stdenv sbcl makeWrapper openssl;
+  inherit (pkgs) elmPackages;
+  inherit (pkgs.third_party) cacert iana-etc libredirect stdenv runCommandNoCC;
 
   frontend = stdenv.mkDerivation {
-    name = "gemma-frontend";
+    name = "gemma-frontend.html";
     src = ./frontend;
-    buildInputs = [ elmPackages.elm ];
+    buildInputs = [ cacert iana-etc elmPackages.elm ];
+
+    # The individual Elm packages this requires are not packaged and I
+    # can't be bothered to do that now, so lets open the escape hatch:
+    outputHashAlgo = "sha256";
+    outputHash = "000xhds5bsig3kbi7dhgbv9h7myacf34bqvw7avvz7m5mwnqlqg7";
 
     phases = [ "unpackPhase" "buildPhase" ];
     buildPhase = ''
+      export NIX_REDIRECTS=/etc/protocols=${iana-etc}/etc/protocols \
+        LD_PRELOAD=${libredirect}/lib/libredirect.so
+
+      export SYSTEM_CERTIFICATE_PATH=${cacert}/etc/ssl/certs
+
       mkdir .home && export HOME="$PWD/.home"
-      mkdir -p $out
-      elm-make --yes Main.elm --output $out/index.html
+      elm-make --yes Main.elm --output $out
     '';
   };
-in stdenv.mkDerivation rec {
+
+  injectFrontend = pkgs.writeText "gemma-frontend.lisp" ''
+    (in-package :gemma)
+    (setq *static-file-location* "${runCommandNoCC "frontend" {} ''
+      mkdir -p $out
+      cp ${frontend} $out/index.html
+    ''}}")
+  '';
+in pkgs.nix.buildLisp.program {
   name = "gemma";
-  src = ./.;
 
-  nativeBuildInputs = with lispPackages; [
-    sbcl
-    hunchentoot
+  deps = with pkgs.third_party.lisp; [
     cl-json
-    cffi
     cl-prevalence
+    hunchentoot
     local-time
-    makeWrapper
   ];
 
-  buildPhase = ''
-    mkdir -p $out/share/gemma $out/bin
-
-    # Build Lisp using the Nix-provided wrapper which sets the load
-    # paths correctly.
-    cd $src
-    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";
-
-  # Stripping an SBCL executable removes the application, which is unfortunate.
-  dontStrip = true;
-
-  meta = with stdenv.lib; {
-    description = "Tool for tracking recurring tasks";
-    homepage    = "https://github.com/tazjin/gemma";
-    license     = licenses.gpl3;
-
-    # Lisp builds are broken for some reason (2019-09-22)
-    broken = true;
-  };
+  srcs = [
+    ./src/gemma.lisp
+    injectFrontend
+  ];
 }
diff --git a/fun/gemma/gemma.asd b/fun/gemma/gemma.asd
deleted file mode 100644
index 0aea9c95ff92..000000000000
--- a/fun/gemma/gemma.asd
+++ /dev/null
@@ -1,33 +0,0 @@
-#|
-  This file is part of Gemma.
-
-  Gemma is free software: you can redistribute it and/or modify it
-  under the terms of the GNU General Public License as published by
-  the Free Software Foundation, either version 3 of the License, or
-  (at your option) any later version.
-
-  Copyright (c) 2017 Vincent Ambo
-|#
-
-(require 'sb-posix)
-
-(defsystem "gemma"
-  :version "0.1.0"
-  :author "Vincent Ambo"
-  :license "GPLv3"
-  :depends-on (local-time
-               hunchentoot
-               cl-json
-               cl-prevalence)
-  :components ((:module "src"
-                :components
-                ((:file "gemma"))))
-  :build-operation program-op
-  :build-pathname #.(or (pathname  (sb-posix:getenv "GEMMA_BIN_TARGET"))
-                        "gemma")
-  :entry-point "gemma::entrypoint"
-  :description "Gemma is a household task management system"
-  :long-description
-  #.(read-file-string
-     (subpathname *load-pathname* "README.markdown"))
-  :in-order-to ((test-op (test-op "gemma-test"))))
diff --git a/fun/gemma/src/gemma.lisp b/fun/gemma/src/gemma.lisp
index b8a20addd907..cf074cfb8701 100644
--- a/fun/gemma/src/gemma.lisp
+++ b/fun/gemma/src/gemma.lisp
@@ -1,4 +1,4 @@
-;; Copyright (C) 2016-2017  Vincent Ambo <mail@tazj.in>
+;; Copyright (C) 2016-2020  Vincent Ambo <mail@tazj.in>
 ;;
 ;; This file is part of Gemma.
 ;;
@@ -13,7 +13,7 @@
         :cl-json)
   (:import-from :sb-posix :getenv)
   (:shadowing-import-from :sb-posix :getcwd)
-  (:export :start-gemma :config :entrypoint))
+  (:export :start-gemma :config :main))
 (in-package :gemma)
 
 ;; TODO: Store an average of how many days it was between task
@@ -29,19 +29,16 @@
 (defvar *gemma-port* 4242
   "Port on which the Gemma web server listens.")
 
-(defvar *static-file-location*
-  (or (in-case-of (sb-posix:getenv "out")
-        (concatenate 'string it "/share/gemma/"))
-      "frontend/")
+(defvar *static-file-location* "frontend/"
   "Folder from which to serve static assets. If built inside of Nix,
-  the folder is concatenated with the output path at which the files
-  are expected to be.")
+  the path is injected during the build.")
 
-(defun initialise-persistence (data-dir)
-  (defvar *p-tasks*
-    (cl-prevalence:make-prevalence-system data-dir)
+(defvar *p-tasks* nil
     "All tasks registered in this Gemma instance.")
 
+(defun initialise-persistence (data-dir)
+  (setq *p-tasks* (cl-prevalence:make-prevalence-system data-dir))
+
   ;; Initialise database ID counter
   (or (> (length (cl-prevalence:find-all-objects *p-tasks* 'task)) 0)
       (cl-prevalence:tx-create-id-counter *p-tasks*)))
@@ -161,7 +158,7 @@ maximum interval."
      (complete-task key)
      (encode-json-to-string (response-for (get-task key))))))
 
-(defun entrypoint ()
+(defun main ()
   "This function serves as the entrypoint for ASDF-built executables.
   It joins the Hunchentoot server thread to keep the process running
   for as long as the server is alive."
diff --git a/third_party/default.nix b/third_party/default.nix
index 1df13abd2e92..fca4ce94c1f5 100644
--- a/third_party/default.nix
+++ b/third_party/default.nix
@@ -54,6 +54,7 @@ let
       jq
       kontemplate
       lib
+      libredirect
       lispPackages
       llvmPackages
       luajit