Skip to content

Commit 6711dd2

Browse files
committed
wip: migrate away from dracut
1 parent 72720f4 commit 6711dd2

File tree

3 files changed

+36
-58
lines changed

3 files changed

+36
-58
lines changed

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ members = [
2626
"sandpolis-shell",
2727
"sandpolis-snapshot",
2828
"sandpolis-tunnel",
29-
"sandpolis-uki",
3029
"sandpolis-user",
3130
]
3231

sandpolis/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
result/

sandpolis/flake.nix

Lines changed: 35 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,12 @@
4949

5050
# Minimal init script to launch the agent
5151
initScript = pkgs.writeScript "init" ''
52-
#!/bin/sh
52+
#!${pkgs.busybox}/bin/sh
5353
set -e
5454
55+
# Create busybox symlinks
56+
/bin/busybox --install -s /bin
57+
5558
# Mount essential filesystems
5659
mount -t proc proc /proc
5760
mount -t sysfs sys /sys
@@ -68,60 +71,33 @@
6871
exec /sbin/sandpolis
6972
'';
7073

71-
# Create initramfs with dracut
74+
# Create initramfs with makeInitrd
7275
buildInitramfs = kernel:
73-
pkgs.stdenv.mkDerivation {
76+
pkgs.makeInitrd {
7477
name = "sandpolis-initramfs";
7578

76-
nativeBuildInputs = [ pkgs.dracut pkgs.cpio pkgs.findutils ];
77-
78-
buildCommand = ''
79-
mkdir -p $out
80-
81-
# Create a minimal root filesystem structure
82-
mkdir -p rootfs/{bin,sbin,dev,proc,sys,tmp,run,var,lib,lib64,etc}
83-
84-
# Copy the agent binary
85-
cp ${sandpolis-agent}/bin/sandpolis rootfs/sbin/sandpolis
86-
chmod +x rootfs/sbin/sandpolis
87-
88-
# Copy the init script
89-
cp ${initScript} rootfs/init
90-
chmod +x rootfs/init
91-
92-
# Copy required shared libraries
93-
mkdir -p rootfs/lib/x86_64-linux-gnu 2>/dev/null || true
94-
mkdir -p rootfs/lib/aarch64-linux-gnu 2>/dev/null || true
95-
96-
# Find and copy all required shared libraries
97-
for lib in $(ldd ${sandpolis-agent}/bin/sandpolis | grep -o '/nix/store/[^ ]*'); do
98-
if [ -f "$lib" ]; then
99-
cp -L "$lib" rootfs/lib/ 2>/dev/null || \
100-
cp -L "$lib" rootfs/lib64/ 2>/dev/null || true
101-
fi
102-
done
103-
104-
# Copy essential busybox for shell commands in init
105-
cp ${pkgs.busybox}/bin/busybox rootfs/bin/sh
106-
ln -s sh rootfs/bin/mount
107-
ln -s sh rootfs/bin/ip
108-
ln -s sh rootfs/bin/mkdir
109-
ln -s sh rootfs/bin/echo
110-
ln -s sh rootfs/bin/exec
111-
112-
# Create the initramfs with dracut
113-
${pkgs.dracut}/bin/dracut \
114-
--force \
115-
--no-hostonly \
116-
--no-hostonly-cmdline \
117-
--kmoddir ${kernel}/lib/modules \
118-
--kver "${kernel.version}" \
119-
--include rootfs / \
120-
--no-compress \
121-
$out/initramfs.img
122-
123-
echo "Initramfs created at $out/initramfs.img"
124-
'';
79+
# Use gzip compression (standard for initramfs)
80+
compressor = "gzip";
81+
82+
contents = [
83+
# Include the init script at /init
84+
{
85+
object = initScript;
86+
symlink = "/init";
87+
}
88+
89+
# Include the Sandpolis agent
90+
{
91+
object = sandpolis-agent;
92+
symlink = "/sbin/sandpolis";
93+
}
94+
95+
# Include busybox for shell utilities
96+
{
97+
object = pkgs.busybox;
98+
symlink = "/bin/busybox";
99+
}
100+
];
125101
};
126102

127103
kernel = pkgs.linuxPackages_latest.kernel;
@@ -133,17 +109,20 @@
133109
name = "sandpolis-uki";
134110

135111
nativeBuildInputs = [
136-
pkgs.systemd # provides ukify
112+
pkgs.systemdUkify # provides ukify
137113
pkgs.binutils
138114
];
139115

140116
buildCommand = ''
141117
mkdir -p $out
142118
143-
# Use systemd's ukify to create the UKI
144-
${pkgs.systemd}/lib/systemd/ukify build \
119+
# Use ukify to create the UKI
120+
${pkgs.systemdUkify}/bin/ukify build \
145121
--linux=${kernel}/bzImage \
146-
--initrd=${initramfs}/initramfs.img \
122+
--initrd=${initramfs}/initrd \
123+
--os-release='NAME="Sandpolis"
124+
ID=sandpolis
125+
VERSION="0.1.0"' \
147126
--cmdline="console=ttyS0 console=tty0 quiet" \
148127
--output=$out/sandpolis.efi
149128
@@ -219,7 +198,6 @@
219198
pkgs.cmake
220199
pkgs.openssl
221200
pkgs.systemd
222-
pkgs.dracut
223201

224202
# Testing/debugging tools
225203
pkgs.qemu

0 commit comments

Comments
 (0)