feat(nix): Add Gemma example deployment

This commit is contained in:
Vincent Ambo 2018-01-03 23:02:34 +01:00
parent 9464a1dee4
commit a6a48806c4
3 changed files with 99 additions and 0 deletions

19
nix/gemma-config.lisp Normal file
View file

@ -0,0 +1,19 @@
(config :port 4242
:data-dir "/var/lib/gemma/")
(deftask bathroom/wipe-mirror 7)
(deftask bathroom/wipe-counter 7)
;; Bedroom tasks
(deftask bedroom/change-sheets 7)
(deftask bedroom/vacuum 10)
;; Kitchen tasks
(deftask kitchen/normal-trash 3)
(deftask kitchen/green-trash 5)
(deftask kitchen/blue-trash 5)
(deftask kitchen/wipe-counters 3)
(deftask kitchen/vacuum 5 "Kitchen has more crumbs and such!")
;; Entire place
(deftask clean-windows 60)

54
nix/pkgs/gemma.nix Normal file
View file

@ -0,0 +1,54 @@
{ pkgs ? import <nixpkgs> {} }:
with pkgs; stdenv.mkDerivation rec {
name = "gemma";
src = fetchFromGitHub {
owner = "tazjin";
repo = "gemma";
rev = "61be253d6baa99f0a2208425b8a03b444bb1b184";
sha256 = "0vbmz2aphcida728rc0z3k7gychs4w1778vsjbrs0ljk9qgbmyr5";
};
buildInputs = with lispPackages; [
sbcl
quicklisp
hunchentoot
cl-json
local-time
elmPackages.elm
pkgconfig
];
# 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
cd $src
quicklisp init
env GEMMA_BIN_TARGET=$out/bin/gemma sbcl --load build.lisp
'';
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;
};
}

View file

@ -14,6 +14,11 @@ blogConfig = {
proxyPass = "http://127.0.0.1:8000";
};
};
gemma = import ./pkgs/gemma.nix { inherit pkgs; };
gemmaConfig = writeTextFile {
name = "config.lisp";
text = builtins.readFile ./gemma-config.lisp;
};
in {
# Ensure that blog software is installed
environment.systemPackages = [
@ -47,6 +52,18 @@ in {
rootUrl = "https://git.tazj.in/";
};
# Set up Gemma
systemd.services.gemma = {
description = "Recurring task tracking app";
script = "${gemma}/bin/gemma";
serviceConfig.Restart = "always";
wantedBy = [ "multi-user.target" ];
environment = {
GEMMA_CONFIG = "${gemmaConfig}";
};
};
# Set up reverse proxy
services.nginx = {
enable = true;
@ -72,5 +89,14 @@ in {
forceSSL = true;
extraConfig = "return 302 https://www.google.com/maps/d/viewer?mid=1pJIYY9cuEdt9DuMTbb4etBVq7hs;";
};
# Gemma demo instance!
virtualHosts."gemma.tazj.in" = {
enableACME = true;
forceSSL = true;
locations."/" = {
proxyPass = "http://127.0.0.1:4242";
};
};
};
}