ysyx-workbench/npc/flake.nix

137 lines
4.3 KiB
Nix
Raw Normal View History

2023-12-23 11:26:57 +00:00
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
2024-03-13 06:53:31 +00:00
nixpkgs-circt162.url = "github:NixOS/nixpkgs/7995cae3ad60e3d6931283d650d7f43d31aaa5c7";
2023-12-23 11:26:57 +00:00
flake-utils.url = "github:numtide/flake-utils";
pre-commit-hooks = {
url = "github:cachix/pre-commit-hooks.nix";
inputs.nixpkgs.follows = "nixpkgs";
};
2024-01-05 15:50:26 +00:00
nur-xin = {
url = "git+https://git.xinyang.life/xin/nur.git";
inputs.nixpkgs.follows = "nixpkgs";
};
2023-12-23 11:26:57 +00:00
};
outputs = { self, ... }@inputs: with inputs;
flake-utils.lib.eachDefaultSystem (system:
2024-01-05 15:50:26 +00:00
let
2024-03-13 06:53:31 +00:00
pkgs = import nixpkgs { inherit system; config.allowUnfree = true; }//
2024-01-05 15:50:26 +00:00
{ nur.xin = nur-xin.legacyPackages.${system}; };
in
2023-12-23 11:26:57 +00:00
{
checks = {
pre-commit-check = pre-commit-hooks.lib.${system}.run {
src = ./.;
hooks = {
trim-trailing-whitespace.enable = true;
clang-format = {
enable = true;
types_or = pkgs.lib.mkForce [ "c" "c++" ];
};
};
};
};
2024-01-05 15:50:26 +00:00
devShells.default = with pkgs; mkShell {
inherit (self.checks.${system}.pre-commit-check) shellHook;
buildInputs = self.checks.${system}.pre-commit-check.enabledPackages;
2024-03-13 06:53:31 +00:00
CHISEL_FIRTOOL_PATH = "${nixpkgs-circt162.legacyPackages.${system}.circt}/bin";
2024-01-05 15:50:26 +00:00
packages = [
clang-tools
2024-03-29 02:35:49 +00:00
cmake
2024-03-13 06:53:31 +00:00
coursier
espresso
2024-03-29 02:35:49 +00:00
bloop
2024-01-08 10:29:28 +00:00
2024-01-05 15:50:26 +00:00
gdb
jre
2024-01-08 10:29:28 +00:00
gtkwave
2023-12-23 11:26:57 +00:00
];
2024-01-05 15:50:26 +00:00
inputsFrom = [ self.packages.${system}.default ];
};
packages.default = with pkgs; clangStdenv.mkDerivation {
name = "npc";
version = "0.0.1";
src = ./.;
nativeBuildInputs = [
cmake
sbt
nur.xin.nvboard
2024-03-13 06:53:31 +00:00
nixpkgs-circt162.legacyPackages.${system}.circt
2024-01-11 07:15:33 +00:00
yosys
cli11
];
2024-01-05 15:50:26 +00:00
buildInputs = [
verilator
nur.xin.nvboard
];
2024-01-05 15:50:26 +00:00
NEMU_HOME="/home/xin/repo/ysyx-workbench/nemu";
2023-12-23 11:26:57 +00:00
};
2024-01-05 15:50:26 +00:00
# This version (1.43.0) of circt does not exist in nixpkgs
# and Chisel 5.1.0 specifically build against it, so here we are.
# Ref: https://github.com/NixOS/nixpkgs/blob/b6465c8/pkgs/development/compilers/circt/default.nix
packages.circt =
with pkgs;
let
pythonEnv = python3.withPackages (ps: [ ps.psutil ]);
in
stdenv.mkDerivation rec {
pname = "circt";
version = "1.43.0";
src = fetchFromGitHub {
owner = "llvm";
repo = "circt";
rev = "firtool-${version}";
sha256 = "sha256-RkjigboswLkLgLkgOGahQLIygCkC3Q9rbVw3LqIzREY=";
fetchSubmodules = true;
};
requiredSystemFeatures = [ "big-parallel" ];
nativeBuildInputs = [ cmake ninja git pythonEnv ];
cmakeDir = "../llvm/llvm";
cmakeFlags = [
"-DLLVM_ENABLE_BINDINGS=OFF"
"-DLLVM_ENABLE_OCAMLDOC=OFF"
"-DLLVM_BUILD_EXAMPLES=OFF"
"-DLLVM_OPTIMIZED_TABLEGEN=ON"
"-DLLVM_ENABLE_PROJECTS=mlir"
"-DLLVM_EXTERNAL_PROJECTS=circt"
"-DLLVM_EXTERNAL_CIRCT_SOURCE_DIR=.."
"-DCIRCT_LLHD_SIM_ENABLED=OFF"
];
LIT_FILTER_OUT = if stdenv.cc.isClang then "CIRCT :: Target/ExportSystemC/.*\.mlir" else null;
preConfigure = ''
find ./test -name '*.mlir' -exec sed -i 's|/usr/bin/env|${coreutils}/bin/env|g' {} \;
'';
installPhase = ''
runHook preInstall
mkdir -p $out/bin
mv bin/{{fir,hls}tool,circt-{as,dis,lsp-server,opt,reduce,translate}} $out/bin
runHook postInstall
'';
doCheck = true;
checkTarget = "check-circt check-circt-integration";
meta = {
description = "Circuit IR compilers and tools";
homepage = "https://circt.org/";
license = lib.licenses.asl20;
maintainers = with lib.maintainers; [ sharzy ];
platforms = lib.platforms.all;
};
};
2023-12-23 11:26:57 +00:00
}
);
}
2024-01-05 15:50:26 +00:00