Skip to content

Commit 41bb1e8

Browse files
author
fnerdman
committed
feat: adds makefile
1 parent 474b625 commit 41bb1e8

File tree

2 files changed

+129
-3
lines changed

2 files changed

+129
-3
lines changed

Makefile

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
BASE_TARGET := base
2+
BUILDERNET_TARGET := buildernet
3+
NIX_CHECK ?= 1
4+
5+
# Default target
6+
.PHONY: all
7+
all: $(BASE_TARGET) $(BUILDERNET_TARGET)
8+
9+
# Development targets
10+
.PHONY: dev
11+
dev: $(BASE_TARGET)-dev $(BUILDERNET_TARGET)-dev
12+
13+
# Check if running in nix shell
14+
.PHONY: check-nix
15+
check-nix:
16+
ifeq ($(NIX_CHECK), 1)
17+
@if ! command -v nix >/dev/null 2>&1; then \
18+
echo "Nix not found. Installing..."; \
19+
sh -c "curl -L https://nixos.org/nix/install | sh -s -- --no-daemon"; \
20+
echo "Nix installed. Please restart your terminal and run the command again."; \
21+
exit 1; \
22+
fi
23+
@if [ -z "$$IN_NIX_SHELL" ]; then \
24+
echo "Not in nix shell. Starting nix shell..."; \
25+
nix --extra-experimental-features "nix-command flakes" develop -c make $(MAKECMDGOALS); \
26+
exit $$?; \
27+
fi
28+
endif
29+
30+
# Base image target
31+
.PHONY: $(BASE_TARGET)
32+
$(BASE_TARGET): check-nix
33+
@echo "Creating base image: $(BASE_TARGET)"
34+
mkosi --force --include=base/base.conf
35+
@echo "Base image created successfully."
36+
37+
# Buildernet image target
38+
.PHONY: $(BUILDERNET_TARGET)
39+
$(BUILDERNET_TARGET): check-nix
40+
@echo "Creating buildernet image: $(BUILDERNET_TARGET)"
41+
mkosi --force --include=base/base.conf --include=buildernet/buildernet.conf
42+
@echo "Buildernet image created successfully."
43+
44+
# Development image targets
45+
.PHONY: $(BASE_TARGET)-dev
46+
$(BASE_TARGET)-dev: check-nix
47+
@echo "Creating development base image: $(BASE_TARGET)-dev"
48+
mkosi --force --include=base/base.conf --include=devtools/devtools.conf
49+
@echo "Development base image created successfully."
50+
51+
.PHONY: $(BUILDERNET_TARGET)-dev
52+
$(BUILDERNET_TARGET)-dev: check-nix
53+
@echo "Creating development buildernet image: $(BUILDERNET_TARGET)-dev"
54+
mkosi --force --include=base/base.conf --include=buildernet/buildernet.conf --include=devtools/devtools.conf
55+
@echo "Development buildernet image created successfully."
56+
57+
# Kernel update target - run outside nix shell
58+
.PHONY: kernel-update
59+
kernel-update:
60+
@echo "Rebuilding kernel..."
61+
nix build --rebuild
62+
@echo "Kernel rebuilt. Please restart nix shell."
63+
64+
# Clean target
65+
.PHONY: clean
66+
clean:
67+
@echo "Cleaning build artifacts..."
68+
rm -rf build
69+
rm -f *.qcow2
70+
rm -rf mkosi.builddir
71+
@echo "Build artifacts cleaned."
72+
73+
# Run target to start QEMU
74+
.PHONY: run
75+
run:
76+
@if [ ! -f persistent.qcow2 ]; then \
77+
echo "Creating persistent storage..."; \
78+
qemu-img create -f qcow2 persistent.qcow2 2048G; \
79+
fi
80+
@echo "Starting QEMU..."
81+
sudo qemu-system-x86_64 \
82+
-enable-kvm \
83+
-machine type=q35,smm=on \
84+
-m 16384M \
85+
-nographic \
86+
-drive if=pflash,format=raw,readonly=on,file=/usr/share/edk2/x64/OVMF_CODE.secboot.4m.fd \
87+
-drive file=/usr/share/edk2/x64/OVMF_VARS.4m.fd,if=pflash,format=raw \
88+
-kernel build/tdx-debian \
89+
-drive file=persistent.qcow2,format=qcow2,if=virtio,cache=writeback
90+
91+
# Environment setup target
92+
.PHONY: env-setup
93+
env-setup:
94+
@if [ ! -f env.json ]; then \
95+
echo "Creating env.json from example..."; \
96+
cp env.json.example env.json; \
97+
echo "Please edit env.json with your configuration values."; \
98+
else \
99+
echo "env.json already exists."; \
100+
fi
101+
102+
# Verify packages
103+
.PHONY: verify
104+
verify:
105+
@echo "Verifying package reproducibility..."
106+
python3 scripts/verify.py
107+
@echo "Verification complete."
108+
109+
# Help target
110+
.PHONY: help
111+
help:
112+
@echo "Usage: make [target]"
113+
@echo ""
114+
@echo "Targets:"
115+
@echo " all Build all production images ($(BASE_TARGET), $(BUILDERNET_TARGET))"
116+
@echo " dev Build all development images ($(BASE_TARGET)-dev, $(BUILDERNET_TARGET)-dev)"
117+
@echo " $(BASE_TARGET) Build base image only"
118+
@echo " $(BUILDERNET_TARGET) Build base + buildernet image"
119+
@echo " $(BASE_TARGET)-dev Build base development image"
120+
@echo " $(BUILDERNET_TARGET)-dev Build base + buildernet development image"
121+
@echo " kernel-update Rebuild kernel (run outside nix shell)"
122+
@echo " clean Clean build artifacts"
123+
@echo " run Run the system in QEMU (creates persistent storage if needed)"
124+
@echo " env-setup Create env.json from example if it doesn't exist"
125+
@echo " verify Verify package reproducibility"
126+
@echo ""
127+
@echo "Notes:"
128+
@echo " - Run within nix shell: nix develop -c make [target]"
129+
@echo " - Use NIX_CHECK=0 to bypass nix shell check"

mkosi.conf

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1 @@
11
[Config]
2-
Include=base/base.conf
3-
Include=buildernet/buildernet.conf
4-
Include=devtools/devtools.conf

0 commit comments

Comments
 (0)