summaryrefslogtreecommitdiff
path: root/nix/package.nix
diff options
context:
space:
mode:
Diffstat (limited to 'nix/package.nix')
-rw-r--r--nix/package.nix47
1 files changed, 47 insertions, 0 deletions
diff --git a/nix/package.nix b/nix/package.nix
new file mode 100644
index 0000000..3d56a51
--- /dev/null
+++ b/nix/package.nix
@@ -0,0 +1,47 @@
+{
+ stdenv,
+ nasm,
+ qemu,
+ ...
+}: let
+ bootImg = "boot";
+in
+ stdenv.mkDerivation {
+ pname = "bootler";
+ version = "0.1.0";
+ src = ../.;
+ buildPhase = ''
+ ${nasm}/bin/nasm asm/boot.asm -o boot.bin
+ ${nasm}/bin/nasm asm/kernel.asm -o kernel.bin
+
+ dd if=/dev/zero of=${bootImg} bs=512 count=2
+ dd if=boot.bin of=${bootImg} conv=notrunc
+ dd if=kernel.bin of=${bootImg} bs=512 seek=1 conv=notrunc
+ '';
+ 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}
+
+ # run image
+ ${qemu}/bin/qemu-system-x86_64 \
+ -nographic \
+ -drive file=./.bootler/${bootImg},format=raw,index=0,media=disk
+
+ # clean up
+ rm ./.bootler -r
+
+ EOF
+
+ chmod +x $out/bin/${bootImg}
+ chmod +x $out/bin/bootler
+ '';
+ }