Crafting happiness with Free Software & Hardware

How to package software for Guix (4)

Logo Guix

This serie of blog posts is an invitation to see how one can learn how to package software for Guix without prior knowledge about Guix or even software packaging. I show you what resources I need and how I use them. My method is driven by doing. The commands execution rhythms my iterations and its return guides the code to produce and the use of external resources (documentation, source code, community).

At the end of this serie, I would have packaged a simple piece of free software : ac-geiser, an extension of Emacs that brings a hint of self-completion to Geiser when I hack with the Guile language.

History :

In the Guix repository you've cloned in the first article of this serie, do the following :

$ git pull
$ guix environment --pure guix
[dev]$ ./bootstrap && ./configure --localstatedir=/var && make
$ exit

You now have an up-to-date stuff.

I retrieve the last commands executed (the first one to create a package definition, the second to build the package according to the definition):

$ echo '(use-modules (guix packages) (guix build-system emacs) (guix licenses)) (package (name "") (version "") (source origin) (build-system emacs-build-system) (synopsis "") (description "") (license bsd-3) (home-page ""))' > /tmp/dummy-package-definition.scm
$ ./pre-inst-env guix build -f /tmp/dummy-package-definition.scm
guix build: error: origin: source expression failed to match any pattern

Guix tells the following portion of the definition is problematic (source origin). I look at what the documentation explains about it... Effectively, origin is an object and not a symbol (as I specified it). I modify the definition to match with it :

$ echo '(use-modules (guix packages) (guix build-system emacs) (guix licenses)) (package (name "") (version "") (source (origin)) (build-system emacs-build-system) (synopsis "") (description "") (license bsd-3) (home-page ""))' > /tmp/dummy-package-definition.scm
$ ./pre-inst-env guix build -f /tmp/dummy-package-definition.scm
/tmp/dummy-package-definition.scm:1:112: error: (origin): missing field initializers (uri method sha256)

Guix tells me that the origin object consists of, at least, three required fields: (uri method sha256). I'm going to pass them to origin and see what Guix tells me :

$ echo '(use-modules (guix packages) (guix build-system emacs) (guix licenses)) (package (name "") (version "") (source (origin uri method sha256)) (build-system emacs-build-system) (synopsis "") (description "") (license bsd-3) (home-page ""))' > /tmp/dummy-package-definition.scm
$ ./pre-inst-env guix build -f /tmp/dummy-package-definition.scm
/tmp/dummy-package-definition.scm:1:112: error: uri: invalid field specifier

uri is not specified. I can see in the documentation this field is a string. Let's try this :

$ echo '(use-modules (guix packages) (guix build-system emacs) (guix licenses)) (package (name "") (version "") (source (origin (uri "") method sha256)) (build-system emacs-build-system) (synopsis "") (description "") (license bsd-3) (home-page ""))' > /tmp/dummy-package-definition.scm
$ ./pre-inst-env guix build -f /tmp/dummy-package-definition.scm
/tmp/dummy-package-definition.scm:1:112: error: method: invalid field specifier

Bingo, now I can move on to the second field: method. The documetation tells me that this is a procedure that will retrieve the sources of the software either from a URL or from a git repository. In my case, it will be a git repository. What the documentation also tells me is that for a git repository, uri must be a git-reference object and not a string as I specified in the previous step. I'll take it back before moving on to method.

$ echo '(use-modules (guix packages) (guix build-system emacs) (guix licenses)) (package (name "") (version "") (source (origin (uri (git-reference (url "") (commit ""))) method sha256)) (build-system emacs-build-system) (synopsis "") (description "") (license bsd-3) (home-page ""))' > /tmp/dummy-package-definition.scm
$ ./pre-inst-env guix build -f /tmp/dummy-package-definition.scm
/tmp/dummy-package-definition.scm:1:112: error: method: invalid field specifier

The construction of my uri field seems to suit Guix. Now, I will take care of the method field. The documentation tells me that method, in order to get the source of a program via git must be set to git-fetch from (guix git-download) module :

$ echo '(use-modules (guix packages) (guix build-system emacs) (guix licenses) (guix git-download)) (package (name "") (version "") (source (origin (uri (git-reference (url "") (commit ""))) (method git-fetch) sha256)) (build-system emacs-build-system) (synopsis "") (description "") (license bsd-3) (home-page ""))' > /tmp/dummy-package-definition.scm
$ ./pre-inst-env guix build -f /tmp/dummy-package-definition.scm
/tmp/dummy-package-definition.scm:1:112: error: sha256: invalid field specifier

Cool, the method field specification is OK for Guix.

But I'll stop here for today. I'll look into it in a future article. Here is the definition at this point:

(use-modules
 (guix packages)
 (guix build-system emacs)
 (guix licenses)
 (guix git-download))

(package
 (name "")
 (version "")
 (source
  (origin
   (uri (git-reference (url "") (commit "")))
   (method git-fetch) sha256))
 (build-system emacs-build-system)
 (synopsis "")
 (description "")
 (license bsd-3)
 (home-page ""))

Thank you so much for reading this article !

Don't hesitate to give me your opinion, leave a comment, or ask a question via :
E-mail: jeremy AT korwin-zmijowski DOT fr
Mastodon: @jeko@framapiaf.org
Peertube: @jeko@video.tedomum.net
Twitter: @JeremyKorwin

Also, please subscribe so you don't miss the next ones :
blog via Mastodon @jeko@write.as et RSS
screencast via Peertube @jeko@video.tedomum.net et RSS

And most importantly, share the blog and tell your friends it's the best blog in the history of Free Software! No shit!

#guix #package #english