refactor(fun/gemma): Use buildLisp.nix to build Gemma
This removes the ASDF system definition for Gemma and switches the code over to buildLisp. The program builds (including some terrifying hacks to get the frontend to work), but there are some bizarre runtime issues that I need to debug.
This commit is contained in:
parent
e25916d10c
commit
78db43898b
5 changed files with 41 additions and 92 deletions
|
@ -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)
|
|
@ -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 {
|
||||
name = "gemma";
|
||||
src = ./.;
|
||||
|
||||
nativeBuildInputs = with lispPackages; [
|
||||
sbcl
|
||||
hunchentoot
|
||||
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";
|
||||
|
||||
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
|
||||
];
|
||||
}
|
||||
|
|
|
@ -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"))))
|
|
@ -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,18 +29,15 @@
|
|||
(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.")
|
||||
|
||||
(defvar *p-tasks* nil
|
||||
"All tasks registered in this Gemma instance.")
|
||||
|
||||
(defun initialise-persistence (data-dir)
|
||||
(defvar *p-tasks*
|
||||
(cl-prevalence:make-prevalence-system data-dir)
|
||||
"All tasks registered in this Gemma instance.")
|
||||
(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)
|
||||
|
@ -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."
|
||||
|
|
1
third_party/default.nix
vendored
1
third_party/default.nix
vendored
|
@ -54,6 +54,7 @@ let
|
|||
jq
|
||||
kontemplate
|
||||
lib
|
||||
libredirect
|
||||
lispPackages
|
||||
llvmPackages
|
||||
luajit
|
||||
|
|
Loading…
Reference in a new issue