-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
82 lines (62 loc) · 2.52 KB
/
Makefile
File metadata and controls
82 lines (62 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
STRIPPED_ISO := $(ISO)/stripped.iso
RAW_ISO := $(ISO)/raw.iso
ISO_MOUNT_DIR := $(ISO)/NIXOS_ISO
MACHINE_UUID := $(MACHINE)/uuid
MACHINE_DISK := $(MACHINE)/disk.qcow2
MACHINE_CONSOLE := $(MACHINE)/console
MACHINE_PIDFILE := $(MACHINE)/hyperkit.pid
MACHINE_KERNEL := $(MACHINE)/kernel
MACHINE_INITRD := $(MACHINE)/initrd
MEMORY := 2G
CPUS := 2
.PHONY: clean $(MACHINE) install run poweroff
$(ISO_MOUNT_DIR): $(STRIPPED_ISO)
hdiutil attach -mountpoint $@ $(STRIPPED_ISO)
$(STRIPPED_ISO): $(RAW_ISO)
dd if=/dev/zero bs=2k count=1 of=$@
dd if=$(RAW_ISO) bs=2k skip=1 >> $@
$(RAW_ISO):
[ -f $@ ]
$(MACHINE):
mkdir -p $@
[ -f $(MACHINE_DISK) ] || qcow-tool create --size=50GiB $(MACHINE_DISK)
[ -f $(MACHINE_UUID) ] || uuidgen > $(MACHINE_UUID)
poweroff:
sudo kill $(shell cat $(MACHINE_PIDFILE))
clean:
hdiutil detach $(ISO_MOUNT_DIR)
livecd: $(ISO_MOUNT_DIR)
sudo bin/hyperkit -A -m $(MEMORY) -c $(CPUS) -u \
-l com1,stdio \
-s 0:0,hostbridge \
-s 1,virtio-net \
-s 2,ahci-cd,$(shell pwd)/$(RAW_ISO) \
-s 31,lpc \
-f kexec,$(ISO_MOUNT_DIR)/boot/bzImage,$(ISO_MOUNT_DIR)/boot/initrd,"earlyprintk=serial console=ttyS0 $(shell cat $(ISO_MOUNT_DIR)/loader/entries/nixos-iso.conf | grep '^options' | cut -d ' ' -f 2-)"
install: $(ISO_MOUNT_DIR) $(MACHINE)
[ -f $(MACHINE_PIDFILE) ] && sudo kill -0 $(shell cat $(MACHINE_PIDFILE)) && \
echo "Machine running!" && exit 1 || \
rm -rf $(MACHINE_PIDFILE)
sudo bin/hyperkit -A -m $(MEMORY) -c $(CPUS) -u \
-F $(MACHINE_PIDFILE) \
-U $(shell cat $(MACHINE_UUID)) \
-l com1,stdio \
-s 0:0,hostbridge \
-s 1:0,ahci-hd,file://$(shell pwd)/$(MACHINE_DISK),format=qcow \
-s 2:0,virtio-net \
-s 3,ahci-cd,$(shell pwd)/$(RAW_ISO) \
-s 31,lpc \
-f kexec,$(ISO_MOUNT_DIR)/boot/bzImage,$(ISO_MOUNT_DIR)/boot/initrd,"earlyprintk=serial console=ttyS0 $(shell cat $(ISO_MOUNT_DIR)/loader/entries/nixos-iso.conf | grep '^options' | cut -d ' ' -f 2-)"
run: $(MACHINE)
[ -f $(MACHINE_PIDFILE) ] && sudo kill -0 $(shell cat $(MACHINE_PIDFILE)) && \
echo "Machine running!" && exit 1 || \
rm -rf $(MACHINE_PIDFILE)
sudo nohup -- bin/hyperkit -A -m $(MEMORY) -c $(CPUS) -u \
-F $(MACHINE_PIDFILE) \
-U $(shell cat $(MACHINE_UUID)) \
-l com1,autopty=$(MACHINE_CONSOLE),log=$(MACHINE_CONSOLE).log \
-s 0:0,hostbridge \
-s 1:0,ahci-hd,file://$(shell pwd)/$(MACHINE_DISK),format=qcow \
-s 2:0,virtio-net \
-s 31,lpc \
-f kexec,$(MACHINE_KERNEL),$(MACHINE_INITRD),"earlyprintk=serial console=ttyS0 loglevel=4 init=/nix/var/nix/profiles/system/init" 2>&1 > $(MACHINE)/hyperkit.log &