Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nix flakes 支持 #121

Open
jackyliu16 opened this issue May 24, 2023 · 0 comments
Open

Nix flakes 支持 #121

jackyliu16 opened this issue May 24, 2023 · 0 comments

Comments

@jackyliu16
Copy link

jackyliu16 commented May 24, 2023

目前基本完成了nix flakes的配置,可以在nix环境下直接通过nix develop打开执行环境,尽可能的降低课程依赖的安装对于外界环境的影响也可以更好的移除,可能具有更好的平台适用性,但是我没测试过

注意:使用本文的方法最好需要有一定nix的使用基础,以在可能出错的地方修改代码使之正常运行。(本文的代码尚未完全测试)

配置文件最新地址
如果在使用的过程中遇到了任何问题,欢迎回复(就是不一定我能解决

# update in 2023-05-24 21:26
{
  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, 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" ];
                });
          })
        ];
        pkgs = import nixpkgs {
          inherit system overlays;
        };
        # pkg-qemu = import nixpkgs-qemu7 { inherit system; };
      in
      {
        devShells.default = pkgs.mkShell {
          buildInputs = (with pkgs;[
            # Basic
            openssl
            pkg-config
            exa
            fd
            libclang
            # Cross Compile
            (with pkgsCross.riscv64; [ musl.stdenv.cc ]) # If use normally, no necessary need to change.
            # Rust Configuraiton  
            rustup
            cargo-binutils
            rust-toolchain
          ]) ++ [
            pkgs.qemu
            # pkg-qemu.qemu
          ];

          shellHook = ''
            alias ls=exa
            alias find=fd
          '';
        };
      }
    );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant