commit d78efe46baf84bfc5f06537146fa9e2a35364edc
parent 030c6af5236f277210b4e2f8bd79685ad2870758
Author: Georges Dupéron <georges.duperon@gmail.com>
Date: Sat, 8 Sep 2018 20:12:40 +0200
Execute some code at boot made accessible to the VM by mounting a disk
Diffstat:
4 files changed, 42 insertions(+), 21 deletions(-)
diff --git a/.gitignore b/.gitignore
@@ -1,2 +1,4 @@
/*.nar
-/signing-key.pub
-\ No newline at end of file
+/*.sizes
+/signing-key.pub
+/vm-image
+\ No newline at end of file
diff --git a/Makefile b/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 $@
-
-.PHONY: rebuild
-rebuild: config.scm Makefile
- ln -s "$$(guix system vm-image config.scm)" vm-image
+ cp '$<' '$@'
+ chmod +w '$@'
-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)" '$@'
diff --git a/config.scm b/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"))
diff --git a/to-be-run-in-vm.sh b/to-be-run-in-vm.sh
@@ -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
+#