Hosting Services with Guix Containers

Updates

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:

https://git.genenetwork.org/guix-bioinformatics/tree/gn/services/bnw-container.scm

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)

(operating-system
  (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 '())

  (users
   (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/systemcrafters.net" ,(local-file "website"
                                                                          "site-files"
                                                                          #:recursive? #t))))

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

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

                  (service syslog-service-type)

                  (service prosody-service-type
                           (prosody-configuration
                            (modules-enabled (cons* "groups" "mam" %default-modules-enabled))
                            (int-components
                             (list
                              (int-component-configuration
                               (hostname "muc.localhost")
                               (plugin "muc")
                               (mod-muc (mod-muc-configuration)))))
                            (virtualhosts
                             (list
                              (virtualhost-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