Execute some code at boot made accessible to the VM by mounting a disk
This commit is contained in:
parent
030c6af523
commit
d78efe46ba
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -1,2 +1,4 @@
|
|||
/*.nar
|
||||
/signing-key.pub
|
||||
/*.sizes
|
||||
/signing-key.pub
|
||||
/vm-image
|
31
Makefile
31
Makefile
|
@ -1,24 +1,31 @@
|
|||
tmp_image := $(shell echo $$$$)
|
||||
|
||||
all: hello.nar signing-key.pub vm-image Makefile
|
||||
all: hello.nar hello.sizes signing-key.pub vm-image Makefile
|
||||
qemu-img create -f qcow2 -o backing_file=vm-image vm-image-${tmp_image}
|
||||
# TODO: qcow2: make a derived image.
|
||||
qemu-system-x86_64 -enable-kvm -m 256 \
|
||||
vm-image-${tmp_image} \
|
||||
-drive format=raw,readonly,file=hello.nar,index=0,if=ide,index=1,media=cdrom \
|
||||
-drive format=raw,readonly,file=signing-key.pub,index=0,if=ide,index=2,media=cdrom
|
||||
-drive format=raw,file=hello.sizes,if=ide,index=1,media=disk \
|
||||
-drive format=raw,file=to-be-run-in-vm.sh,if=ide,index=2,media=disk \
|
||||
-drive format=raw,file=hello.nar,if=ide,index=3,media=disk \
|
||||
# -drive format=raw,file=signing-key.pub,if=ide,index=4,media=disk
|
||||
rm vm-image-${tmp_image}
|
||||
|
||||
%.sizes: %.nar signing-key.pub Makefile
|
||||
printf "%020d\\n%020d\\n%020d\\n%$$((512-((20+1)*3)-1))s\\n" \
|
||||
"$$(wc -c "to-be-run-in-vm.sh" | sed -e 's/^[[:space:]]*\([0-9][0-9]*\)[[:space:]].*$$/\1/')" \
|
||||
"$$(wc -c "$*.nar" | sed -e 's/^[[:space:]]*\([0-9][0-9]*\)[[:space:]].*$$/\1/')" \
|
||||
"$$(wc -c "signing-key.pub" | sed -e 's/^[[:space:]]*\([0-9][0-9]*\)[[:space:]].*$$/\1/')" \
|
||||
"" \
|
||||
> $@
|
||||
|
||||
%.nar: Makefile
|
||||
guix archive --export --recursive $* > $@
|
||||
guix archive --export --recursive '$*' > '$@'
|
||||
|
||||
signing-key.pub: /etc/guix/signing-key.pub Makefile
|
||||
cp $< $@
|
||||
chmod +w $@
|
||||
cp '$<' '$@'
|
||||
chmod +w '$@'
|
||||
|
||||
.PHONY: rebuild
|
||||
rebuild: config.scm Makefile
|
||||
ln -s "$$(guix system vm-image config.scm)" vm-image
|
||||
|
||||
vm-image: config.scm # Makefile
|
||||
ln -s "$$(guix system vm-image config.scm)" vm-image
|
||||
vm-image: config.scm Makefile
|
||||
rm -f '$@'
|
||||
ln -sf "$$(guix system vm-image config.scm)" '$@'
|
||||
|
|
17
config.scm
17
config.scm
|
@ -1,12 +1,15 @@
|
|||
(use-modules (gnu)
|
||||
(gnu services shepherd))
|
||||
|
||||
(define (my-service)
|
||||
(shepherd-service
|
||||
(documentation "This command is executed when the GUIX system boots.")
|
||||
(provision '(my-stuff))
|
||||
(start #~(lambda ()
|
||||
(system* "seq 1000")))))
|
||||
(define my-service
|
||||
(shepherd-service-type
|
||||
'run-commands-at-boot
|
||||
(lambda (x)
|
||||
(shepherd-service
|
||||
(documentation "This command is executed when the GUIX system boots.")
|
||||
(provision '(my-stuff))
|
||||
(start #~(lambda ()
|
||||
(system "(read len < /dev/sdb; dd if=/dev/sdc bs=1 count=$len | sh) > /dev/tty1")))))))
|
||||
|
||||
(operating-system
|
||||
(bootloader
|
||||
|
@ -20,6 +23,6 @@
|
|||
(mount-point "/")
|
||||
(type "ext4"))
|
||||
%base-file-systems))
|
||||
(services (cons (my-service)
|
||||
(services (cons (service my-service 42)
|
||||
%base-services))
|
||||
(timezone "GMT"))
|
||||
|
|
9
to-be-run-in-vm.sh
Normal file
9
to-be-run-in-vm.sh
Normal file
|
@ -0,0 +1,9 @@
|
|||
#!/bin/sh
|
||||
|
||||
echo LALALA
|
||||
{ read len_script; read len_nar; read len_key; } < /dev/sdb
|
||||
echo x $len_script y $len_nar z $len_key t
|
||||
head -c "$len_nar" /dev/sdd | sha1sum
|
||||
echo DONE
|
||||
# dd if=/dev/sde bs=1 count=$len_key | sha1sum
|
||||
#
|
Loading…
Reference in New Issue
Block a user