From 726fe6c32ad19f1110cea6ab12d7d7a1e4c9d949 Mon Sep 17 00:00:00 2001 From: Timo Wilken Date: Sun, 11 Feb 2024 20:39:17 +0100 Subject: Use the less memory-hungry ledgerplot instead of hledger-dashboard --- tw/packages/finance.scm | 77 +++++++++++++++++++++++++++++++++++++++++++++++++ tw/system/vin.scm | 30 +++++++++---------- 2 files changed, 92 insertions(+), 15 deletions(-) diff --git a/tw/packages/finance.scm b/tw/packages/finance.scm index 38b20aa2..facb2bf7 100644 --- a/tw/packages/finance.scm +++ b/tw/packages/finance.scm @@ -1,6 +1,11 @@ (define-module (tw packages finance) + #:use-module (gnu packages databases) + #:use-module (gnu packages finance) #:use-module (gnu packages haskell-xyz) + #:use-module (gnu packages lisp-check) + #:use-module (gnu packages lisp-xyz) #:use-module (guix build-system haskell) + #:use-module (guix build-system asdf) #:use-module (guix gexp) #:use-module (guix git-download) #:use-module (guix packages) @@ -23,3 +28,75 @@ (description "Maintain a database containing financial data extracted from hledger, for use in Grafana, e.g. to create nice graphs.") (license license:gpl3+))) + +;; Upstream binary-types declares "bt" as a package nickname, but +;; bordeaux-threads also uses that, so there's a conflict at load time: +;; https://github.com/Ferada/cl-inotify/issues/3 +;; https://github.com/frodef/binary-types/issues/1 +;; Instead, use a fixed version of binary-types. +(define sbcl-binary-types/fix + (let ((commit "a17caf8890f11fdc56f6ea3a21260bf0fb9c589c")) + (package + (inherit sbcl-binary-types) + (version (git-version "1.2" "2" commit)) + (home-page "https://github.com/Ferada/binary-types") + (source + (origin + (method git-fetch) + (uri (git-reference (url home-page) (commit commit))) + (file-name (git-file-name "binary-types" version)) + (sha256 + (base32 "1bh65p9vg2kgh4m8q1a4jiyncnp5prdzh0d0l4pzh3jvfhgbm0gh"))))))) + +(define sbcl-cl-inotify/fix + (package + (inherit sbcl-cl-inotify) + (inputs (modify-inputs (package-inputs sbcl-cl-inotify) + (replace "sbcl-binary-types" sbcl-binary-types/fix))))) + +(define-public ledgerplot + (package + (name "ledgerplot") + (version "1.1.0") + (source (origin + (method git-fetch) + (uri (git-reference + (url "https://git.twilken.net/ledgerplot") + (commit version))) + (sha256 (base32 "04i6chp2b3vd0i7bj9zp2bfy50mdbjcdr9zqspy9np3y7i48pimv")))) + ;; Ledgerplot only works with SBCL. + (build-system asdf-build-system/sbcl) + (arguments `(#:phases + ,#~(modify-phases %standard-phases + (add-after 'unpack 'patch-executable-names + (lambda* (#:key inputs #:allow-other-keys) + (substitute* (find-files "src" "\\.lisp$") + (("\"hledger\"") + (string-append "\"" (search-input-file inputs "bin/hledger") "\""))))) + (add-after 'create-asdf-configuration 'build-program + (lambda* (#:key outputs #:allow-other-keys) + (build-program + (string-append (assoc-ref outputs "out") "/bin/ledgerplot") + outputs + #:entry-program '((ledgerplot:main) 0))))))) + (inputs (list hledger + sbcl-bordeaux-threads + sbcl-local-time + sbcl-cl-ppcre + sbcl-trivia + sbcl-parse-float + sbcl-unix-opts + sbcl-cl-inotify/fix + sbcl-cl-json + sbcl-cl-csv + sbcl-drakma + sbcl-eazy-gnuplot + sbcl-md5 + sbcl-postmodern)) + (native-inputs (list postgresql-15 ; tests bring up a temporary database + sbcl-fiveam)) + (home-page "https://cgit.twilken.net/ledgerplot/about/") + (synopsis "Visualise data from hledger") + (description "Ledgerplot reads financial data from the hledger plain text +accounting system and processes it into various useful plots.") + (license license:gpl3+))) diff --git a/tw/system/vin.scm b/tw/system/vin.scm index c3cbc50c..4d6b216f 100644 --- a/tw/system/vin.scm +++ b/tw/system/vin.scm @@ -208,32 +208,32 @@ (syncthing-configuration (user "timo"))) (service postgresql-service-type (postgresql-configuration - ;; hledger-dashboard is linked against libpq from postgresql@14. - ;; Using a different Postgres server version is probably fine, though. - (postgresql postgresql-14))) - (simple-service 'hledger-dashboard-roles postgresql-role-service-type + (postgresql postgresql-15))) + (simple-service 'ledgerplot-roles postgresql-role-service-type (list (postgresql-role (name "timo") (create-database? #t) (permissions '(login))))) - (simple-service 'hledger-dashboard shepherd-root-service-type + (simple-service 'ledgerplot shepherd-root-service-type (list (shepherd-service - (provision '(hledger-dashboard)) + (provision '(ledgerplot)) (requirement '(postgresql syncthing-timo)) (documentation "Monitor a ledger file and keep a database in sync with it.") (start #~(make-forkexec-constructor - (list #$(file-append hledger-dashboard "/bin/hledger-dashboard") - ;; This is where Syncthing puts the ledger file. - "-f" "/home/timo/sync/ledger/ledger.journal") + (list #$(file-append ledgerplot "/bin/ledgerplot") + "-wd" "timo") #:user "timo" #:group "users" #:environment-variables - ;; Use an appropriate locale so that hledger-dashboard - ;; can read the UTF-8 ledger file. - (cons* (string-append - "LC_ALL=" #$(locale-definition-name - (car locale-definitions))) - (default-environment-variables)))) + (cons* + ;; This is where Syncthing puts the ledger file. + "LEDGER_FILE=/home/timo/sync/ledger/ledger.journal" + ;; Use an appropriate locale so that ledgerplot + ;; can read the UTF-8 ledger file. + (string-append + "LC_ALL=" #$(locale-definition-name + (car locale-definitions))) + (default-environment-variables)))) (stop #~(make-kill-destructor))))) (service unattended-upgrade-service-type -- cgit v1.2.3