DEV Community

Red Nose Hacker
Red Nose Hacker

Posted on

First steps toward Guix Home

Guix logo

In this article, I will show you, step by step, how one can simply install and configure software they use with Guix Home. For the demonstration, I will focus on a single package and a single service.

Disclaimer: I'm not an experienced Guix Home user. So don't take my words for granted. Read manuals, ask questions.

So far, to install a software, say Emacs, for my user, I could simply :
$ guix install emacs
Or, I could write a manifest and use it to populate my default user profile (or a custom one) :
$ guix package --manifest=$HOME/manifest.scm
Where manifest.scm contains the following :

(specifications->manifest (list "emacs"))
Enter fullscreen mode Exit fullscreen mode

Then, the configuration for the new software had to be edited separately.
Here is a dummy ~/.config/emacs/init.el :

(setq initial-scratch-message nil)
Enter fullscreen mode Exit fullscreen mode

Now, let's use Guix Home to start managing the whole !

The blank home

Guix Home ask you for two things : a list of packages and a list of home services.
So a blank Guix Home configuration file (which installs and configures nothing) would look like this :

(use-modules (gnu home))

(home-environment
 (packages (list))
 (services (list)))
Enter fullscreen mode Exit fullscreen mode

You can save this expressions in a file named home-configuration.scm. So you now can invoke Guix Home to generate a home environment from this blank configuration :

$ guix home container home-configuration.scm
Enter fullscreen mode Exit fullscreen mode

No worries, this won't affect your current environment.
Take a few seconds to see how empty this shell is and move on !

Oops, you need to leave the empty shell.

$ exit
Enter fullscreen mode Exit fullscreen mode

Installing the software

To tell Guix Home to add a software package to the generated home environment, you have to edit home-configuration.scm and add its name to the package list :

(use-modules
 (gnu home)
 (gnu packages emacs))

(home-environment
 (packages
  (list emacs)))
Enter fullscreen mode Exit fullscreen mode

You can now try it out.

$ guix home container home-configuration.scm
Enter fullscreen mode Exit fullscreen mode

In this shell, you can run Emacs, proof that Emacs has been added to the generated home environment.

$ emacs -nw
Enter fullscreen mode Exit fullscreen mode

Then you can quit the shell.

Install the software's configuration

From Guix Home perspective, things are packages or services. It's time to look for services. Especially one that can handle the process to configure Emacs. Simply put, a service capable of installing the init.el file on the right place : home-xdg-configuration-files-service-type.

Edit home-configuration.scm to be like :

(use-modules
 (gnu home)
 (gnu home services)
 (gnu packages emacs)
 (gnu services)
 (guix gexp))

(home-environment
 (packages
  (list emacs))
 (services
  (list (service home-xdg-configuration-files-service-type
         `(("emacs/init.el" ,(local-file "init.el")))))))
Enter fullscreen mode Exit fullscreen mode

Then, create a init.el file, with your Emacs configuration, next to the home-configuration.scm :

(setq initial-scratch-message nil)
Enter fullscreen mode Exit fullscreen mode

Try it with :

$ guix home container home-configuration.scm
Enter fullscreen mode Exit fullscreen mode

Here you can see there is the init.el file at ~/.config/emacs/init.el !
So the Emacs in this environment will use this configuration file at startup… Ok, maybe not in the container, but trust me, it will when running (careful, it will have an effect to your current environment this time) :

$ guix home reconfigure home-configuration.scm
Enter fullscreen mode Exit fullscreen mode

Warning : because there is no shell configuration in the home-configuration.scm (yet), you will need to manually configure your shell to make it benefits from the generated home environment.

Thank you very much for reading this article!

Don't hesitate to give me your opinion, suggest an idea for improvement, report an error, or ask a question ! I would be so glad to discuss about the topic covered here with you ! You can reach me here.

Don't miss out on the next ones ! Either via RSS or via e-mail !

And more importantly, share this blog and tell your friends why they should read this post!

Top comments (2)