Spice-up Guix setup

Mehrad Mahmoudian published on
2 min, 303 words

Abstract

Here are my suggestions on how to improve the experience with Guix. This post will get updated every now and then when I have something to add.

Shell Integration

One of the things that are quite useful for me is to know if I'm in a guix shell environment. I've added the following to my .bashrc and .zshrc to change my prompt from to ෧ ❯, and instead of my HOSTNAME I would get [env]. I chose this spiral character because it reminds me of some seashells. You can chose anything you like.

if [ -n "${GUIX_ENVIRONMENT}" ];then
    echo "\n---------------------[ you are inside a Guix Environment ]---------------------"
    # replace hostname with [env] using shell replacement.
    PS1="$(echo -En "${PS1/$HOST/[env]}")"
    # replace the prompt "❯" with "෧ ❯"
    PS1="$(echo -En "${PS1//෧ ❯}")"
    return
fi

Note that typically my shell prompt looks like this:

[mehrad@my-computer:~] [15:59:13]

and if I run for example guix shell r-minimal to get R language, I will get this:

[mehrad@my-computer:~] [16:00:51]
❯  guix shell r-minimal

---------------------[ you are inside a Guix Environment ]---------------------

[mehrad@[env]:~] [16:00:54]
෧ ❯

This way I always know this terminal is inside a Guix shell and will not get confused my some software is there or why I have a different version of a software.

Emacs Integration

Emacs and Guix are perfectly fitting each-other, and one could say that Guix is the Emacs of package managers. It is no surprise that both are Gnu projects, and many Guix users also use Emacs. There is an Emacs package called guix that is the Emacs interface to the Guix. I have added the following to my personal Emacs config:

(when (executable-find "guix")
  (use-package guix
    :ensure t
    :defer t
    :bind
    ("C-h g" . guix)))

This is super handy. For example to search for r-minimal, you can do equivalent of guix search 'r-minimal' with C-h g p n to search a package by name. When you press C-h g you already see a well transient menu, then because you want to deal with a package, you press p, and in the next menu you can see that pressing n does a "name search". The output is also colored and easy to read compared to the Guix CLI output.