From 3f6f81f8ab2291840a78450bdcb8e93b80e759bc Mon Sep 17 00:00:00 2001 From: Kenryu Shibata Date: Thu, 15 Oct 2026 00:52:05 +0900 Subject: [PATCH] initial commit --- flake.lock | 27 +++++++++++++++++ flake.nix | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 112 insertions(+) create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..47cfb45 --- /dev/null +++ b/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1791883866, + "narHash": "sha256-yvkDdToRZ4IgPc9tSBzzCYJvTLf8n5eE3rgUkpCuD5A=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "a033e66ab94a6bedf2c3d58d93a36319d3cbbbaf", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-26.05", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..6757e98 --- /dev/null +++ b/flake.nix @@ -0,0 +1,85 @@ +{ + 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"; + }; + riscv32Pkgs = 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 + + 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 = riscv32Pkgs.mkShell { + name = "WCH ch32"; + packages = [ + pkgs.wlink + ch32fun + whereis-ch32fun + ]; + }; + in + { + packages.x86_64-linux.default = ch32fun; + devShells.x86_64-linux.default = shellProfile; + }; +}