This commit is contained in:
Chad Nelson 2025-02-28 06:31:42 -07:00
parent 90cfb07fe5
commit 6f6ff44638

View file

@ -3,13 +3,13 @@
#:use-module (ice-9 rdelim) #:use-module (ice-9 rdelim)
#:use-module (ice-9 textual-ports) #:use-module (ice-9 textual-ports)
#:use-module (system foreign) #:use-module (system foreign)
;;#:use-module (msg helpers) #:use-module (msg helpers)
;;#:use-module (msg config) #:use-module (msg config)
#:export (machine)) #:export (machine))
(define home-path (getenv "HOME")) (define home-path (getenv "HOME"))
;;(define arch (run-shell-command "uname -m")) (define arch (run-shell-command "uname -m"))
(define cpu-conf #f) (define cpu-conf #f)
@ -31,14 +31,14 @@
(match args (match args
(("-h") (("-h")
(help)) (help))
;; (("init" rest ...) (("init" rest ...)
;; (init rest)) (init rest))
;; (("reinit") (("reinit")
;; (stop) (stop)
;; (clear-install) (clear-install)
;; (init)) (init))
;; (("start" rest ...) (("start" rest ...)
;; (start rest)) (start rest))
(("stop") (("stop")
(stop)) (stop))
(("rm") (("rm")
@ -69,134 +69,134 @@
(display "Please enter a valid response.\n") (display "Please enter a valid response.\n")
(loop))))) (loop)))))
;; (define* (start #:optional args) (define* (start #:optional args)
;; (define config (load-config)) (define config (load-config))
;; (if (not (directory-exists? (format #f "~a/.guix" home-path))) (if (not (directory-exists? (format #f "~a/.guix" home-path)))
;; (begin (begin
;; (display "MSG not initialized. Please run `msg machine init` to continue. If you already tried to install and are receiving this message, try running `msg machine reinit`") (display "MSG not initialized. Please run `msg machine init` to continue. If you already tried to install and are receiving this message, try running `msg machine reinit`")
;; (exit 0))) (exit 0)))
;; (cond (cond
;; ((string=? arch "arm64") ((string=? arch "arm64")
;; (system (format #f "/opt/homebrew/bin/qemu-system-aarch64 \ (system (format #f "/opt/homebrew/bin/qemu-system-aarch64 \
;; -machine virt,highmem=on \ -machine virt,highmem=on \
;; -accel hvf \ -accel hvf \
;; -cpu host \ -cpu host \
;; -smp ~a \ -smp ~a \
;; -display none \ -display none \
;; -hda $HOME/.guix/qemu/guix-user.qcow2 \ -hda $HOME/.guix/qemu/guix-user.qcow2 \
;; -m ~aG \ -m ~aG \
;; -virtfs local,path=/Users,security_model=mapped,mount_tag=macos \ -virtfs local,path=/Users,security_model=mapped,mount_tag=macos \
;; -bios /opt/homebrew/opt/qemu/share/qemu/edk2-aarch64-code.fd \ -bios /opt/homebrew/opt/qemu/share/qemu/edk2-aarch64-code.fd \
;; -device virtio-net,netdev=vmnic \ -device virtio-net,netdev=vmnic \
;; -netdev user,id=vmnic,hostfwd=tcp:127.0.0.1:9001-:22 &" cpu-conf mem-conf))) -netdev user,id=vmnic,hostfwd=tcp:127.0.0.1:9001-:22 &" cpu-conf mem-conf)))
;; ((string=? arch "x86_64") ((string=? arch "x86_64")
;; (system (format #f "/usr/local/bin/qemu-system-x86_64 \ (system (format #f "/usr/local/bin/qemu-system-x86_64 \
;; -machine type=q35,accel=hvf \ -machine type=q35,accel=hvf \
;; -smp ~a \ -smp ~a \
;; -hda $HOME/.guix/qemu/guix-user.qcow2 \ -hda $HOME/.guix/qemu/guix-user.qcow2 \
;; -m ~aG \ -m ~aG \
;; -display none \ -display none \
;; -cpu Nehalem \ -cpu Nehalem \
;; -virtfs local,path=/Users,security_model=mapped,mount_tag=macos \ -virtfs local,path=/Users,security_model=mapped,mount_tag=macos \
;; -device virtio-net,netdev=vmnic \ -device virtio-net,netdev=vmnic \
;; -netdev user,id=vmnic,hostfwd=tcp:127.0.0.1:9001-:22 &" cpu-conf mem-conf)))) -netdev user,id=vmnic,hostfwd=tcp:127.0.0.1:9001-:22 &" cpu-conf mem-conf))))
;; (display "MSG has been started") (display "MSG has been started")
;; ) )
(define* (stop) (define* (stop)
(system "ssh -o StrictHostKeyChecking=no -i $HOME/.guix/ssh-cert/msg_rsa admin@127.0.0.1 -p 9001 'sudo shutdown'")) (system "ssh -o StrictHostKeyChecking=no -i $HOME/.guix/ssh-cert/msg_rsa admin@127.0.0.1 -p 9001 'sudo shutdown'"))
;; (define* (init #:optional args) (define* (init #:optional args)
;; (if (not (directory-exists? (format #f "~a/.guix" home-path))) (if (not (directory-exists? (format #f "~a/.guix" home-path)))
;; (begin (begin
;; ;; Grab ssh cert for installer ;; Grab ssh cert for installer
;; (system "mkdir -p $HOME/.guix/qemu $HOME/.guix/home $HOME/.guix/ssh-cert") (system "mkdir -p $HOME/.guix/qemu $HOME/.guix/home $HOME/.guix/ssh-cert")
;; (system "ssh-keygen -R \"[127.0.0.1]:9001\"") (system "ssh-keygen -R \"[127.0.0.1]:9001\"")
;; ;; Download system image and and start vm ;; Download system image and and start vm
;; (cond (cond
;; ((string=? arch "arm64") ((string=? arch "arm64")
;; (system "/opt/homebrew/bin/wget https://objectstorage.us-phoenix-1.oraclecloud.com/n/axfgkze2xif1/b/guix-system/o/msg-system-aarch64guix-installer.qcow2.tar.gz -O $HOME/.guix/qemu/guix.qcow2.tar.gz") (system "/opt/homebrew/bin/wget https://objectstorage.us-phoenix-1.oraclecloud.com/n/axfgkze2xif1/b/guix-system/o/msg-system-aarch64guix-installer.qcow2.tar.gz -O $HOME/.guix/qemu/guix.qcow2.tar.gz")
;; (system "tar -xvzf $HOME/.guix/qemu/guix.qcow2.tar.gz -C $HOME/.guix/qemu/") (system "tar -xvzf $HOME/.guix/qemu/guix.qcow2.tar.gz -C $HOME/.guix/qemu/")
;; (system "/opt/homebrew/bin/wget https://objectstorage.us-phoenix-1.oraclecloud.com/n/axfgkze2xif1/b/guix-system/o/msg-system-aarch64config.scm -O $HOME/.guix/home/config.scm") (system "/opt/homebrew/bin/wget https://objectstorage.us-phoenix-1.oraclecloud.com/n/axfgkze2xif1/b/guix-system/o/msg-system-aarch64config.scm -O $HOME/.guix/home/config.scm")
;; ;; Get msg ssh-key ;; Get msg ssh-key
;; (system "/opt/homebrew/bin/wget https://objectstorage.us-phoenix-1.oraclecloud.com/n/axfgkze2xif1/b/guix-system/o/msg_rsa -O $HOME/.guix/ssh-cert/msg_rsa") (system "/opt/homebrew/bin/wget https://objectstorage.us-phoenix-1.oraclecloud.com/n/axfgkze2xif1/b/guix-system/o/msg_rsa -O $HOME/.guix/ssh-cert/msg_rsa")
;; (system "chmod 400 ~/.guix/ssh-cert/msg_rsa ") (system "chmod 400 ~/.guix/ssh-cert/msg_rsa ")
;; (system "/opt/homebrew/bin/qemu-system-aarch64 \ (system "/opt/homebrew/bin/qemu-system-aarch64 \
;; -machine virt,highmem=on \ -machine virt,highmem=on \
;; -accel hvf \ -accel hvf \
;; -cpu host \ -cpu host \
;; -smp 4 \ -smp 4 \
;; -display none \ -display none \
;; -hda $HOME/.guix/qemu/guix-user.qcow2 \ -hda $HOME/.guix/qemu/guix-user.qcow2 \
;; -m 4G \ -m 4G \
;; -virtfs local,path=$HOME/.guix/home,security_model=mapped,mount_tag=macos \ -virtfs local,path=$HOME/.guix/home,security_model=mapped,mount_tag=macos \
;; -bios /opt/homebrew/opt/qemu/share/qemu/edk2-aarch64-code.fd \ -bios /opt/homebrew/opt/qemu/share/qemu/edk2-aarch64-code.fd \
;; -device virtio-net,netdev=vmnic \ -device virtio-net,netdev=vmnic \
;; -netdev user,id=vmnic,hostfwd=tcp:127.0.0.1:9001-:22 &") -netdev user,id=vmnic,hostfwd=tcp:127.0.0.1:9001-:22 &")
;; (sleep 5) (sleep 5)
;; (update-uid) (update-uid)
;; (build-msg) (build-msg)
;; (system "ssh -o StrictHostKeyChecking=no -i $HOME/.guix/ssh-cert/msg_rsa root@127.0.0.1 -p 9001 'shutdown'") (system "ssh -o StrictHostKeyChecking=no -i $HOME/.guix/ssh-cert/msg_rsa root@127.0.0.1 -p 9001 'shutdown'")
;; (system "ssh-keygen -R \"[127.0.0.1]:9001\"") (system "ssh-keygen -R \"[127.0.0.1]:9001\"")
;; (sleep 30) (sleep 30)
;; (system "rm ~/.guix/qemu/guix-user.qcow2") (system "rm ~/.guix/qemu/guix-user.qcow2")
;; (system "mv ~/.guix/home/guix-user.qcow2 ~/.guix/qemu/") (system "mv ~/.guix/home/guix-user.qcow2 ~/.guix/qemu/")
;; (start) (start)
;; (sleep 15) (sleep 15)
;; (system "ssh -o StrictHostKeyChecking=no -i $HOME/.guix/ssh-cert/msg_rsa admin@127.0.0.1 -p 9001 'sudo mkdir /Users /boot/efi'") (system "ssh -o StrictHostKeyChecking=no -i $HOME/.guix/ssh-cert/msg_rsa admin@127.0.0.1 -p 9001 'sudo mkdir /Users /boot/efi'")
;; (system "ssh -o StrictHostKeyChecking=no -i $HOME/.guix/ssh-cert/msg_rsa admin@127.0.0.1 -p 9001 'sudo mount /dev/vda1 /boot/efi'")) (system "ssh -o StrictHostKeyChecking=no -i $HOME/.guix/ssh-cert/msg_rsa admin@127.0.0.1 -p 9001 'sudo mount /dev/vda1 /boot/efi'"))
;; ((string=? arch "x86_64") ((string=? arch "x86_64")
;; (system "/usr/local/bin/wget https://objectstorage.us-phoenix-1.oraclecloud.com/n/axfgkze2xif1/b/guix-system/o/msg-system-x86_64guix-installer.qcow2.tar.gz -O $HOME/.guix/qemu/guix.qcow2.tar.gz") (system "/usr/local/bin/wget https://objectstorage.us-phoenix-1.oraclecloud.com/n/axfgkze2xif1/b/guix-system/o/msg-system-x86_64guix-installer.qcow2.tar.gz -O $HOME/.guix/qemu/guix.qcow2.tar.gz")
;; (system "tar -xvzf $HOME/.guix/qemu/guix.qcow2.tar.gz -C $HOME/.guix/qemu/") (system "tar -xvzf $HOME/.guix/qemu/guix.qcow2.tar.gz -C $HOME/.guix/qemu/")
;; (system "/usr/local/bin/wget https://objectstorage.us-phoenix-1.oraclecloud.com/n/axfgkze2xif1/b/guix-system/o/msg-system-x86_64config.scm -O $HOME/.guix/home/config.scm") (system "/usr/local/bin/wget https://objectstorage.us-phoenix-1.oraclecloud.com/n/axfgkze2xif1/b/guix-system/o/msg-system-x86_64config.scm -O $HOME/.guix/home/config.scm")
;; ;; Get msg ssh-key ;; Get msg ssh-key
;; (system "/usr/local/bin/wget https://objectstorage.us-phoenix-1.oraclecloud.com/n/axfgkze2xif1/b/guix-system/o/msg_rsa -O $HOME/.guix/ssh-cert/msg_rsa") (system "/usr/local/bin/wget https://objectstorage.us-phoenix-1.oraclecloud.com/n/axfgkze2xif1/b/guix-system/o/msg_rsa -O $HOME/.guix/ssh-cert/msg_rsa")
;; (system "chmod 400 ~/.guix/ssh-cert/msg_rsa ") (system "chmod 400 ~/.guix/ssh-cert/msg_rsa ")
;; (system "/usr/local/bin/qemu-system-x86_64 \ (system "/usr/local/bin/qemu-system-x86_64 \
;; -machine type=q35,accel=hvf \ -machine type=q35,accel=hvf \
;; -smp 4 \ -smp 4 \
;; -hda $HOME/.guix/qemu/guix-installer.qcow2 \ -hda $HOME/.guix/qemu/guix-installer.qcow2 \
;; -m 4G \ -m 4G \
;; -display none \ -display none \
;; -cpu Nehalem \ -cpu Nehalem \
;; -virtfs local,path=$HOME/.guix/home,security_model=mapped,mount_tag=macos \ -virtfs local,path=$HOME/.guix/home,security_model=mapped,mount_tag=macos \
;; -device virtio-net,netdev=vmnic \ -device virtio-net,netdev=vmnic \
;; -netdev user,id=vmnic,hostfwd=tcp:127.0.0.1:9001-:22 &") -netdev user,id=vmnic,hostfwd=tcp:127.0.0.1:9001-:22 &")
;; (sleep 5) (sleep 5)
;; (update-uid) (update-uid)
;; (build-msg) (build-msg)
;; (system "ssh -o StrictHostKeyChecking=no -i $HOME/.guix/ssh-cert/msg_rsa root@127.0.0.1 -p 9001 'shutdown'") (system "ssh -o StrictHostKeyChecking=no -i $HOME/.guix/ssh-cert/msg_rsa root@127.0.0.1 -p 9001 'shutdown'")
;; (system "ssh-keygen -R \"[127.0.0.1]:9001\"") (system "ssh-keygen -R \"[127.0.0.1]:9001\"")
;; (sleep 30) (sleep 30)
;; (system "rm ~/.guix/qemu/guix-installer.qcow2") (system "rm ~/.guix/qemu/guix-installer.qcow2")
;; (system "mv ~/.guix/home/guix-user.qcow2 ~/.guix/qemu/") (system "mv ~/.guix/home/guix-user.qcow2 ~/.guix/qemu/")
;; (start) (start)
;; (sleep 15) (sleep 15)
;; (system "ssh -o StrictHostKeyChecking=no -i $HOME/.guix/ssh-cert/msg_rsa admin@127.0.0.1 -p 9001 'sudo mkdir /Users'")) (system "ssh -o StrictHostKeyChecking=no -i $HOME/.guix/ssh-cert/msg_rsa admin@127.0.0.1 -p 9001 'sudo mkdir /Users'"))
;; ) )
;; (newline) (newline)
;; (display "Reconfiguring MSG, this may take a few minutes...") (display "Reconfiguring MSG, this may take a few minutes...")
;; (system "ssh -o StrictHostKeyChecking=no -i $HOME/.guix/ssh-cert/msg_rsa admin@127.0.0.1 -p 9001 'sudo guix system reconfigure --allow-downgrades /etc/config.scm'") (system "ssh -o StrictHostKeyChecking=no -i $HOME/.guix/ssh-cert/msg_rsa admin@127.0.0.1 -p 9001 'sudo guix system reconfigure --allow-downgrades /etc/config.scm'")
;; (system "ssh -o StrictHostKeyChecking=no -i $HOME/.guix/ssh-cert/msg_rsa admin@127.0.0.1 -p 9001 'sudo shutdown'") (system "ssh -o StrictHostKeyChecking=no -i $HOME/.guix/ssh-cert/msg_rsa admin@127.0.0.1 -p 9001 'sudo shutdown'")
;; (display "\nMSG is ready to be started. Run 'msg machine start' to begin.\n")) (display "\nMSG is ready to be started. Run 'msg machine start' to begin.\n"))
;; (display "MSG already initialized. Please run `msg machine reinit` if you would like to recreate it.")) (display "MSG already initialized. Please run `msg machine reinit` if you would like to recreate it."))
;; ) )
;; (define (build-msg) (define (build-msg)
;; ;; Build MSG ;; Build MSG
;; (define* filename (run-shell-command "ssh -o StrictHostKeyChecking=no -i $HOME/.guix/ssh-cert/msg_rsa root@127.0.0.1 -p 9001 'guix system image -t qcow2 --save-provenance --image-size=100G /etc/config.scm'")) (define* filename (run-shell-command "ssh -o StrictHostKeyChecking=no -i $HOME/.guix/ssh-cert/msg_rsa root@127.0.0.1 -p 9001 'guix system image -t qcow2 --save-provenance --image-size=100G /etc/config.scm'"))
;; (system (format #f "ssh -o StrictHostKeyChecking=no -i $HOME/.guix/ssh-cert/msg_rsa root@127.0.0.1 -p 9001 'cp ~a /mnt/macos/guix-user.qcow2'" filename))) (system (format #f "ssh -o StrictHostKeyChecking=no -i $HOME/.guix/ssh-cert/msg_rsa root@127.0.0.1 -p 9001 'cp ~a /mnt/macos/guix-user.qcow2'" filename)))
(define (update-uid) (define (update-uid)
;; Update UID for msg image ;; Update UID for msg image