Compare commits
3 Commits
main
...
31052a65c8
| Author | SHA1 | Date | |
|---|---|---|---|
| 31052a65c8 | |||
| 2cc1a079a7 | |||
| 6e9531f944 |
17
default.nix
17
default.nix
@@ -33,8 +33,8 @@ let
|
||||
];
|
||||
|
||||
doerg-config = writeText "doerg-extra-config.edn" ''
|
||||
#:net.deertopia.doerg.config
|
||||
{:ibm-plex-web "${ibm-plex-web}/share/ibm-plex-web"
|
||||
#:net.deertopia.doerg
|
||||
{:ibm-plex-web "${ibm-plex-web}"
|
||||
:latex "${lib.getExe' our-tex "xelatex"}"
|
||||
:dvisvgm "${lib.getExe' our-tex "dvisvgm"}"
|
||||
:doerg-temml-worker "${lib.getExe doerg-temml-worker}"
|
||||
@@ -43,21 +43,15 @@ let
|
||||
in mkCljBin' {
|
||||
name = "net.deertopia/doerg";
|
||||
version = "0.1.0";
|
||||
projectSrc = lib.cleanSourceWith {
|
||||
filter = path: type:
|
||||
lib.sources.cleanSourceFilter path type
|
||||
|| lib.hasSuffix ".nix" path;
|
||||
src = ./.;
|
||||
};
|
||||
projectSrc = lib.cleanSource ./.;
|
||||
lockfile = ./deps-lock.json;
|
||||
main-ns = "net.deertopia.doerg.main";
|
||||
nativeBuildInputs = [
|
||||
plex
|
||||
makeWrapper
|
||||
];
|
||||
propagatedBuildInputs = [
|
||||
buildInputs = [
|
||||
doerg-parser
|
||||
ibm-plex-web
|
||||
doerg-temml-worker
|
||||
plex
|
||||
our-tex
|
||||
@@ -79,6 +73,5 @@ in mkCljBin' {
|
||||
XDG_STATE_HOME=$(mktemp -d "state-home-XXXXXX")
|
||||
clojure -M:test
|
||||
'';
|
||||
passthru = { inherit plex our-tex test-emacs doerg-config; };
|
||||
meta.mainProgram = "doerg";
|
||||
passthru = { inherit plex our-tex test-emacs; };
|
||||
}
|
||||
|
||||
17
dev/user.clj
17
dev/user.clj
@@ -1,17 +0,0 @@
|
||||
(ns user
|
||||
(:require [net.deertopia.doerg.server :as server]
|
||||
[net.deertopia.doerg.config :as cfg]
|
||||
[net.deertopia.doerg.cached-file :as cached-file]
|
||||
[babashka.fs :as fs]))
|
||||
|
||||
(cfg/load-config! :profile :dev)
|
||||
|
||||
(when (not= :running (server/status))
|
||||
(server/start!))
|
||||
|
||||
(defn invalidate-html-cache! []
|
||||
(fs/delete-tree (server/html-dir))
|
||||
nil)
|
||||
|
||||
(defn toggle-html-cache! []
|
||||
(alter-var-root #'cached-file/*use-cache?* not))
|
||||
27
flake.nix
27
flake.nix
@@ -14,15 +14,12 @@
|
||||
"x86_64-linux"
|
||||
];
|
||||
|
||||
overlays = [
|
||||
inputs.sydpkgs.overlays.default
|
||||
clj-nix.overlays.default
|
||||
];
|
||||
|
||||
each-system = f: nixpkgs.lib.genAttrs supportedSystems (system: f rec {
|
||||
pkgs = import nixpkgs {
|
||||
inherit system;
|
||||
overlays = overlays ++ [
|
||||
overlays = [
|
||||
inputs.sydpkgs.overlays.default
|
||||
clj-nix.overlays.default
|
||||
self.overlays.default
|
||||
];
|
||||
};
|
||||
@@ -39,17 +36,13 @@
|
||||
});
|
||||
|
||||
overlays.default = final: prev:
|
||||
let
|
||||
# is this really the correct way to satisfy our
|
||||
# dependencies? lmfao
|
||||
final' = final.appendOverlays overlays;
|
||||
graal = x: final'.mkGraalBin { cljDrv = x; };
|
||||
let graal = x: final.mkGraalBin { cljDrv = x; };
|
||||
in {
|
||||
ibm-plex-web = final'.callPackage ./ibm-plex-web.nix {};
|
||||
doerg = final'.callPackage ./. {};
|
||||
doerg-parser = final'.callPackage ./doerg-parser {};
|
||||
doerg-temml-worker = final'.callPackage ./doerg-temml-worker {};
|
||||
our-tex = final'.callPackage ./our-tex.nix {};
|
||||
ibm-plex-web = final.callPackage ./ibm-plex-web.nix {};
|
||||
doerg = final.callPackage ./. {};
|
||||
doerg-parser = final.callPackage ./doerg-parser {};
|
||||
doerg-temml-worker = final.callPackage ./doerg-temml-worker {};
|
||||
our-tex = final.callPackage ./our-tex.nix {};
|
||||
};
|
||||
|
||||
checks = each-system ({ pkgs, system, ... }: {
|
||||
@@ -59,8 +52,6 @@
|
||||
(pkgs.lib.attrValues self.packages.${system});
|
||||
});
|
||||
|
||||
nixosModules.default = import ./module.nix { inherit self; };
|
||||
|
||||
devShells = each-system ({ pkgs, system, ... }: {
|
||||
default = pkgs.mkShell {
|
||||
inputsFrom = [
|
||||
|
||||
107
module.nix
107
module.nix
@@ -1,107 +0,0 @@
|
||||
{ self, ... }:
|
||||
{ config, lib, pkgs, ... }:
|
||||
|
||||
let
|
||||
cfg = config.services.doerg;
|
||||
doerg-config = pkgs.writeText "doerg-config.edn" ''
|
||||
#:net.deertopia.doerg.config
|
||||
{:org-roam-db-path "${cfg.databasePath}"
|
||||
:state-directory "${cfg.stateDir}"
|
||||
:port ${builtins.toString cfg.port}}
|
||||
'';
|
||||
|
||||
inherit (lib) types;
|
||||
|
||||
org-roam-db-sync = pkgs.writeText "org-roam-db-sync.el" ''
|
||||
#!/usr/bin/env -S emacs -Q -x
|
||||
|
||||
(require 'org-roam)
|
||||
|
||||
(setq org-roam-directory (expand-file-name (car command-line-args-left)))
|
||||
(setq org-roam-db-location (expand-file-name (cadr command-line-args-left)))
|
||||
|
||||
(org-roam-db-sync)
|
||||
'';
|
||||
in {
|
||||
options.services.doerg = {
|
||||
enable = lib.mkEnableOption "Doerg";
|
||||
org-roam-db-sync.enable = lib.mkEnableOption "Org-roam db sync";
|
||||
port = lib.mkOption {
|
||||
default = 21984;
|
||||
type = lib.types.port;
|
||||
description = ''
|
||||
The port on which Doerg will listen.
|
||||
'';
|
||||
};
|
||||
stateDir = lib.mkOption {
|
||||
type = types.path;
|
||||
default = "/var/lib/private/doerg";
|
||||
description = "Daemon's state directory.";
|
||||
};
|
||||
orgDir = lib.mkOption {
|
||||
type = types.path;
|
||||
description = "Org roam directory.";
|
||||
};
|
||||
package = lib.mkPackageOption pkgs "doerg" {};
|
||||
databasePath = lib.mkOption {
|
||||
type = types.path;
|
||||
description = "Org roam database path";
|
||||
default = cfg.orgDir + "org-roam.db";
|
||||
};
|
||||
openFirewall = lib.mkOption {
|
||||
type = types.bool;
|
||||
description = "Open doerg ports?";
|
||||
default = false;
|
||||
};
|
||||
};
|
||||
|
||||
config = lib.mkIf cfg.enable {
|
||||
nixpkgs.overlays = [ self.overlays.default ];
|
||||
|
||||
systemd.services.org-roam-db-sync = lib.mkIf cfg.org-roam-db-sync.enable {
|
||||
script = lib.escapeShellArgs [
|
||||
(lib.getExe cfg.package.test-emacs)
|
||||
"-Q" "-x" org-roam-db-sync cfg.orgDir cfg.databasePath
|
||||
];
|
||||
serviceConfig = {
|
||||
Type = "oneshot";
|
||||
ReadOnlyBindPaths = [
|
||||
cfg.orgDir
|
||||
];
|
||||
};
|
||||
};
|
||||
|
||||
systemd.timers.org-roam-db-sync = lib.mkIf cfg.org-roam-db-sync.enable {
|
||||
unitConfig.StopWhenUnneeded = true;
|
||||
timerConfig = {
|
||||
OnActiveSec = "1h";
|
||||
RandomizedDelaySec = "30m";
|
||||
Persistent = true;
|
||||
};
|
||||
};
|
||||
|
||||
networking.firewall.allowedTCPPorts = lib.mkIf cfg.openFirewall [
|
||||
cfg.port
|
||||
];
|
||||
|
||||
systemd.services.doerg = {
|
||||
after = [ "network-online.target" ];
|
||||
wants = [ "network-online.target" "org-roam-db-sync.timer" ];
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
environment.DOERG_CONFIG = doerg-config;
|
||||
serviceConfig = {
|
||||
# WorkingDirectory = cfg.stateDir;
|
||||
StateDirectory = "doerg";
|
||||
ExecStart = lib.getExe cfg.package;
|
||||
DynamicUser = true;
|
||||
ProtectSystem = "strict";
|
||||
PrivateTmp = true;
|
||||
BindReadOnlyPaths = [
|
||||
cfg.orgDir
|
||||
# cfg.databasePath
|
||||
"/nix"
|
||||
];
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
#:net.deertopia.doerg.config
|
||||
{:ibm-plex-web #or [#env IBM_PLEX_WEB
|
||||
#xdg-data-dir "ibm-plex-web"]
|
||||
{:ibm-plex-web #or [#xdg-data-dir "ibm-plex-web"
|
||||
#env IBM_PLEX_WEB]
|
||||
:latex "xelatex"
|
||||
:dvisvgm "dvisvgm"
|
||||
:doerg-temml-worker
|
||||
|
||||
@@ -18,10 +18,8 @@
|
||||
calling `compute` with no arguments only if stale? is logical true."
|
||||
[& {:keys [file stale? compute]}]
|
||||
(when (or (not *use-cache?*) stale?)
|
||||
(let [r (compute)
|
||||
dir (fs/parent file)]
|
||||
(let [r (compute)]
|
||||
(assert (string? r))
|
||||
(when-not (fs/exists? dir)
|
||||
(fs/create-dirs dir))
|
||||
(fs/create-dirs (fs/parent file))
|
||||
(spit file r)))
|
||||
file)
|
||||
|
||||
@@ -46,8 +46,7 @@
|
||||
"Aero tag to search for a directory on $XDG_DATA_DIRS."
|
||||
(some #(let [x (fs/path % value)]
|
||||
(and (fs/exists? x) x))
|
||||
(some-> (System/getenv "XDG_DATA_DIRS")
|
||||
fs/split-paths)))
|
||||
(fs/split-paths (System/getenv "XDG_DATA_DIRS"))))
|
||||
|
||||
(defmethod aero/reader 'file
|
||||
[{:keys [source]} tag value]
|
||||
@@ -67,6 +66,9 @@
|
||||
(throw (ex-info "Failed to conform config"
|
||||
(s/explain-data ::config r))))))
|
||||
|
||||
(defn load-config! [var spec files & {:as opts}]
|
||||
(alter-var-root var (constantly (read-config files opts))))
|
||||
|
||||
(def sources
|
||||
[;; Default config.
|
||||
(io/resource "net/deertopia/doerg/default-config.edn")
|
||||
@@ -78,10 +80,3 @@
|
||||
(def default (read-config sources))
|
||||
|
||||
(def ^:dynamic *cfg* default)
|
||||
|
||||
(defn load-config!
|
||||
([& {:as opts :keys [files]
|
||||
:or {files sources}}]
|
||||
(let [passthru-opts (-> opts (dissoc :files))]
|
||||
(alter-var-root
|
||||
#'*cfg* (constantly (read-config files passthru-opts))))))
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
[babashka.process :as p]
|
||||
[cheshire.core :as json]
|
||||
[clojure.core.match :refer [match]]
|
||||
[net.deertopia.doerg :as-alias doerg]
|
||||
[clojure.java.io :as io]
|
||||
[clojure.set :as set]
|
||||
[clojure.string :as str]
|
||||
@@ -34,7 +35,7 @@
|
||||
:or {in *in*}}]
|
||||
(let [r (-> (p/process
|
||||
{:in in :out :string}
|
||||
(-> cfg/*cfg* ::cfg/doerg-parser str))
|
||||
(-> cfg/*cfg* ::doerg/doerg-parser str))
|
||||
(common/deref-with-timeout *uniorg-timeout-duration*))]
|
||||
(when (zero? (:exit r))
|
||||
(-> r :out (json/parse-string (comp keyword camel->kebab))))))
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
(ns net.deertopia.doerg.main
|
||||
(:require [net.deertopia.doerg.server :as server]
|
||||
[net.deertopia.doerg.config :as cfg])
|
||||
(:gen-class))
|
||||
|
||||
(defn -main [& _]
|
||||
(binding [cfg/*cfg* (cfg/read-config cfg/sources)]
|
||||
(server/start!)))
|
||||
(defn -main []
|
||||
(println "hello from doerg"))
|
||||
|
||||
@@ -63,19 +63,16 @@
|
||||
|
||||
(defn org-document
|
||||
"Recursively render an Org-mode document to Hiccup."
|
||||
[doc & {:as opts :keys [postamble header title]}]
|
||||
[doc & {:as opts :keys [postamble]}]
|
||||
(binding [*opts* opts]
|
||||
(tex-temml/binding-worker
|
||||
(let [rendered (-> doc gather-footnotes render-tex-snippets
|
||||
org-element-recursive)]
|
||||
[:html
|
||||
[:head
|
||||
(when title
|
||||
[:title title])
|
||||
[:title "org document"]
|
||||
doerg-html/head]
|
||||
[:body {:lang default-language}
|
||||
(when header
|
||||
[:header header])
|
||||
[:article
|
||||
rendered
|
||||
(when postamble
|
||||
@@ -276,14 +273,11 @@
|
||||
(defmethod org-element "bold" [{:keys [children]}]
|
||||
[:b children])
|
||||
|
||||
(defmethod org-element "strike-through" [{:keys [children]}]
|
||||
[:s children])
|
||||
|
||||
(defmethod org-element "subscript" [{:keys [children]}]
|
||||
[:sub children])
|
||||
|
||||
(defmethod org-element "superscript" [{:keys [children]}]
|
||||
[:sup children])
|
||||
[:super children])
|
||||
|
||||
(defmethod org-element "italic" [{:keys [children]}]
|
||||
[:em children])
|
||||
@@ -388,18 +382,9 @@
|
||||
(defmethod org-keyword "TITLE" [{:keys [value]}]
|
||||
[:h1 value])
|
||||
|
||||
(defmethod org-keyword "SUBTITLE" [{:keys [value]}]
|
||||
[:p.subtitle value])
|
||||
|
||||
(defmethod org-keyword "LATEX_COMPILER" [_] nil)
|
||||
(defmethod org-keyword "LATEX_HEADER" [_] nil)
|
||||
|
||||
;; TODO: A bunch of things I'd rather hide for now, but should be
|
||||
;; implemented eventually.
|
||||
(defmethod org-keyword "FILETAGS" [_] nil)
|
||||
(defmethod org-element "planning" [_] nil)
|
||||
(defmethod org-element "timestamp" [_] nil)
|
||||
|
||||
;; Not sure how to deal with this one yet.
|
||||
(defmethod org-keyword "AUTHOR" [_] nil)
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
(fs/create-dirs dest)
|
||||
(fs/create-dirs resource-dir)
|
||||
(force-create-sym-link (fs/file resource-dir "ibm-plex-web")
|
||||
(-> cfg/*cfg* ::cfg/ibm-plex-web))
|
||||
(-> cfg/*cfg* ::doerg/ibm-plex-web))
|
||||
(doseq [x #{"Temml-Plex.css" "tuftesque.css" "deerstar.css"}]
|
||||
(force-create-sym-link
|
||||
(fs/file resource-dir x)
|
||||
|
||||
@@ -133,15 +133,11 @@
|
||||
elisp/read-alist)))
|
||||
|
||||
(defn public? [node]
|
||||
(some-> (properties node) (get "DEERTOPIAVISIBILITY") (= "public")))
|
||||
|
||||
(defn get-public-node [node]
|
||||
(when-let [n (get-node node)]
|
||||
(when (public? n) n)))
|
||||
(-> node properties (get "DEERTOPIAVISIBILITY") (= "public")))
|
||||
|
||||
(defn graph-visible? [node]
|
||||
(#{"public" "graphonly"}
|
||||
(some-> (properties node) (get "DEERTOPIAVISIBILITY"))))
|
||||
(-> node properties (get "DEERTOPIAVISIBILITY"))))
|
||||
|
||||
(defn backlinks
|
||||
"Returns a collection of nodes linking to `node`."
|
||||
@@ -153,8 +149,7 @@
|
||||
where links.dest = ?"
|
||||
(elisp/print (str (:id node)))])
|
||||
:let [id' (elisp/read-string id)]
|
||||
:when (some-> (-> id' parse-uuid get-node)
|
||||
public?)]
|
||||
:when (-> id' parse-uuid get-node public?)]
|
||||
(make-node id' {:title (elisp/read-string title)})))
|
||||
|
||||
|
||||
|
||||
@@ -23,7 +23,9 @@
|
||||
[net.deertopia.doerg.cached-file :as cached-file]
|
||||
[babashka.fs :as fs]
|
||||
[aero.core :as aero]
|
||||
[clojure.string :as str]))
|
||||
[clojure.string :as str]
|
||||
[net.deertopia.doerg :as-alias doerg]
|
||||
[net.deertopia.doerg.config :as doerg-config]))
|
||||
|
||||
|
||||
;;; Routes
|
||||
@@ -49,13 +51,8 @@
|
||||
(defn html-dir []
|
||||
(-> cfg/*cfg* ::cfg/state-directory (fs/file "html")))
|
||||
|
||||
(declare node-by-slug)
|
||||
|
||||
;; This could infinitely loop if the 404 page can't be found. lmfao.
|
||||
(defn not-found [_req]
|
||||
(-> (node-by-slug {:path-params {:slug not-found-slug}})
|
||||
(assoc :status 404))
|
||||
#_(response/not-found "not found"))
|
||||
(defn not-found [req]
|
||||
(response/not-found "not found"))
|
||||
|
||||
(defn org-file->html-file [org-file]
|
||||
(fs/file (html-dir)
|
||||
@@ -76,34 +73,17 @@
|
||||
#_[:a {:href (str "/n/" (slug/from-uuid path))}
|
||||
(or (seq children) raw-link)]])
|
||||
|
||||
(def navbar
|
||||
"Hiccup element for Deertopia.net's navbar."
|
||||
[:nav.navbar
|
||||
[:ol.navbar-list
|
||||
[:li
|
||||
[:a.home-link {:href "/"}
|
||||
"🦌 deertopia.net"]]
|
||||
#_[:li
|
||||
[:a.home-link {:href "/graph"}
|
||||
"graph"]]
|
||||
#_
|
||||
[:li
|
||||
[:a.home-link {:onclick "alert('unimplemented }:(')"}
|
||||
"search"]]]])
|
||||
|
||||
(defn backlinks-postamble [node]
|
||||
(let [backlinks (roam/backlinks node)]
|
||||
(when-not (empty? backlinks)
|
||||
[:section#backlinks
|
||||
[:h2 "Backlinks"]
|
||||
[:ul
|
||||
(for [n (->> backlinks
|
||||
(for [n (->> (roam/backlinks node)
|
||||
(sort-by (comp str/lower-case roam/title)))]
|
||||
[:li (slug-link (roam/slug n)
|
||||
(roam/title n))])]])))
|
||||
(roam/title n))])]])
|
||||
|
||||
(defn node-by-slug [{{:keys [slug]} :path-params :as req}]
|
||||
(if-some [node (some-> slug slug/from-string roam/get-public-node)]
|
||||
(if-some [node (some-> slug slug/from-string roam/get-node)]
|
||||
(let [org-file (roam/org-file node)
|
||||
html-file (org-file->html-file org-file)]
|
||||
(cached-file/cached-file
|
||||
@@ -111,9 +91,7 @@
|
||||
:stale? (cached-file/newer-than? org-file html-file)
|
||||
:compute #(doerg-render/to-html
|
||||
org-file
|
||||
:postamble (backlinks-postamble node)
|
||||
:header navbar
|
||||
:title (roam/title node)))
|
||||
:postamble (backlinks-postamble node)))
|
||||
(-> (str html-file)
|
||||
response/file-response
|
||||
(response/content-type "text/html")))
|
||||
@@ -140,7 +118,7 @@
|
||||
(if-some [[_ resource] (re-matches #"^/resource/ibm-plex-web/(.*)" uri)]
|
||||
(-> resource
|
||||
(response/file-response
|
||||
{:root (-> cfg/*cfg* ::cfg/ibm-plex-web str)}))
|
||||
{:root (-> doerg-config/*cfg* ::doerg/ibm-plex-web str)}))
|
||||
(-> uri
|
||||
(str/replace-first #"^/resource/" "")
|
||||
(response/resource-response
|
||||
|
||||
@@ -83,14 +83,14 @@
|
||||
acc))))
|
||||
|
||||
(defn- invoke-latex [& {:keys [file output-dir]}]
|
||||
(let [latex (-> cfg/*cfg* ::cfg/latex)]
|
||||
(let [latex (-> cfg/*cfg* ::doerg/latex)]
|
||||
(invoke
|
||||
{:dir output-dir}
|
||||
latex "-no-pdf" "-interaction" "nonstopmode"
|
||||
"-output-directory" output-dir file)))
|
||||
|
||||
(defn- invoke-dvisvgm [& {:keys [file output-dir]}]
|
||||
(let [dvisvgm (-> cfg/*cfg* ::cfg/dvisvgm)]
|
||||
(let [dvisvgm (-> cfg/*cfg* ::doerg/dvisvgm)]
|
||||
(invoke
|
||||
{:dir output-dir}
|
||||
dvisvgm "--page=1-" "--optimize" "--clipjoin"
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
fs/file))
|
||||
|
||||
(defn worker []
|
||||
(let [doerg-temml-worker (-> cfg/*cfg* ::cfg/doerg-temml-worker)]
|
||||
(let [doerg-temml-worker (-> cfg/*cfg* ::doerg/doerg-temml-worker)]
|
||||
(when (or (not (fs/exists? prelude-file))
|
||||
(zero? (fs/size prelude-file)))
|
||||
(-> "net/deertopia/doerg/prelude.tex"
|
||||
|
||||
Reference in New Issue
Block a user