Skip to content

Nix flake and overlay for WCH (for now only ch58x) development.

License

Notifications You must be signed in to change notification settings

azazak123/nixpkgs-wch-dev

Repository files navigation

nixpkgs-wch-dev

Nix flake and overlay for developing for WCH MCUs.

This tool is a work in progress.

General

This flake provides packages and tools to make development for WCH MCUs easier. Moreover, it consists of Nix functions to make package and shell creation more convenient.

Package building

To create a package, one can use the mkWCHProject Nix function. It has the following parameters:

  • pname - package name
  • version - package version
  • src - path to the source code
  • mcu - MCU's name (e.g. ch58x)
  • toolchain - one of the toolchain packages
  • debug - whether to enable debug build or not (default: true)

Shell Creation

Additionally, one can use mkWCHShell Nix function to create a shell. Its parameters are:

  • name - shell name
  • mcu - MCU's name (e.g., "ch58x")
  • toolchain - one of toolchain packages

Provided Packages and Shells

Shells:

  • ch58x

Tools:

Supported toolchains:

Examples

To enter a simple predefined shell:

nix develop github:azazak123/nixpkgs-wch-dev#ch58x

Package definition:

packages.example = pkgs.mkWCHProject {
  pname = "example";
  version = "1";
  src = ./.;
  debug = false;
  mcu = "ch58x";
};

Example of a simple flake.nix file:

{
  inputs = {
    nixpkgs.url = "nixpkgs/nixpkgs-unstable";
    nixpkgs-wch-dev.url = "github:azazak123/nixpkgs-wch-dev";
  };

  outputs =
    { self, nixpkgs, nixpkgs-wch-dev }:
    let
      pkgs = nixpkgs.legacyPackages.x86_64-linux.extend (nixpkgs-wch-dev.overlays.default);
    in
    {
      packages.x86_64-linux.default = pkgs.mkWCHProject {
        pname = "example";
        version = "0.1";
        src = ./.;
        debug = false;
        mcu = "ch58x";
      };

      devShells.x86_64-linux = {
        default = nixpkgs-wch-dev.devShells.x86_64-linux.ch58x;
      };
    };
}

A more complicated example can be found in the examples folder. It has a blink program that includes a simple project structure example with a source folder, flake.nix, and CMakeLists.txt.

Supported MCUs

For now, I only have ch58x unfortunately. As my collection grows, I will add new MCUs.

  • ch58x

Related projects

Here are some projects that I used and took inspiration from. Many thanks to their developers!

Contribution

Contributions to nixpkgs-wch-dev are welcome! Whether you are fixing a bug, adding new features, improving documentation, or providing feedback, your input helps improve this project!

About

Nix flake and overlay for WCH (for now only ch58x) development.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published