Files
bootler/package.nix
2026-02-28 23:25:10 +01:00

46 lines
873 B
Nix

{
stdenv,
nasm,
qemu,
...
}: let
bootImg = "boot";
in
stdenv.mkDerivation {
pname = "bootler";
version = "0.1.0";
src = ./.;
buildPhase = ''
${nasm}/bin/nasm boot.asm -o ${bootImg}
'';
installPhase = ''
mkdir -p $out/bin
cp ${bootImg} $out/bin
# create emulation binary
cat<<EOF>$out/bin/bootler
#!/usr/bin/env bash
# create temp dir
mkdir -p ./.bootler
cp $(echo $out)/bin/${bootImg} ./.bootler/${bootImg}
chmod a+w ./.bootler/${bootImg}
echo "press any key to continue. Qemu will clear the screen..."
read -s -n 1
# run image
${qemu}/bin/qemu-system-x86_64 \
-nographic \
-hda ./.bootler/${bootImg}
# clean up
rm ./.bootler -r
EOF
chmod +x $out/bin/${bootImg}
chmod +x $out/bin/bootler
'';
}