Deploy Guix on DigitalOcean without cloud-init
Published by Arun Isaac on
In other languages: தமிழ்
A cloud-init service for Guix is still a work in progress. Meanwhile, here’s how you can deploy Guix on DigitalOcean right away.
Guix image to initialize the VPS
Start with a simple image configuration like this:
;; starter.scm (use-modules (gnu) (gnu image) (gnu system image)) (use-service-modules base networking ssh) (define %starter-os (operating-system (host-name "my-vps") (timezone "Europe/London") (bootloader (bootloader-configuration (bootloader grub-bootloader) (targets '("/dev/vda")) (terminal-outputs '(console)))) (file-systems (cons (file-system (mount-point "/") (device "/dev/vda1") (type "ext4")) %base-file-systems)) (services (cons* (service dhcpcd-service-type) (service openssh-service-type (openssh-configuration (permit-root-login 'prohibit-password) (authorized-keys `(("root" ,(local-file "/path/to/ssh/public/key")))))) (modify-services %base-services (guix-service-type config => (guix-configuration (inherit config) (authorized-keys (cons (local-file "/etc/guix/signing-key.pub") (guix-configuration-authorized-keys config)))))))))) (define GiB (* 1024 1024 1024)) (image (inherit mbr-disk-image) (name 'starter-image) (format 'compressed-qcow2) (operating-system %starter-os) (partitions (list (partition (inherit root-partition) (offset root-offset) (size (* 9 GiB))))) (volatile-root? #false))
In this example, we are targeting a very small DigitalOcean VPS with 10 GiB of disk. However, the exact size will be a little less than 10 GiB, and we don’t know exactly how much. So, we undersize to a safe 9 GiB. Later, we will grow the partition to cover the whole disk.
We also authorize the signing key of our local machine in the Guix of the image. This way, we can guix deploy
to the VPS later.
Build and upload image
Build the image using guix system image
.
guix system image starter.scm
Then, upload the image to DigitalOcean as a custom image, and boot off it. Now, you should be able to log in via SSH. If not, maybe try troubleshooting using the web-based droplet console.
The DigitalOcean custom image upload is quite temperamental. It often crashes with internal server errors. If it does, maybe build an image in the raw disk-image
format (instead of compressed-qcow2
), compress it with gzip
and upload; that worked for me.
Grow the partition
Once you are logged in, we grow the partition, resize the root filesystem, and we’re done!
guix shell cloud-utils -- growpart /dev/vda 1 resize2fs /dev/vda1
This is now just a regular Guix machine. You can update it via SSH using guix deploy
and the managed-host-environment-type
.
Take advantage of cheap and tiny VPSes!
Note that it doesn’t matter if your VPS has too little memory to actually build Guix packages. If you’re using guix deploy
, everything is built on your local machine (aka your laptop), and shipped off to the VPS. This way, you can benefit from Guix even on really cheap and tiny VPSes.
Remember that the VPS is only a deploy target. If you are building an image for your router, you don’t insist on building everything from source on your router, do you? It’s the same idea.