Guix Packager's Guide

This is a guide/cheatsheet for writing Guix packages.

Example package definitions file

(define-module (my-packages)
  #:use-module (ice-9 fdes-finalizers)
  #:use-module (guix utils)
  #:use-module (guix packages)
  #:use-module (guix download)
  #:use-module (guix git-download)
  #:use-module ((guix licenses) #:prefix license:)
  #:use-module (guix build-system meson)
  #:use-module (guix licenses)
  #:use-module (guix packages)
  #:use-module (gnu packages)
  #:use-module (gnu packages audio)
  #:use-module (gnu packages music))

(define-public zlfo
  (package
    (name "zlfo")
    (version "0.1.3")
    (source
     (origin
       (method git-fetch)
       (uri (git-reference
             (url "https://git.zrythm.org/git/ZLFO")
             (commit (string-append "v" version))))
       (file-name (git-file-name name version))
       (sha256
        (base32
         "0bm466ci5xyvxvq7l9p6xyh789lvk6i31b4zja1igqh13akbjnjz"))))
    (build-system meson-build-system)
    (inputs
     `(("librsvg" ,librsvg)
       ("lv2" ,lv2)
       ("ztoolkit-rsvg" ,ztoolkit-rsvg)))
    (native-inputs
     `(("pkg-config" ,pkg-config)))
    (synopsis "Low frequency oscillator plugin")
    (description "ZLFO is a fully featured
@dfn{low frequency oscillator} (LFO) for @dfn{control voltage} (CV)-based
automation that comes as an LV2 plugin bundle with a custom UI.")
    (home-page "https://git.zrythm.org/cgit/ZLFO/")
    (license license:agpl3+)))

;; more packages here

The rest of this guide assumes this file is saved as my-packages.scm under the current dir.

Build a package from definition

guix build -L . -K zlfo
  • -L specifies the directory where the package definitions are
  • -K tells guix to keep the temporary build dir if the build fails

Force-rebuild a package

guix build --check --no-grafts zlfo

Deprecate a package

(define-public zlfo
  ;; The "zlfo" package is now included in zplugins
  (deprecated-package "zlfo" zplugins))

Use source as input

(inputs
 `(("juce"
    ,(let ((commit "c51d03f11be20cb35eb28e8016e9a81827b50339"))
       (origin
         (method git-fetch)
         (uri (git-reference
                (url "https://github.com/lv2-porting-project/JUCE")
                (commit commit)))
         (sha256
           (base32 "1mkjbixvp7q1fyz9s7qn152iv6c03gfwjbx32dymcx2jayjlakp4"))
         (file-name "juce-src"))))))

Delete a phase

(arguments
 `(#:tests? #f  ; no "check" target
   #:phases
   (modify-phases %standard-phases
     (delete 'configure))))

Change Make flags

(arguments
 `(#:make-flags
   (list "--directory=extras/Projucer/Builds/LinuxMakefile" "CONFIG=Release")))

Copy a file during install

(arguments
 `(#:phases
   (modify-phases %standard-phases
     (replace 'install
       (lambda* (#:key outputs #:allow-other-keys)
         (let* ((out (assoc-ref outputs "out"))
                (bin (string-append out "/bin")))
           (mkdir-p bin)
           (copy-file "extras/Projucer/Builds/LinuxMakefile/build/Projucer"
                      (string-append bin "/Projucer"))))))))

Various procedures

;; setting an env variable
(setenv "GDK_BACKEND" "x11")

;; invoking a command
(invoke "patch" "-N" "Builds/LinuxMakefile/Makefile"
        makefile-patch)

Tips

  1. Libraries should list their pkgconfig dependencies as propagated-inputs (see librsvg for example)
By Alexandros Theodotou in
Tags : #packaging,