Introduction on hacking guix with emacs

Michael Rohleder

Created: 2020-05-14 Thu 13:35

1 Note

For a programmer (and maybe everyone) it is satisfying to hack and customize the environment he/she is working on. That's why emacs and guix (and a lot of other software) is so much fun! And even more, if all these pieces of wonderful art start to flow and work together.

On IRC I often see questions like "What is the best way to contribute patches" and also I saw that the guix package "emacs-org-re-reveal" might need a version bump, so it feels natural to combine these two and record the way I do this currently. Also, it is a nice way to test the new emacs-org-re-reveal version.

2 Requiremts and Setup

You need to have a guix enviroment and its sources, as described in the guix manual. From now on, I assume you are in git tree of guix.

For demonstration, we start a new isolated container environment with the tools we need: (for real work, you should already have that…)

guix environment -C -N -E TERM guix --expose=/var/guix=/var/guix \
--ad-hoc emacs-no-x emacs-magit git git:send-email emacs-yasnippet help2man pkg-config guile \
-- emacs --execute "(load-theme 'wombat)"

requirement.gif

2.1 set up yas-snippets

we want to use the git commit-hook snippets:

(setq yas-snippet-dirs (list (concat default-directory "etc/snippets")))
(yas-global-mode)

and "M-x eval-buffer"

yasnippet.gif

3 git working branch

for every patch we want to make, we make a fresh new local branch ("local-work" in my case) that is "hard" reseted to master (or the branch we want patch) every time.

to do this in magit, we start magit with "M-x magit-status" and press "b b" and select our working branch. then, we reset that to master with "X h"

git-branch.gif

4 hacking

ok, now it's time to edit files. we type "C-x C-f gnu/packages/emacs-xyz.scm" to open "emacs-xyz.scm".

In the file, we know we want to bump "emacs-org-re-reveal" so we search for that with "C-s".

Because we read a lot of documentation (to make this presentation), we know that the latest version tag is 2.12.2, so we change that version and save the file with "C-x s".

hacking.gif

4.1 compiling

because we are in a new environment, we need to reconfigure and -compile the guix tree, so we start a shell with "M-x shell" and type:

./configure --localstatedir=/var && make -j12

(change to -jX to the number of cpu's you have).

compiling.gif

let's try to compile our hack:

./pre-inst-env guix build emacs-org-re-reveal

hack-compile.gif

as expected, this fails, because we changed the version number, but not the hash. so, let's fix that with the help of "M-@" which marks a word and compile again.

fix-hash.gif

ok, looks better now. let's check if the package is reproducable and deterministic:

./pre-inst-env guix build emacs-org-re-reveal --rounds=3 --check --no-grafts

5 git commit

we want to commit our changes to our branch, so we type "s" and than "c c" in magit to stage and then commit.

now we get an error from git, because we are in a container, so we have to setup git as magit suggests:

git config --global user.email "[email protected]"
git config --global user.name "Michael Rohleder"

commit1.gif

we should be able to commit now with typing "c c" in magit. then we insert this pretty guix snippet with "M-x yas-insert-snippet" and select the snippet named "guix-commit-message-update-package". "C-c C-c" commits this.

commit2.gif

6 send patch

for actually sending the patch, we need to have working email delivery, which is beyond the scope of these slides, so I only show the principle.

the most straight forward way is to use "git send-email" with something like

git send-email -1

which would ask some questions and send the last commit.

I personally use the package "emacs-gitpatch" in the following way: type "W" in magit to format patches and then "c c" to create a patch file. then, I put the cursor on this file and type "M-x gitpatch-mail".

this starts an email buffer where the patch file is included, and you can edit the email as normal…

send-patch.gif