87 lines
2.6 KiB
Nix
87 lines
2.6 KiB
Nix
{
|
|
description = "ch32fun with devshell.";
|
|
|
|
inputs = {
|
|
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-26.05";
|
|
};
|
|
|
|
outputs = inputs@{ self, nixpkgs }:
|
|
let
|
|
pkgs = import nixpkgs {
|
|
system = "x86_64-linux";
|
|
};
|
|
riscvPkgs = import nixpkgs {
|
|
system = "x86_64-linux";
|
|
crossSystem = {
|
|
system = "riscv32-none-elf";
|
|
};
|
|
};
|
|
|
|
ch32fun = pkgs.stdenv.mkDerivation {
|
|
pname = "ch32fun";
|
|
version = "1.0rc2";
|
|
src = pkgs.fetchgit {
|
|
url = "https://github.com/cnlohr/ch32fun.git";
|
|
rev = "72957fb697fe18c875f09126858c94c2590f9ae9";
|
|
hash = "sha256-xaSlC8R3mgSaodOWiRRWkVxcdikoDdSpUN31R2guBR4=";
|
|
};
|
|
|
|
buildInputs = with pkgs; [ coreutils udev libusb1 ];
|
|
|
|
postUnpack = ''
|
|
export sourceRoot="$sourceRoot/minichlink"
|
|
'';
|
|
|
|
installPhase = ''
|
|
runHook preInstall
|
|
|
|
mkdir -p $out/{share,src}
|
|
cp -rv ../ch32fun/ $out/src/
|
|
cp -rv ../extralibs/ $out/src/
|
|
cp -rv ../misc/ $out/src/
|
|
rm $out/src/ch32fun/README.md
|
|
sed -i 's/PREFIX_DEFAULT:=riscv64-elf/PREFIX_DEFAULT:=riscv32-unknown-none-elf/' $out/src/ch32fun/ch32fun.mk
|
|
sed -i 's/MINICHLINK?=$(CH32FUN)\/..\/minichlink/MINICHLINK?=$(CH32FUN)\/..\/..\/bin/' $out/src/ch32fun/ch32fun.mk
|
|
sed -i 's/GENERATED_LD_FILE:=$(CH32FUN)\/generated_$(TARGET_MCU_PACKAGE)_$(TARGET_MCU_MEMORY_SPLIT).ld/GENERATED_LD_FILE:=.\/generated_$(TARGET_MCU_PACKAGE)_$(TARGET_MCU_MEMORY_SPLIT).ld/' $out/src/ch32fun/ch32fun.mk
|
|
sed -i 's/-flto//' $out/src/ch32fun/ch32fun.mk
|
|
|
|
mkdir -p $out/{bin,lib}
|
|
mkdir -p $out/lib/udev/rules.d
|
|
cp -v minichlink $out/bin
|
|
cp -v minichlink.so $out/lib
|
|
cp -v 99-minichlink.rules $out/lib/udev/rules.d/
|
|
|
|
mkdir -p $out/share/{doc,examples}
|
|
ls -al $out/share/doc
|
|
cp -v ../ch32fun/README.md $out/share/doc
|
|
ls -al $out/share/doc
|
|
mv $out/share/doc/README.md $out/share/doc/compability.md
|
|
ls -al $out/share/doc
|
|
cp -v ../README.md $out/share/doc/README.md
|
|
ls -al $out/share/doc
|
|
cp -rv ../examples* $out/share/examples/
|
|
ls -al $out/share/doc
|
|
|
|
runHook postInstall
|
|
'';
|
|
};
|
|
|
|
whereis-ch32fun = pkgs.writeShellScriptBin "whereis-ch32fun" ''
|
|
echo "${ch32fun}/src/ch32fun"
|
|
'';
|
|
|
|
shellProfile = riscvPkgs.mkShell {
|
|
name = "WCH ch32";
|
|
packages = [
|
|
pkgs.wlink
|
|
ch32fun
|
|
whereis-ch32fun
|
|
];
|
|
};
|
|
in
|
|
{
|
|
packages.x86_64-linux.default = ch32fun;
|
|
devShells.x86_64-linux.default = shellProfile;
|
|
};
|
|
}
|