Skip to content

Commit

Permalink
Add support for creating GNU/Hurd images.
Browse files Browse the repository at this point in the history
* parameters.list (hurd): New parameter.
* create (main): When building a Hurd image, use 'guix system image'
and qemu-img instead of 'guix system init' & co.
* configure.ac: Check for 'qemu-img'.
* guix.scm (ganeti-instance-guix)[inputs]: Add QEMU-MINIMAL.
* common.sh.in (QEMU_IMG): New variable.
* Makefile.am (do_subst): Substitute it.
(dist_example_DATA): Install example Hurd config.
* examples/hurd.scm: New file.
  • Loading branch information
mbakke committed Sep 14, 2023
1 parent 0683e23 commit 0679e69
Show file tree
Hide file tree
Showing 7 changed files with 132 additions and 23 deletions.
4 changes: 3 additions & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ exampledir = $(docdir)/examples
dist_example_DATA = \
examples/config-base.scm \
examples/dynamic.scm \
examples/generic.scm
examples/generic.scm \
examples/hurd.scm

EXTRA_DIST = \
$(TESTS) \
Expand All @@ -34,6 +35,7 @@ do_subst = $(SED) \
-e 's,[@]GUIX[@],$(GUIX),g' \
-e 's,[@]GCROOTSDIR[@],$(GCROOTSDIR),g' \
-e 's,[@]VARIANTSDIR[@],$(VARIANTSDIR),g' \
-e 's,[@]QEMU_IMG[@],$(QEMU_IMG),g' \
-e 's,[@]MOUNT[@],$(MOUNT),g' \
-e 's,[@]UMOUNT[@],$(UMOUNT),g' \
-e 's,[@]FALLOCATE[@],$(FALLOCATE),g' \
Expand Down
1 change: 1 addition & 0 deletions common.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ trap cleanup EXIT
GUIX=@GUIX@

# external programs
QEMU_IMG=@QEMU_IMG@
CRYPTSETUP=@CRYPTSETUP@
MOUNT=@MOUNT@
UMOUNT=@UMOUNT@
Expand Down
3 changes: 3 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ fi

# Optional dependencies. They still work if found on PATH at runtime.

AC_ARG_VAR(QEMU_IMG, [qemu-img path])
AC_PATH_PROG(QEMU_IMG, [qemu-img], qemu-img)

AC_ARG_VAR(BTRFS, [btrfs path])
AC_PATH_PROG(BTRFS, [btrfs], btrfs)
AC_PATH_PROG(MKFS_BTRFS, [mkfs.btrfs], mkfs.btrfs)
Expand Down
17 changes: 17 additions & 0 deletions create
Original file line number Diff line number Diff line change
Expand Up @@ -283,9 +283,11 @@ main(){
log Running with options set to:
log INSTANCE_NAME: "${INSTANCE_NAME}"
log TARGET_DEVICE: "${TARGET_DEVICE}"
log DISK_0_SIZE: "${DISK_0_SIZE}"
log OSP_FILESYSTEM: "${OSP_FILESYSTEM:-ext4}"
log OSP_LAYOUT: "${OSP_LAYOUT:-basic}"
log VARIANT_CONFIG: "${VARIANT_CONFIG}"
log OSP_HURD: "${OSP_HURD}"

# Make Guix use the specified CACHE_DIR to store Guile and Git caches.
if [[ -n "$CACHE_DIR" ]] && [[ ! -d "$CACHE_DIR" ]]; then
Expand Down Expand Up @@ -314,6 +316,21 @@ main(){
# Say 'cheeese'.
$GUIX_COMMAND --version

if [[ "${OSP_HURD}" = "true" ]]; then
log "Creating GNU/Hurd image..."
# Reserve 50 MiB to ensure the image does not exceed Ganeti size.
IMAGE_SIZE=$((DISK_0_SIZE - 50))
DISK_IMAGE=$($GUIX_COMMAND image -t hurd-qcow2 --image-size=${IMAGE_SIZE}M "${VARIANT_CONFIG}")
if [[ -b "${TARGET_DEVICE}" ]]; then
$QEMU_IMG dd bs=4M -O raw if="$DISK_IMAGE" of="$TARGET_DEVICE"
else
$QEMU_IMG convert -O raw "$DISK_IMAGE" "$TARGET_DEVICE"
fi

# Nothing left to do.
return
fi

# A basic 2 partitions setup.
partition_disk "$TARGET_DEVICE" "$PART_SIZE"
log DONE PARTITIONING.
Expand Down
84 changes: 84 additions & 0 deletions examples/hurd.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
(use-modules (gnu)
(gnu bootloader grub)
(gnu packages ssh)
(gnu services base)
(gnu services ssh)
(gnu system hurd)
(ice-9 match))

(define %cache.gexp.no-key
(plain-file "cache.gexp.no.pub" "
(public-key
(ecc
(curve Ed25519)
(q #07F59B9831390BCC3FB6CA33A4E1AC21197EA3122456751BCF53D62BD80E3366#)))
"))

(define %ssh-authorized-key
(plain-file "admin.pub"
"ssh-ed25519 \
AAAAC3NzaC1lZDI1NTE5AAAAIFoN0V4dObmbaLBUvHDs4OKPpSSJBrtOW3aNdoJn2hfD"))

(define %cool-stuff
'("curl"
;; "emacs-minimal"
"gdb"
"git-minimal"
"nss-certs"
"openssh-sans-x"
"parted"
"python"
"wget"))

(define %hurd-vm-operating-system
(operating-system
(inherit %hurd-default-operating-system)
;;(kernel-arguments '("console=com0"))
(host-name "cloudhurd")
(timezone "Europe/Amsterdam")
(bootloader (bootloader-configuration
(bootloader grub-minimal-bootloader)
(targets '("/dev/vda"))
(timeout 0)))
(packages (append (map specification->package %cool-stuff)
(operating-system-packages
%hurd-default-operating-system)))
(services
(append
(list (service openssh-service-type
(openssh-configuration
(openssh openssh-sans-x)
(permit-root-login #t)
(authorized-keys
`(("root" ,%ssh-authorized-key)))

This comment has been minimized.

Copy link
@methuselah-0

methuselah-0 Mar 24, 2024

Collaborator

I dont think anyone who tries out a default hurd config wants or expects this pub key to be allowed by default here since its hard coded above.

(allow-empty-passwords? #f)
(password-authentication? #t))))
(modify-services %base-services/hurd
(static-networking-service-type
config =>
(list %loopback-static-networking
(static-networking
(requirement '())
(name-servers '("9.9.9.9" "8.8.8.8"))
(addresses
(list (network-address
(device "eth0")
(value (string-append
(getenv "NIC_0_IP") "/"
(match (string-split
(getenv "NIC_0_NETWORK_SUBNET")
#\/)
((addr mask) mask)))))))
(routes
(list (network-route
(destination "default")
(gateway (getenv "NIC_0_NETWORK_GATEWAY"))))))))
(guix-service-type
config =>
(guix-configuration
(inherit config)
(authorized-keys (cons %cache.gexp.no-key %default-authorized-guix-keys))
(substitute-urls (cons "https://cache.gexp.no"
%default-substitute-urls)))))))))

%hurd-vm-operating-system
45 changes: 23 additions & 22 deletions guix.scm
Original file line number Diff line number Diff line change
Expand Up @@ -45,27 +45,28 @@

(define ganeti-instance-guix
(package
(name "ganeti-instance-guix")
(version version)
(source (local-file %source-dir
#:recursive? #t
#:select? (git-predicate %source-dir)))
(build-system gnu-build-system)
(native-inputs
(list autoconf automake
;; For tests.
jq))
(inputs
(list cryptsetup
e2fsprogs
lvm2
multipath-tools
parted
util-linux))
(home-page "https://github.com/mbakke/ganeti-instance-guix")
(synopsis "Create Guix instances on Ganeti")
(description
"@code{instance-guix} is a Ganeti OS definition that creates Guix instances.")
(license gpl3+)))
(name "ganeti-instance-guix")
(version version)
(source (local-file %source-dir
#:recursive? #t
#:select? (git-predicate %source-dir)))
(build-system gnu-build-system)
(native-inputs
(list autoconf automake
;; For tests.
jq))
(inputs
(list cryptsetup
e2fsprogs
lvm2
multipath-tools
parted
qemu-minimal ;for qemu-img
util-linux))
(home-page "https://github.com/mbakke/ganeti-instance-guix")
(synopsis "Create Guix instances on Ganeti")
(description
"@code{instance-guix} is a Ganeti OS definition that creates Guix instances.")
(license gpl3+)))

ganeti-instance-guix
1 change: 1 addition & 0 deletions parameters.list
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ layout A partitioning layout option, either basic or advanced. Defaults to basi
filesystem Defaults to ext4 if unset. Supported values are ext2, ext3, ext4, f2fs, xfs and btrfs.
luks_passphrase By setting a passphrase in this option, you enable full disk encryption.
part_size Maximum disk size to use when partitioning, in addition to 3MiB total for offset and empty bootloader partition. Defaults to using up all disk size.
hurd Whether to build a GNU/Hurd image.

0 comments on commit 0679e69

Please sign in to comment.