missed some changes

This commit is contained in:
root@procul 2020-07-16 15:46:52 -05:00
parent 8af542c16b
commit 115548495f
3 changed files with 81 additions and 18 deletions

View File

@ -5,6 +5,8 @@ let
cfg = config.informis.cl-gemini; cfg = config.informis.cl-gemini;
lisp-libs = with pkgs.lispPackages; [ lisp-libs = with pkgs.lispPackages; [
asdf-package-system
asdf-system-connections
alexandria alexandria
asdf-package-system asdf-package-system
asdf-system-connections asdf-system-connections
@ -16,21 +18,17 @@ let
usocket usocket
]; ];
launchServer = load-paths: ip: port: root: public-dir: key: cert: slynk-port: launchServer = ip: port: root: public-dir: key: cert: slynk-port: feeds-string: textfiles-archive:
let pkgs.writeText "launch-server.lisp" ''
load-path-string =
concatStringsSep " " (map (path: "\"${path}\"") load-paths);
in pkgs.writeText "launch-server.lisp" ''
(load (merge-pathnames "quicklisp/setup.lisp" (user-homedir-pathname))) (load (merge-pathnames "quicklisp/setup.lisp" (user-homedir-pathname)))
(setf asdf:*central-registry*
(append asdf:*central-registry*
(list ${load-path-string})))
(ql:quickload :slynk) (ql:quickload :slynk)
(ql:quickload :cl-gemini) (ql:quickload :cl-gemini)
${optionalString (slynk-port != null) "(slynk:create-server :port ${toString slynk-port} :dont-close t)"} ${optionalString (slynk-port != null) "(slynk:create-server :port ${toString slynk-port} :dont-close t)"}
${feeds-string}
(cl-gemini:start-gemini-server "${ip}" "${key}" "${cert}" (cl-gemini:start-gemini-server "${ip}" "${key}" "${cert}"
:port ${toString port} :port ${toString port}
:document-root "${root}" :document-root "${root}"
:textfiles-root "${textfiles-archive}"
:file-cmd "${pkgs.file}/bin/file" :file-cmd "${pkgs.file}/bin/file"
:log-stream *standard-output* :log-stream *standard-output*
:threaded t :threaded t
@ -44,6 +42,36 @@ let
]; ];
}); });
feedOpts = with types; {
options = {
url = mkOption {
type = str;
description = "Base URI of the feed, i.e. the URI corresponding to the feed path.";
example = "gemini://my.server/path/to/feedfiles";
};
title = mkOption {
type = str;
description = "Title of given feed.";
example = "My Fancy Feed";
};
path = mkOption {
type = str;
description = "Path to Gemini files making up the feed.";
example = "/path/to/feed";
};
};
};
register-feed = name: opts: ''
(cl-gemini:register-feed :name "${name}" :title "${opts.title}" :path "${opts.path}" :base-uri "${opts.url}")'';
register-feeds = feeds:
concatStringsSep "\n"
(mapAttrsToList register-feed feeds);
in { in {
options.informis.cl-gemini = with types; { options.informis.cl-gemini = with types; {
enable = mkEnableOption "Enable the cl-gemini server."; enable = mkEnableOption "Enable the cl-gemini server.";
@ -61,9 +89,9 @@ in {
}; };
document-root = mkOption { document-root = mkOption {
type = path; type = str;
description = "Root at which to look for gemini files."; description = "Root at which to look for gemini files.";
example = /my/gemini/root; example = "/my/gemini/root";
}; };
user-public = mkOption { user-public = mkOption {
@ -89,6 +117,25 @@ in {
description = "Port on which to open a slynk server, if any."; description = "Port on which to open a slynk server, if any.";
default = null; default = null;
}; };
feeds = mkOption {
type = loaOf (submodule feedOpts);
description = "Feeds to generate and make available (as eg. /feed/name.xml).";
example = {
diary = {
title = "My Diary";
path = "/path/to/my/gemfiles/";
url = "gemini://my.host/blog-path/";
};
};
default = {};
};
textfiles-archive = mkOption {
type = str;
description = "A path containing only gemini & text files.";
example = "/path/to/textfiles/";
};
}; };
config = mkIf cfg.enable { config = mkIf cfg.enable {
@ -124,13 +171,11 @@ in {
description = "cl-gemini Gemini server (https://gemini.circumlunar.space/)"; description = "cl-gemini Gemini server (https://gemini.circumlunar.space/)";
serviceConfig = let serviceConfig = let
load-paths = (map (pkg: "${pkg}/lib/common-lisp//") feed-registrations = register-feeds cfg.feeds;
(lisp-libs ++ [pkgs.cl-gemini]));
in { in {
ExecStartPre = "${pkgs.lispPackages.quicklisp}/bin/quicklisp init"; ExecStartPre = "${pkgs.lispPackages.quicklisp}/bin/quicklisp init";
ExecStart = "${sbcl-with-ssl}/bin/sbcl --load ${ ExecStart = "${sbcl-with-ssl}/bin/sbcl --load ${
launchServer launchServer
load-paths
cfg.server-ip cfg.server-ip
cfg.port cfg.port
cfg.document-root cfg.document-root
@ -138,6 +183,8 @@ in {
"/etc/cl-gemini/key.pem" "/etc/cl-gemini/key.pem"
"/etc/cl-gemini/cert.pem" "/etc/cl-gemini/cert.pem"
cfg.slynk-port cfg.slynk-port
feed-registrations
cfg.textfiles-archive
}"; }";
Restart = "on-failure"; Restart = "on-failure";
PIDFile = "/run/cl-gemini.$USERNAME.uid"; PIDFile = "/run/cl-gemini.$USERNAME.uid";
@ -146,9 +193,15 @@ in {
environment = { environment = {
LD_LIBRARY_PATH = "${pkgs.openssl_1_1.out}/lib"; LD_LIBRARY_PATH = "${pkgs.openssl_1_1.out}/lib";
CL_SOURCE_REGISTRY = concatStringsSep ":"
(["${config.users.users.cl-gemini.home}/quicklisp/quicklisp"] ++
(map
(pkg: "${pkg}//")
(lisp-libs ++ [pkgs.cl-gemini])));
}; };
path = with pkgs; [ path = with pkgs; [
gcc
file file
getent getent
]; ];

View File

@ -267,9 +267,19 @@ in {
enable = true; enable = true;
server-ip = host_ipv4; server-ip = host_ipv4;
document-root = /srv/gemini; document-root = "/srv/gemini/root";
ssl-private-key = acme-private-key "informis.land"; ssl-private-key = "/srv/gemini/private/key.pem";
ssl-certificate = acme-certificate "informis.land"; ssl-certificate = "/srv/gemini/private/cert.pem";
slynk-port = 4005; slynk-port = 4005;
textfiles-archive = "/srv/gemini/textfiles";
feeds = {
viator = {
title = "viator's phlog";
path = "/home/viator/gemini-public/feed/";
url = "gemini://informis.land/user/viator/feed/";
};
};
}; };
} }

View File

@ -9,8 +9,8 @@ in stdenv.mkDerivation {
src = fetchgit { src = fetchgit {
url = "https://git.informis.land/viator/cl-gemini.git"; url = "https://git.informis.land/viator/cl-gemini.git";
rev = "a4596703a4e7ff628639ea4a2350591e4db9a32d"; rev = "3de4d1945fc91d0c9f8f65a5d4b0d3f39fbdaa80";
sha256 = "18zqgx200fd32kgbpfhvcnlwanzmjk3f0ggiks0n579zkhzslxs0"; sha256 = "1xzfsp5vp36a3yas5pnhj2a1dd72r72fw3l49ah19hvbapaikhsw";
fetchSubmodules = false; fetchSubmodules = false;
}; };