;;; Stolen from https://g.tylerm.dev/tylerm/dotfiles/raw/branch/main/modules/home-packages/virtualization.scm

(define-module (ryan-packages virtualization)
               #:use-module (guix packages)
               #:use-module (guix utils)
               #:use-module (gnu packages)
               #:use-module (gnu packages package-management)
               #:use-module (gnu packages build-tools)
               #:use-module (gnu packages virtualization)
               #:use-module (gnu packages firmware)
               #:use-module (guix gexp))

(define-public libvirt-ovmf
  (package
    (inherit libvirt)
    (name "libvirt-ovmf")
    (inputs
      (modify-inputs (package-inputs libvirt)
                     (append qemu)))
    (arguments
      (substitute-keyword-arguments (package-arguments libvirt)
        ((#:phases phases)
         #~(modify-phases #$phases
            (add-after 'install 'install-firmware
                (lambda _
                    (let ((fmw (string-append #$output "/share/qemu")))
                        (mkdir-p fmw)
                        (copy-recursively #$(file-append qemu "/share/qemu") fmw))))))))))

(define-public virt-manager-ovmf
    (package
      (inherit virt-manager)
      (name "virt-manager-ovmf")
      (inputs
        (modify-inputs (package-inputs virt-manager)
                     (append qemu)))
      (arguments
        (substitute-keyword-arguments (package-arguments virt-manager)
         ((#:phases phases)
          #~(modify-phases #$phases
             (add-after 'install 'install-firmware
                 (lambda _
                   (let ((fmw (string-append #$output "/share/qemu")))
                     (mkdir-p fmw)
                     (copy-recursively #$(file-append qemu "/share/firmware") fmw))))))))))
