summaryrefslogtreecommitdiff
path: root/flake.nix
diff options
context:
space:
mode:
authorNathan Ringo <nathan@remexre.com>2024-02-24 22:03:49 -0600
committerNathan Ringo <nathan@remexre.com>2024-02-24 22:03:49 -0600
commitc8de43bf43242c4ebac3d0ecb8e7951fe2371506 (patch)
treeb438bb1b47b41241702f5783fb7ec3326a4e8ab7 /flake.nix
Initial commit
Diffstat (limited to 'flake.nix')
-rw-r--r--flake.nix103
1 files changed, 103 insertions, 0 deletions
diff --git a/flake.nix b/flake.nix
new file mode 100644
index 0000000..9e812b8
--- /dev/null
+++ b/flake.nix
@@ -0,0 +1,103 @@
+{
+ inputs = {
+ fenix-flake = {
+ url = "github:nix-community/fenix";
+ inputs.nixpkgs.follows = "nixpkgs";
+ };
+ };
+ outputs = { self, fenix-flake, flake-utils, nixpkgs }:
+ flake-utils.lib.eachSystem [ "aarch64-linux" "x86_64-linux" ] (system:
+ let
+ pkgsBuild = nixpkgs.legacyPackages.${system};
+ pkgsHost = import nixpkgs {
+ inherit system;
+ crossSystem.config = "riscv64-unknown-none-elf";
+ };
+ fenix = fenix-flake.packages.${system};
+
+ toolchain = fenix.combine [
+ fenix.stable.cargo
+ fenix.stable.rustc
+ fenix.stable.clippy
+ fenix.targets.riscv64gc-unknown-none-elf.stable.rust-std
+ ];
+ rust = pkgsHost.makeRustPlatform {
+ cargo = toolchain;
+ rustc = toolchain;
+ };
+
+ packages = rec {
+ boards = import ./boards {
+ inherit libkernel;
+ pkgs = pkgsHost;
+ };
+ libkernel = pkgsBuild.callPackage ./kernel { inherit rust; };
+ };
+ run-vm = pkgsBuild.writeShellApplication {
+ name = "run-vm";
+
+ runtimeInputs = [ pkgsBuild.qemu ];
+
+ text = ''
+ set -x
+ qemu-system-riscv64 \
+ -machine virt \
+ -m 1G \
+ -nographic \
+ -bios none \
+ -kernel ${packages.boards.qemu-virt}/kernel.elf \
+ "$@"
+ '';
+ };
+ in {
+ apps = {
+ default = {
+ type = "app";
+ program = pkgsBuild.lib.getExe run-vm;
+ };
+
+ debug = {
+ type = "app";
+ program = pkgsBuild.lib.getExe (pkgsBuild.writeShellApplication {
+ name = "run-vm-debug";
+ runtimeInputs = [ run-vm ];
+ text = ''
+ port=$(( 1000 * ("$(id -u)" - 990) ))
+ run-vm -gdb tcp::$port -S "$@"
+ '';
+ });
+ };
+
+ gdb = {
+ type = "app";
+ program = pkgsBuild.lib.getExe (pkgsBuild.writeShellApplication {
+ name = "gdb";
+ runtimeInputs = [ toolchain ];
+ text = ''
+ port=$(( 1000 * ("$(id -u)" - 990) ))
+ rust-gdb ${packages.boards.qemu-virt}/kernel.elf \
+ -ex "target remote 127.0.0.1:$port" \
+ -ex "set riscv use-compressed-breakpoints yes" \
+ -ex "layout src" \
+ -ex "focus cmd" \
+ -ex "tbreak hart0_boot" \
+ -ex "c"
+ '';
+ });
+ };
+ };
+
+ devShells.default = pkgsBuild.mkShell {
+ inputsFrom =
+ builtins.attrValues (flake-utils.lib.flattenTree packages);
+ nativeBuildInputs = [
+ pkgsBuild.cargo-watch
+ pkgsBuild.qemu
+ pkgsHost.stdenv.cc.bintools.bintools
+ ];
+ CARGO_BUILD_TARGET = "riscv64gc-unknown-none-elf";
+ };
+
+ packages = flake-utils.lib.flattenTree packages;
+ });
+}