Crafting happiness with Free Software & Hardware

How to package software for Guix (5)

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

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) (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

I have no idea how to specify the sha256 field. So I request documentation on this subject. Unfortunately, I can't find much information on how to use sha256, or how to define a bytevector in base 32 format. So I looked at the hello package example in the documentation to unlock me (it's the wildcard of the session). I can now change my definition accordingly.

$ 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 (base32 "")))) (build-system emacs-build-system) (synopsis "") (description "") (license bsd-3) (home-page ""))' > /tmp/dummy-package-definition.scm
$ guix build -f /tmp/dummy-package-definition.scm
guix build: error: derivation `/gnu/store/diif4n2lx6s5g9qxrvpc9pshfyypwa6k-git-checkout.drv' has incorrect output `/gnu/store/7ygy97wz9d1zcbz3k2kg1ga9g389bd7b-git-checkout', should be `/gnu/store/0fd9p27axy1jdw7fv29fa8i3sa0vajbl-git-checkout'

This time, I don't use the pre-inst-env script as it seems to be broken for me (see my thread on the mailing list). Will see if I can fix it later...
Anyway, here the Guix return message tells me Guix made a step forward to the build process. But it is not very explicit about what is missing or wrong. In the mailing list thread previously mentionned, Julien Lepiller said I have to specifiy a non-empty hash for the package (the base32 field). So let's specify it !
First, compute the expected hash with the help of the documentation !

$ cd /tmp
$ git clone https://github.com/xiaohanyu/ac-geiser.git
Clonage dans 'ac-geiser'...
remote: Enumerating objects: 20, done.
remote: Total 20 (delta 0), reused 0 (delta 0), pack-reused 20
Dépaquetage des objets: 100% (20/20), 148.08 Kio | 746.00 Kio/s, fait.
$ cd ac-geiser/
$ guix hash -rx .
0h2kakb4f5hgzf5l2kpqngalcmc4402lkg1pvs88c8z4rqp2vfvz

Now it is time to complete the package definition. I take this opportunity to fill all the fields I can (I want to create the package for ac-geiser).

$ echo \
'(use-modules 
   (guix packages)
   (guix build-system emacs)
   (guix licenses) 
   (guix git-download)) 
 (package 
   (name "emacs-ac-geiser") 
   (version "0.1") 
   (source 
     (origin 
       (uri (git-reference 
              (url "https://github.com/xiaohanyu/ac-geiser.git") 
              (commit "502d18a8a0bd4b5fdd495a99299ba2a632c5cd9a"))) 
       (method git-fetch) 
       (sha256 (base32 "0h2kakb4f5hgzf5l2kpqngalcmc4402lkg1pvs88c8z4rqp2vfvz"))))
   (build-system emacs-build-system) 
   (synopsis "Auto-complete backend for geiser")
   (description "Provides one auto-complete source for Scheme projects using geiser.")
   (license bsd-3) 
   (home-page "https://github.com/xiaohanyu/ac-geiser"))'\
> /tmp/dummy-package-definition.scm
$ guix build -f /tmp/dummy-package-definition.scm
[...]

With this, guix build is finally working ! The traces on console are too long to be fully copied here (so I created a Gist).
It finishes with an error reported in a log :

[...]
Cannot open load file: No such file or directory, geiser
[...]

That make sense considering ac-geiser requires both geiser and auto-complete but I never specified it.
In the documentation I found there are fields dedicated to this purpose. One fit exactly : propagated-inputs. Both geiser and auto-complete have their own Guix package. The commandsguix show emacs-geiser and guix show emacs-auto-complete tell me their are defined in the file gnu/packages/emacs-xyz.scm.
So I edit my definition (not so dummy anymore) to bring them into it. I store it under /tmp/emacs-ac-geiser.scm :

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

(package
 (name "emacs-ac-geiser")
 (version "0.1")
 (source
  (origin
   (uri (git-reference
	 (url "https://github.com/xiaohanyu/ac-geiser.git")
	 (commit "502d18a8a0bd4b5fdd495a99299ba2a632c5cd9a")))
   (method git-fetch)
   (sha256 (base32 "0h2kakb4f5hgzf5l2kpqngalcmc4402lkg1pvs88c8z4rqp2vfvz"))))
 (build-system emacs-build-system)
 (propagated-inputs `(("geiser" ,emacs-geiser)
		      ("auto-complete" ,emacs-auto-complete)))
 (synopsis "Auto-complete backend for geiser")
 (description "Provides one auto-complete source for Scheme projects using geiser.")
 (license bsd-3)
 (home-page "https://github.com/xiaohanyu/ac-geiser"))

Et voilà !

$ guix build -f /tmp/emacs-ac-geiser.scm
[...]
construction de /gnu/store/2yz7ax3h5qwjg0i24kb65p5l8r8n5vh6-emacs-ac-geiser-0.1.drv réussie
/gnu/store/hp2jli29jchkdi50klzydrxqk72r3n2w-emacs-ac-geiser-0.1

Guix successfuly build the package according to my definition ! Yay \o/

It is a good place to stop. Next one will be for submitting the package to the Guix Project ! My first contribution ?!

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