~tieong/guix-images

71321f63db1caa8cc276ac6813a563a3bf4136e1 — Thomas Ieong 11 months ago 5ba430f master
Added more arguments such as the ssh key and user and the image size
1 files changed, 22 insertions(+), 9 deletions(-)

M make-vm.scm
M make-vm.scm => make-vm.scm +22 -9
@@ 34,11 34,11 @@

(define* (base-users #:optional extra-users)
  `(cons* (user-account
	   (name "user")
	   (comment "user")
	   (name "guix")
	   (comment "guix")
	   (group "users")
	   (supplementary-groups '("wheel"))
	   (home-directory "/home/user"))
	   (home-directory "/home/guix"))
	  ,@(if extra-users extra-users '())
	  %base-user-accounts))



@@ 56,16 56,20 @@ root ALL=(ALL) ALL
%wheel ALL=(ALL) NOPASSWD: ALL
"))

(define* (base-services #:optional extra-services)
(define* (base-services #:key
			ssh-user
			ssh-pub
			(guest-agent? #t)
			(extra-services '()))
  `(append (list (service dhcp-client-service-type)
		 (service unattended-upgrade-service-type)
		 (service qemu-guest-agent-service-type)
		 ,@(if guest-agent? '((service qemu-guest-agent-service-type)) '())
		 (service openssh-service-type
			  (openssh-configuration
			   (openssh openssh-sans-x)
			   (permit-root-login #f)
			   (authorized-keys
			    `(("user" ,(plain-file "" ""))))))
			    `((,,ssh-user ,(plain-file "key.pub" ,ssh-pub))))))
		 ,@(if extra-services extra-services '()))
	   (modify-services %base-services
			    (sysctl-service-type config =>


@@ 125,6 129,8 @@ root ALL=(ALL) ALL
   (else obj)))

(define* (make-vm #:key
		  (image-type "qcow2")
		  (image-size "10737418240") ;; 10gb
		  (config-path #f)
		  (no-os #f)
		  (modules (base-modules))


@@ 160,14 166,21 @@ root ALL=(ALL) ALL
    (let* ((port (open-input-pipe (string-join `("guix"
						 "system"
						 "image"
						 "--image-type=qcow2"
						 ,(string-append  "--image-type=" image-type)
						 "--save-provenance"
						 "--image-size=10737418240" ;; 10gb
						 ,(string-append  "--image-size=" image-size)
						 "--"
						 ,(if no-os config-path tmp-file))
					       " ")))
	   (image-path (read-line port))
	   (output-img (string-append "output/" host-name ".qcow2")))
	   (output-img (string-append
			"output/"
			host-name
			(string-append "."
				       (if
					(string-ci=? "efi-raw" image-type)
					"img"
					image-type)))))
      (close-pipe port)
      (if (file-exists? "output") #f (mkdir "output"))
      (copy-file image-path output-img)