Skip to content

Instantly share code, notes, and snippets.

@jackyliu16
Last active October 26, 2024 17:49
Show Gist options
  • Save jackyliu16/e6952c26a3810e4b46a1d348831984dd to your computer and use it in GitHub Desktop.
Save jackyliu16/e6952c26a3810e4b46a1d348831984dd to your computer and use it in GitHub Desktop.
A flake of nix for rCore
{
description = "A devShell for rCore";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
nixpkgs-qemu7.url = "https://github.com/NixOS/nixpkgs/archive/7cf5ccf1cdb2ba5f08f0ac29fc3d04b0b59a07e4.tar.gz";
rust-overlay.url = "github:oxalica/rust-overlay";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, nixpkgs-qemu7, rust-overlay, flake-utils, ... }:
flake-utils.lib.eachDefaultSystem (system:
let
overlays = [
(import rust-overlay)
(self: super: {
# ref: https://github.com/the-nix-way/dev-templates
rust-toolchain =
let
rust = super.rust-bin;
in
if builtins.pathExists ./rust-toolchain.toml then
rust.fromRustupToolchainFile ./rust-toolchain.toml
else if builtins.pathExists ./rust-toolchain then
rust.fromRustupToolchainFile ./rust-toolchain
else
# The rust-toolchain when i make this file, which maybe change
(rust.nightly."2022-08-05".minimal.override {
extensions = [ "rust-src" "llvm-tools-preview" "rustfmt" "clippy" ];
targets = [ "riscv64gc-unknown-none-elf" ];
});
qemu = self.callPackage "${nixpkgs-qemu7}/pkgs/applications/virtualization/qemu" {
inherit (self.darwin.apple_sdk.frameworks) CoreServices Cocoa Hypervisor;
inherit (self.darwin.stubs) rez setfile;
inherit (self.darwin) sigtool;
# Reduces the number of qemu source files from ~10000 to ~2600 source files.
hostCpuTargets = ["riscv64-softmmu" "riscv32-softmmu"];
};
})
];
pkgs = import nixpkgs {
inherit system overlays;
};
in
{
devShells.default = pkgs.mkShell {
buildInputs = (with pkgs;[
# Basic
openssl
pkg-config
exa
fd
qemu
# Cross Compile
(with pkgsCross.riscv64; [ musl.stdenv.cc ]) # If use normally, no necessary need to change.
# Rust Configuraiton
rustup
cargo-binutils
rust-toolchain
]);
shellHook = ''
alias ls=exa
alias find=fd
'';
};
}
);
}
@jackyliu16
Copy link
Author

jackyliu16 commented May 26, 2023

@gjz010 would you be interested in another one?
Another rust operating system support Multiple Architectur, which flake haven't complete yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment