diff options
Diffstat (limited to 'nix/pkgs/bootle.nix')
| -rw-r--r-- | nix/pkgs/bootle.nix | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/nix/pkgs/bootle.nix b/nix/pkgs/bootle.nix new file mode 100644 index 0000000..5c3c63d --- /dev/null +++ b/nix/pkgs/bootle.nix @@ -0,0 +1,63 @@ +{ + callPackage, + rust-bin, + naersk, + bootler, + qemu, + ... +}: let + rust-toolchain = rust-bin.fromRustupToolchainFile ../../rust-toolchain.toml; + naersk' = callPackage naersk { + cargo = rust-toolchain; + rustc = rust-toolchain; + clippy = rust-toolchain; + }; +in (naersk'.buildPackage { + src = ../../.; + + # deps for rust-src + additionalCargoLock = "${rust-toolchain.availableComponents.rust-src}/lib/rustlib/src/rust/library/Cargo.lock"; + + # just library build + copyBins = false; + release = true; + + # build std + cargoBuildOptions = x: x ++ ["-Zbuild-std=core,compiler_builtins,alloc" "-Zbuild-std-features=compiler-builtins-mem"]; + + postInstall = '' + ld --oformat binary \ + -o kernel.bin \ + -T src/linker.ld \ + -e _start \ + target/x86_64-unknown-none/release/libbootle.a + + dd if=/dev/zero of=disk bs=512 count=2 + dd if=${bootler}/bin/boot.bin of=disk conv=notrunc + dd if=kernel.bin of=disk bs=512 seek=1 conv=notrunc + + mkdir -p $out/lib + mkdir -p $out/bin + + cat<<EOF>$out/bin/bootle + #!/usr/bin/env bash + + mkdir -p ./.bootle + cp $(echo $out)/bin/disk ./.bootle/disk + chmod a+w ./.bootle/disk + + ${qemu}/bin/qemu-system-x86_64 \ + -nographic \ + -drive file=./.bootle/disk,format=raw,index=0,media=disk + + rm ./.bootle -r + + EOF + + chmod +x $out/bin/bootle + + cp target/x86_64-unknown-none/release/libbootle.a $out/lib + cp kernel.bin $out/bin + cp disk $out/bin + ''; +}) |
