fix: nix stuff and config

This commit is contained in:
2026-02-28 20:26:55 -07:00
parent 17e61aabc8
commit 6ef81a4a45
11 changed files with 304 additions and 37 deletions

View File

@@ -8,7 +8,8 @@
hiccup/hiccup {:mvn/version "2.0.0-RC4"}
com.rpl/specter {:mvn/version "1.1.6"}
lambdaisland/deep-diff2 {:mvn/version "2.12.219"}
mvxcvi/clj-cbor {:mvn/version "1.1.1"}}
mvxcvi/clj-cbor {:mvn/version "1.1.1"}
ch.qos.logback/logback-classic {:mvn/version "1.1.3"}}
:paths ["src" "resources" "test"]
:aliases
{:test {:extra-deps {lambdaisland/kaocha {:mvn/version "1.91.1392"}}

View File

@@ -3,7 +3,6 @@
, makeWrapper
, ibm-plex
, callPackage
, our-tex ? callPackage ./our-tex.nix {}
}:
buildNpmPackage {
@@ -13,7 +12,4 @@ buildNpmPackage {
npmDeps = importNpmLock { npmRoot = ./.; };
npmConfigHook = importNpmLock.npmConfigHook;
dontNpmBuild = true;
buildInputs = [
our-tex
];
}

View File

@@ -1,8 +1,13 @@
{ mkCljBin
, callPackage
, lib
, doerg-parser
, doerg-tex
, ibm-plex-web
, fake-git
, our-tex ? callPackage ./our-tex.nix {}
, makeWrapper
, breakpointHook
}:
let
@@ -19,6 +24,11 @@ let
plex = ibm-plex-web.override {
families = [ "math" "serif" "sans" "sans-kr" ];
};
bin-path = lib.makeBinPath [
doerg-parser
our-tex
doerg-tex
];
in mkCljBin' {
name = "net.deertopia/doerg";
version = "0.1.0";
@@ -27,9 +37,32 @@ in mkCljBin' {
main-ns = "net.deertopia.doerg.main";
nativeBuildInputs = [
plex
makeWrapper
breakpointHook
];
buildInputs = [
doerg-parser
doerg-tex
plex
our-tex
];
nativeCheckInputs = [
doerg-parser
doerg-tex
plex
our-tex
];
doCheck = true;
checkPhase = ''
clojure -M:test
'';
postInstall = ''
wrapProgram $out/bin/doerg \
--prefix PATH : ${bin-path}
'';
# installPhase= ''
# runHook preInstall
# exit 1
# runHook postInstall
# '';
}

View File

@@ -4,16 +4,32 @@
[spec-dict.main :refer [dict]]))
(s/def ::config
(s/keys :req [::ibm-plex-web]))
(s/keys :req [::ibm-plex-web
::latex
::dvisvgm]))
(s/def ::file
#(or (instance? java.io.File %)
(string? %)))
(def default
{::ibm-plex-web
(fs/file
(or (System/getenv "IBM_PLEX_WEB")
(some #(let [x (fs/path % "ibm-plex-web")]
(and (fs/exists? x) x))
(fs/split-paths (System/getenv "XDG_DATA_DIRS")))))})
(or (System/getenv "DOERG_IBM_PLEX_WEB")
(fs/file (some #(let [x (fs/path % "ibm-plex-web")]
(and (fs/exists? x) x))
(fs/split-paths (System/getenv "XDG_DATA_DIRS")))))
::latex "xelatex"
::dvisvgm "dvisvgm"
;; TODO: Can we automatically set this to "./doerg-tex/index.js" in
;; a development environment?
::doerg-tex "doerg-tex"})
(def ^:dynamic *cfg* default)
(s/def ::ibm-plex-web #(instance? java.io.File %))
(s/def ::ibm-plex-web ::file)
(s/def ::latex ::file)
(s/def ::dvisvgm ::file)
(s/def ::doerg-tex ::file)

View File

@@ -200,10 +200,7 @@
(deliver promise (hiccup/raw temml))))
(catch Exception e
(lr/error e)
(throw e))))
(when (fs/exists? "/tmp/doerg-svgs")
(fs/delete-tree "/tmp/doerg-svgs"))
(fs/copy-tree svg-dir "/tmp/doerg-svgs"))))
(throw e)))))))
fut (future-call (bound-fn* f))]
;; Time out after eight seconds. With all the LaTeX and IPC, there
;; are so many opportunities for things to go wrong </3.

View File

@@ -6,7 +6,8 @@
[clojure.java.io :as io]
[clojure.string :as str]
[clojure.tools.logging :as l]
[babashka.fs :as fs])
[babashka.fs :as fs]
[net.deertopia.doerg.config :as cfg])
(:import (java.io ByteArrayOutputStream)))
(def ^:private scale-divisor 66873.46948423679)
@@ -80,20 +81,21 @@
errors))))))
acc))))
(defn- invoke-latex [& {:keys [file output-dir latex]
:or {latex "xelatex"}}]
(invoke
{:dir output-dir}
latex "-no-pdf" "-interaction" "nonstopmode"
"-output-directory" output-dir file))
(defn- invoke-latex [& {:keys [file output-dir]}]
(let [latex (::cfg/latex cfg/*cfg*)]
(invoke
{:dir output-dir}
latex "-no-pdf" "-interaction" "nonstopmode"
"-output-directory" output-dir file)))
(defn- invoke-dvisvgm [& {:keys [file output-dir]}]
(invoke
{:dir output-dir}
"dvisvgm" "--page=1-" "--optimize" "--clipjoin"
"--relative" "--no-fonts" "-v3"
"--message=processing page {?pageno}: output written to {?svgpath}"
"--bbox=preview" "-o" "%9p.svg" file))
(let [dvisvgm (::cfg/dvisvgm cfg/*cfg*)]
(invoke
{:dir output-dir}
dvisvgm "--page=1-" "--optimize" "--clipjoin"
"--relative" "--no-fonts" "-v3"
"--message=processing page {?pageno}: output written to {?svgpath}"
"--bbox=preview" "-o" "%9p.svg" file)))
(defn- snippet-file-names
"Return a map of TeX snippets (as strings, including the math

View File

@@ -1,6 +1,7 @@
(ns net.deertopia.doerg.tex.temml
(:require [babashka.process :as p]
[net.deertopia.doerg.common :as common]
[net.deertopia.doerg.config :as cfg]
[clj-cbor.core :as cbor]
[clojure.java.io :as io]
[clojure.string :as str]
@@ -16,13 +17,13 @@
(def ^:dynamic *worker*)
(defn worker [& {:keys [preamble]}]
(p/process
{:shutdown p/destroy-tree
:err (l/log-stream :info "temml/err")}
#_"doerg-tex"
"./doerg-tex/index.js"
"--preamble"
"resources/net/deertopia/doerg/prelude.tex"))
(let [doerg-tex (::cfg/doerg-tex cfg/*cfg*)]
(p/process
{:shutdown p/destroy-tree
:err (l/log-stream :info "temml/err")}
doerg-tex
"--preamble"
"resources/net/deertopia/doerg/prelude.tex")))
(defn close-worker [tw]
(.close (:in tw)))

1
doerg/tests.edn Normal file
View File

@@ -0,0 +1 @@
#kaocha/v1 {}