Ivory Siege Tower

mobile construct built of thoughts and parentheses

Adventures in the GuixLand #2: Package Samlpe

[2022-05-10]

guix lisp st_dev

ยง Packaging my precious stuff

Second step of diving into Guix, after initial setting for $HOME and desktop - preserving my own code that is mostly hidden under a carpet but is occasionally useful. Like my lisp utility that outputs paper connection diagrams for the PaperGraph section. Back in the spotlight nowadays since I'm brushing up the literature review...

The packaging is straightforward. Among the Build Systems for Guix one can find asdf-build-system for packing lisp systems with ASDF. As the manual suggests, providing executables is also possible through 'build-program argument, for example one can take stumpwm Guix package definition.

Particularly, under the #entry-program keyword I provide instructions located previously in app/build.lisp. One thing I noticed to keep in mind: by default, the forms of an #entry-program are compiled as a separate <package>-exec lisp package. So in my example they will fall into :papergraph-exec, not :papergraph. Maybe there is a work around such behavior, idk. Here I kept the defaults which means I had to edit a bit the utility config (to account for interning state variables in the right place).

Below is the entire literate package definition for the papergraph, well preserved and evergreen.

  (define-module (my-utils-papergraph)
    #:use-module (guix licenses)
    #:use-module (guix packages)
    #:use-module (guix utils)
    #:use-module (guix git-download)
    #:use-module (guix build-system asdf)
    #:use-module (gnu packages lisp-xyz)
    #:use-module (gnu packages graphviz)
    #:use-module (guix download))


  (define-public papergraph
    (let ((commit "24164264f9e1d2021dec63c6fe051f6e78bcdf67")
          (revision "1"))
      (package
        (name "papergraph")
        (version (git-version "0.1.5" revision commit))
        (source
         (origin
           (method git-fetch)
           (uri (git-reference
                 (url "https://github.com/vdikan/papergraph")
                 (commit commit)))
           (file-name (git-file-name name version))
           (sha256
            (base32 "15ih3rr9qbqciwj90avya3ml3npqhimkkfdmrfpphsyic6x0asj0"))))
        (build-system asdf-build-system/sbcl)
        (inputs
         `(("graphviz" ,graphviz)
           ("parser-combinators" ,sbcl-parser-combinators)
           ("alexandria" ,sbcl-alexandria)
           ("serapeum" ,sbcl-serapeum)
           ("dexador" ,sbcl-dexador)
           ("jonathan" ,sbcl-jonathan)
           ("arrows" ,sbcl-arrows)
           ("lparallel" ,sbcl-lparallel)
           ("bordeaux-threads" ,sbcl-bordeaux-threads)))
        (outputs '("out"))
        (arguments
         '(#:asd-systems '("papergraph")
           #:tests? #f
           #:phases
           (modify-phases
            %standard-phases
            (add-after
             'create-asdf-configuration 'build-program
             (lambda* (#:key outputs #:allow-other-keys)
               (build-program
                (string-append (assoc-ref outputs "out") "/bin/papergraph")
                outputs
                #:entry-program
                '(; Mind that this program form is by default
                  ; defind in :papergraph-exec package, not :papergraph
                  (defvar num-api-threads 8)
                  (defvar ref-files '("~/Refs/refs.bib"))
                  (defvar out-dir "/tmp/papergraph/")
                  (defvar out-file "papergraph.dot")
                  (defvar system-img-browser nil)
                  ; Load Paperggraph Config
                  (format t "Starting PaperGraph application...~%")
                  (load "papergraphrc")
                  (format t "Configuration file loaded~%")
                  ; Create threads that will request CrossRef on metadata
                  (setf lparallel:*kernel*
                        (lparallel:make-kernel num-api-threads :name "custom-kernel"))
                  ; Generate Graphis source
                  (uiop:with-current-directory (out-dir)
                   (let ((out-file-name (merge-pathnames out-file))
                         (out-svg-name (merge-pathnames
                                        (format nil "~a.~a" (pathname-name out-file) "svg"))))
                    (with-open-file (f out-file-name :direction :output :if-exists :supersede)
                                    (format f (papergraph:process-graph
                                               (papergraph:process-entries ref-files))))
                    (format t "PaperGraph: processing finished!~%")
                    ; Output image from GraphVis
                    (uiop:run-program (format nil "dot -Tsvg -o ~a ~a" out-svg-name out-file-name))
                    (format t "PaperGraph: image produced.~%")
                    ; Optionally, view the image
                    (when system-img-browser
                      (progn
                       (format t "PaperGraph: starting preview...~%")
                       (uiop:run-program (format nil "~a ~a" system-img-browser out-svg-name))))))
                  ; Shutdown
                  (lparallel:end-kernel :wait t)
                  (format t "PaperGraph: done.~%")
                  0)))))))
       (home-page "https://github.com/vdikan/papergraph")
       (synopsis "Bibtex -> Graphviz-Dot converter.")
       (description "Bibtex -> Graphviz-Dot converter. Using CrossRef to grab references.")
       (license gpl3+))))

Social Timeline: