利用nix,在本地一次性配置完整的rcore开发环境,严格使用教程推荐的rust与qemu的版本,不需要rustup
flake.nix如下
{ description = "rCore dev flake"; inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; oldnixpkgs.url = "github:NixOS/nixpkgs/7cf5ccf1cdb2ba5f08f0ac29fc3d04b0b59a07e4"; flake-utils.url = "github:numtide/flake-utils"; rust-overlay = { url = "github:oxalica/rust-overlay"; inputs.nixpkgs.follows = "nixpkgs"; }; }; outputs = { nixpkgs, oldnixpkgs, flake-utils, rust-overlay, ... }: flake-utils.lib.eachDefaultSystem (system: let pkgs = import nixpkgs { inherit system; overlays = [(import rust-overlay)]; }; oldpkgs = import oldnixpkgs { inherit system; }; in { devShells.default = pkgs.mkShell { packages = with pkgs; [ (rust-bin.nightly."2024-05-02".minimal.override { extensions = [ "rust-src" "llvm-tools" "rustfmt" "rust-analyzer" "rust-docs" ]; targets = ["riscv64gc-unknown-none-elf"]; }) cargo-binutils python3 gdb tmux ] ++ [oldpkgs.qemu]; # qemu 7.0 # 进入环境后显示rust和qemu版本 shellHook = '' rustc --version cargo --version qemu-system-riscv64 --version qemu-riscv64 --version ''; }; }); }
建议使用非官方的The Determinate Nix Installer安装nix:
curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | sh -s -- install
在Windows的wsl中安装需要先启用systemd。具体安装方法参考https://github.com/DeterminateSystems/nix-installer