Hosting Services with Guix Containers


Making Guix Hosting Easier

One big challenge of using Guix to deploy servers to the cloud is that most cloud providers do not provide Guix images so you either have to upload your own or convert another distro to Guix!

Recently it occurred to me, though, that it might be possible to use Guix inside of a common “foreign” distro on a cloud provider. Both Debian and Alpine have Guix in their package repos, so we’ll experiment with one of these distros to see how feasible this idea will be!

There is prior art for hosting services in Guix containers. Pjotr Prins shared this configuration with me:

Let’s try to host a few things inside of a Guix container (or containers?)

  • Basic website with Nginx
  • XMPP server with Prosody
  • IRC bouncer with ZNC?
  • SSH server?

The final config

(use-modules (gnu)
             (guix gexp))

(use-package-modules bash messaging)
(use-service-modules messaging networking ssh web)

  (host-name "crafter-host")
  (timezone "Etc/UTC")
  (locale "en_US.utf8")

  (bootloader (bootloader-configuration
               (bootloader grub-bootloader)
               (targets '("does-not-matter"))))

  (file-systems %base-file-systems)

  ;; No firmware for containers.
  (firmware '())

   (list (user-account
          (name "crafter")
          (group "users")
          (password (crypt "InitialPassword!" "crafter")))))

  ;; We don't need any packages inside the container.
  (packages (list coreutils bash prosody))

  ;; Basic services
  (services (list (service dhcp-client-service-type)

                  ;; Copy our web server files into the container
                  (service special-files-service-type
                           `(("/srv/http/" ,(local-file "website"
                                                                          #:recursive? #t))))

                  (service nginx-service-type
                             (list (nginx-server-configuration
                                    (listen '("*:8000"))
                                    (server-name '(""))
                                    (root "/srv/http/"))))))

                  (service openssh-service-type
                            (port-number 2222)
                            (permit-root-login #t)))

                  (service syslog-service-type)

                  (service prosody-service-type
                            (modules-enabled (cons* "groups" "mam" %default-modules-enabled))
                               (hostname "muc.localhost")
                               (plugin "muc")
                               (mod-muc (mod-muc-configuration)))))
                               (domain "localhost")))))))))

I was running it with the following command:

sudo $(guix system container --network container-config.scm)

Guix Containers vs Docker Compose

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