5 Reasons to Try GNU Guix in 2022

What is GNU Guix?

Guix is a package manager and system configuration tool which enables you to safely and repeatably install software and an entire GNU/Linux environment on your computer.

To be more specific, it is a functional package manager (inspired by Nix) which can make transactional changes to your system configuration. This “functional” model ensures that any configuration you apply will always have the same result when given a particular set of inputs. Also, every change can be rolled back to a previous configuration if something goes wrong.

One interesting aspect of GNU Guix for the Lisp enthusiasts out there is that the entire tool is written and configured with Guile Scheme, so you can almost think of this as the Emacs of Linux distributions.

Read more about this model in the Guix Manual!

If you find this guide helpful, please consider supporting System Crafters via the links on the How to Help page!

Follow along!

In this video I’ll demonstrate a few Guix features using a virtual machine. If you’d like to follow along, you can find instructions on how to set up a standard Guix VM image in the Guix manual.

If you want to get started quickly on a Linux system with QEMU installed, you might be able to run these commands:

wget -O ~/Downloads/guix-vm.qcow2 https://ftp.gnu.org/gnu/guix/guix-system-vm-image-1.3.0.x86_64-linux.qcow2 --show-progress

qemu-system-x86_64 \
  -nic user,model=virtio-net-pci \
  -enable-kvm -m 2048 \
  -device virtio-blk,drive=guix-demo \
  -drive if=none,file=$HOME/Downloads/guix-vm.qcow2,id=guix-demo

1. You’ll never lose your configuration again

In other GNU/Linux distributions, you install your system and then manually make changes to the configuration:

  • Installing packages
  • Adding user accounts
  • Tweaking configuration files
  • Configuring system services
  • Setting up your user configuration (dotfiles)

GNU Guix allows you to describe your entire system configuration using a declarative syntax. This enables you to manage your whole configuration using a single file and then check it into source control so that you never lose it!

Typically the process is to start with a configuration file generated from Guix’ “graphical installer” or one you’ve found online, install it on your system, and then tweak it to your liking.

Whether you want to install or update your system, it’s the same command:

sudo guix system reconfigure config.scm

You can always find the current system configuration at /run/current-system/configuration.scm but I recommend keeping your own copy of your system configuration file that you check into source control.

Let’s add a new user to the system configuration:

;; ... starts at line 62 ...

(users (cons* (user-account
               (name "guest")
               (comment "GNU Guix Live")
               (password "")            ;no password
               (group "users")
               (supplementary-groups '("wheel" "netdev"
                                       "audio" "video")))
              (user-account
               (name "david")
               (comment "GNU Guix Live")
               (password "")            ;no password
               (group "users")
               (supplementary-groups '("wheel" "netdev"
                                       "audio" "video")))

              %base-user-accounts)

Now we can verify that the change gets applied by running sudo guix system reconfigure config.scm and checking /etc/passwd:

cat /etc/passwd | grep david  # No result!
sudo guix system reconfigure config.scm
cat /etc/passwd | grep david  # The account is now there!

Guix enables you to truly craft a system configuration that will last, even if you have to reinstall your system or move the configuration to a different computer.

You can even share the same base configuration between multiple machines with custom tweaks for each!

2. Changing your configuration is safe

If you’ve used distributions like Arch, Gentoo, or even Ubuntu, you’ve probably experienced a system-breaking upgrade at some point.

With Guix, no matter whether you’re tweaking some part of your configuration or installing new versions of packages, you can always roll back to the previous state!

And if you make a change that makes your system unbootable, you can always find the previous configuration in the Grub bootloader menu!

Let’s try to roll back the user addition we added before:

sudo guix system roll-back

Now the configuration update we just applied has been rolled back!

We can check for the user we added just like last time:

cat /etc/passwd | grep david  # The user is gone!

3. You can also use it for managing your dotfiles

Last year, an important new feature called guix home was added which enables you to apply the same declarative configuration style (including rollbacks) to your user-level configuration.

This makes it possible to ensure all your favorite programs are installed and configured exactly how you want no matter which machine you use them on. You can even configure user-level services with it!

Let’s try it out! This configuration will install Emacs and Syncthing, configure the Bash profile, and then set up Syncthing as a user-level Shepherd service.

Run the following commands to apply the configuration to the guest account’s home directory:

wget https://0x0.st/ozVe.scm -O home.scm
guix home reconfigure home.scm

To verify the home configuration:

emacs -v
cat ~/.bash_profile
herd status syncthing

NOTE: This feature is newer than the Guix 1.3.0 release that the demo VM is based on! You will need to run the following commands before trying it:

guix pull
hash guix

This might take a while, so be patient!

Example Home Configuration

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

(define my-syncthing-service
  (shepherd-service
   (provision '(syncthing))
   (documentation "Run and control syncthing.")
   (start #~(make-forkexec-constructor
             (list #$(file-append syncthing "/bin/syncthing")
                   "-no-browser")))
   (stop #~(make-kill-destructor))))

(home-environment
 (packages (list emacs syncthing))
 (services
  (list
   (service home-bash-service-type
            (home-bash-configuration
             (environment-variables
              '(("VISUAL" . "emacsclient")
                ("EDITOR" . "emacsclient")))))
   (simple-service 'my-services
                   home-shepherd-service-type
                   (list my-syncthing-service)))))

More information: Home Configuration

4. You can easily create isolated development environments

If you’re a software developer, you’ve probably had to work a variety of different projects, all with their own platforms and tools and different versions of the same libraries. This can quickly become a nightmare if you have to install all these things directly into your system!

Guix provides a command called guix shell that can easily create an on-demand, isolated shell environment to work on your projects! If you create a Guix manifest file (manifest.scm or guix.scm) in your project folder, you can run the following command to create such an environment:

guix shell --pure

It will let you know if you need to mark the project as safe for creating an environment, so run the command that it suggests!

Let’s use guix shell to set up a development environment for the project I’m building on my other channel Flux Harmonic:

git clone https://github.com/FluxHarmonic/flux-compose
cd flux-compose

# Try to run CMake, it's not there!
cmake

# Set up the development environment using manifest.scm
guix shell --pure

# Try to build the code
./bootstrap.sh
cmake  # It works!
make -C build

# Exit the environment to see if commands are still there
exit
cmake
make

NOTE: This feature is also newer than the Guix 1.3.0 release that the demo VM is based on! You will need to run the two commands mentioned in the guix home slide (reason #3).

5. You can get many of these benefits on your current Linux distribution

You don’t need to install the full Guix System to benefit from Guix! You can install the Guix package manager on many other Linux distributions, either from the distro package manager or by using the installation script provided by the Guix maintainers.

This enables you to use Guix to install software, manage your dotfiles with guix home, create isolated development environments with guix shell, and even create installation media for Guix System while still using your existing Linux distribution.

Check out my video about this for more details!

How to get started

More videos coming soon!

This year I’ll be making a lot more videos about GNU Guix to help with day to day usage and also going deeper into how you can write your own customizations and package definitions:

  • A crash course on Guile Scheme
  • “I installed Guix, now what?”
  • Writing and updating Guix package definitions
  • Configuring system services
  • Managing your user-level configuration with guix home
  • Developing server configurations and managing remotely

I want to hear from you!

Now I want to hear from all of you, especially those who are finding this channel for the first time.

Leave a comment with an answer to one of these questions:

  • What has kept you from using Guix before?
  • If you’ve tried Guix, what problems did you have?
  • What’s the worst you’ve ever broken your Linux install with another distro?

Don’t forget to subscribe and click the bell to be notified when new Guix videos are released!

Subscribe to the System Crafters Newsletter!
Stay up to date with the latest System Crafters news and updates! Read the Newsletter page for more information.
Name (optional)
Email Address