Compare commits

...

27 Commits

Author SHA1 Message Date
reed 60448993c5 refactor(rust): update the way the rust.srcToolchain default works and also some defaultText 2026-06-10 23:51:54 -05:00
reed 0d1a37eef3 feat: add treefmt to flake root 2026-06-07 21:58:16 -05:00
reed ba2dce4b85 style: treefmt options format fix 2026-06-07 21:55:15 -05:00
reed d40b80a910 feat: add toml and markdown formatters 2026-06-07 21:49:51 -05:00
reed 7a05bf3d5e feat(rust): add toml and markdown formatters 2026-06-07 21:38:44 -05:00
reed 81008113e3 feat(rust-esp32-c6): disable checks because they don't work with std 2026-06-04 21:28:57 -05:00
reed bc7f84a854 feat(rust): add the krantz.rust.cargoArtifacts.extraAttrs option 2026-06-04 21:28:32 -05:00
reed c95a397e58 fix(rust): fix krantz.rust.package.extraAttrs option 2026-06-04 21:28:06 -05:00
reed e6289d758b feat(rust-esp32-c6): make the rust-esp32-c6 template 2026-06-04 20:25:26 -05:00
reed d00885ced7 feat(rust): add to .gitignore 2026-06-04 20:18:34 -05:00
reed 0c581ed8b0 fix: don't error if src and srcToolchain is not defined. Just default to nixpkgs toolchain instead. 2026-06-01 16:11:50 -05:00
reed 3fefb3570a feat: add support for custom rust toolchains compatible with rustup 2026-05-31 20:16:39 -05:00
reed 30264efdb4 chore: sign commits from gitea actions 2026-05-07 22:05:23 -05:00
reed f62e56552b chore!: use https urls for private flake inputs 2026-05-07 15:16:31 -05:00
github-actions[bot] dcbc45ff0a flake.lock: Update
Flake lock file updates:

• Updated input 'crane':
    'github:ipetkov/crane/60c829383710f7e26454e6677c4d3adbc56dd3b8?narHash=sha256-WMC5ktOHtCyJL/jtlf46P%2BI4Vhw938%2BoLlSpM8gwQwU%3D' (2026-04-25)
  → 'github:ipetkov/crane/5e0fb2f64edff2822249f21293b8304dedaaf676?narHash=sha256-bEg5xoAxAwsyfnGhkEX7RJViTIBIYPd8ISg4O1c0HFc%3D' (2026-04-28)
• Updated input 'nixpkgs':
    'github:nixos/nixpkgs/0726a0ecb6d4e08f6adced58726b95db924cef57?narHash=sha256-EHq1/OX139R1RvBzOJ0aMRT3xnWyqtHBRUBuO1gFzjI%3D' (2026-04-22)
  → 'github:nixos/nixpkgs/1c3fe55ad329cbcb28471bb30f05c9827f724c76?narHash=sha256-bxrdOn8SCOv8tN4JbTF/TXq7kjo9ag4M%2BC8yzzIRYbE%3D' (2026-04-27)
2026-05-01 00:02:04 +00:00
reed 72c39db45c feat: add enable options for formatters and checks
Flake.lock: update Nix dependencies for development environment only / nix-flake-update (push) Successful in 1m54s
2026-04-28 18:52:59 -05:00
reed b4f51b4209 fix: fix the error about options not set when disabling the devShell or package options for templates 2026-04-28 18:31:06 -05:00
reed bc9f888bcf fix: fix warning about x86_64-darwin being depreciated 2026-04-28 17:12:39 -05:00
reed df51d2ffc8 fix: fix the flake producing errors on check and when trying to access the templates output 2026-04-28 17:11:37 -05:00
reed 5683d7e84c feat!(cad): rename build123d template to cad 2026-04-28 13:04:50 -05:00
reed 69f0dcbd66 fix(build123d): fix an incorrect project-templates flake input url 2026-04-27 22:31:02 -05:00
reed c7705bb8fc refactor(build123d): removed unused parameter 2026-04-27 22:30:32 -05:00
reed b28ed8c20f fix(build123d): fix pyright errors 2026-04-27 22:30:31 -05:00
reed 0bd8cd1fb8 fix(build123d): fix .envrc not getting commited because of .gitignore 2026-04-27 22:30:19 -05:00
reed 4c00d7762b feat(build123d): support multiple outputs from the builder script and replace the objectName and outputFileName with just outputName 2026-04-27 19:18:50 -05:00
reed 28b32ca0fa feat(build123d): make the first working version of the build123d template 2026-04-27 19:18:49 -05:00
reed e2f2abb1ac chore(build123d): create the build123d scafold that is not yet working 2026-04-27 19:05:10 -05:00
28 changed files with 1200 additions and 47 deletions
+5 -2
View File
@@ -14,8 +14,11 @@ jobs:
- name: "install nix" - name: "install nix"
uses: cachix/install-nix-action@v31 uses: cachix/install-nix-action@v31
- name: "setup git user" - uses: photostructure/git-ssh-signing-action@v1
uses: fregante/setup-git-user@v2 with:
ssh-signing-key: ${{ secrets.SSH_SIGNING_KEY }}
git-user-name: ${{ vars.GIT_USER_NAME }}
git-user-email: ${{ vars.GIT_USER_EMAIL }}
- name: "update flake.lock" - name: "update flake.lock"
run: | run: |
+8
View File
@@ -0,0 +1,8 @@
[global]
disable = [
# line length limits
"MD013",
]
[MD057]
absolute-links = "relative_to_roots"
+1 -1
View File
@@ -1,3 +1,3 @@
# project-templates # project-templates
Nix flake templates for initializing new projects. Nix flake templates for initializing new projects.
+165
View File
@@ -0,0 +1,165 @@
{
flake-parts-lib,
inputs,
...
}: {
flake = {
templates = {
cad = {
path = ./template;
description = "A python flake with a build132d/cadquery parametric cad setup";
};
};
flakeModules.cad = {
imports = [
inputs.treefmt-nix.flakeModule
];
options.perSystem = flake-parts-lib.mkPerSystemOption ({
lib,
config,
pkgs,
system,
...
}: let
cfg = config.krantz.cad;
cq = inputs.cadquery.packages.${system};
pyEnv = cq.python3.withPackages (p:
with p; [
cadquery
build123d
]);
outputExt = [
"step"
"stl"
"3mf"
];
in {
options.krantz.cad = {
enable = lib.mkEnableOption "executing a python build123d/cadquery file to generate 3d files";
builder = lib.mkOption {
description = "The path to python cad script that generates the 3d file(s).";
type = lib.types.path;
example = lib.literalExpression "./build3d.py";
};
outputName = lib.mkOption {
description = ''
The derivation's name that will also be used to rename the following default outputs.
${
# output.${ext} where ext is from the outputExt list
lib.concatStringsSep "\n" (lib.map (ext: "* output.${ext}") outputExt)
}
If left empty no files will be renamed.
'';
type = lib.types.str;
default = "";
example = "box_for_stuf";
};
devShell = {
enable = lib.mkEnableOption "a build123d/cadquery development environment" // {default = true;};
name = lib.mkOption {
description = "The name of the attribute in devShells to configure";
type = lib.types.str;
default = "default";
example = "cad";
};
extraAttrs = lib.mkOption {
description = "Extra attributes to merge into the devshell. See https://nixos.org/manual/nixpkgs/stable/#sec-pkgs-mkShell";
type = lib.types.attrs;
default = {};
example = {
shellHook = ''
export DEBUG=1
'';
};
};
};
package = {
enable = lib.mkEnableOption "a package output for the 3d file" // {default = true;};
name = lib.mkOption {
description = "The name of the attribute in packages to configure";
type = lib.types.str;
default = "default";
example = "3dfiles";
};
};
formatter = {
enable = lib.mkEnableOption "treefmt for formatting multiple types of files" // {default = true;};
nix = lib.mkEnableOption "formatting for nix files" // {default = true;};
};
};
config = lib.mkIf cfg.enable {
# Dev Shell that lets you enter an environment with all the necessary utilites
# Available through 'nix develop'
# Also can be activated automatically if direnv is installed on the system with 'direnv allow'
devShells = lib.mkIf cfg.devShell.enable {
${cfg.devShell.name} =
pkgs.mkShell {
packages = [
pyEnv
];
shellHook = ''
export PYTHONPATH="${pyEnv}/${pyEnv.sitePackages}:$PYTHONPATH"
'';
}
// cfg.devShell.extraAttrs;
};
# Your custom packages
# Accessible through 'nix build', 'nix shell', 'nix run', etc
packages = lib.mkIf cfg.package.enable {
${cfg.package.name} =
pkgs.runCommand cfg.outputName {}
/*
bash
*/
''
mkdir $out
cd $out
${pyEnv}/bin/python ${cfg.builder}
${
if cfg.outputName != ""
then
/*
bash
*/
''
for ext in ${lib.concatStringsSep " " outputExt}; do
if [[ -f output.$ext ]]; then
mv output.$ext ${cfg.outputName}.$ext
fi
done
''
else ""
}
'';
};
# Formatter for nix files, available through 'nix fmt'
treefmt.programs = lib.mkIf cfg.formatter.enable {
alejandra.enable = lib.mkIf cfg.formatter.nix true;
};
};
});
};
};
}
+1
View File
@@ -0,0 +1 @@
use flake
+223
View File
@@ -0,0 +1,223 @@
# Generated by nix
.direnv/
result
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[codz]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py.cover
*.lcov
.hypothesis/
.pytest_cache/
cover/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
.pybuilder/
target/
# Jupyter Notebook
.ipynb_checkpoints
# IPython
profile_default/
ipython_config.py
# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version
# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
# Pipfile.lock
# UV
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# uv.lock
# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
# poetry.lock
# poetry.toml
# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
# pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
# https://pdm-project.org/en/latest/usage/project/#working-with-version-control
# pdm.lock
# pdm.toml
.pdm-python
.pdm-build/
# pixi
# Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
# pixi.lock
# Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
# in the .venv directory. It is recommended not to include this directory in version control.
.pixi/*
!.pixi/config.toml
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/
# Celery stuff
celerybeat-schedule*
celerybeat.pid
# Redis
*.rdb
*.aof
*.pid
# RabbitMQ
mnesia/
rabbitmq/
rabbitmq-data/
# ActiveMQ
activemq-data/
# SageMath parsed files
*.sage.py
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# Pyre type checker
.pyre/
# pytype static type analyzer
.pytype/
# Cython debug symbols
cython_debug/
# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
# .idea/
# Abstra
# Abstra is an AI-powered process automation framework.
# Ignore directories containing user credentials, local state, and settings.
# Learn more at https://abstra.io/docs
.abstra/
# Visual Studio Code
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
# that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
# and can be added to the global gitignore or merged into this file. However, if you prefer,
# you could uncomment the following to ignore the entire vscode folder
# .vscode/
# Temporary file for partial code execution
tempCodeRunnerFile.py
# Ruff stuff:
.ruff_cache/
# PyPI configuration file
.pypirc
# Marimo
marimo/_static/
marimo/_lsp/
__marimo__/
# Streamlit
.streamlit/secrets.toml
+10
View File
@@ -0,0 +1,10 @@
# pyright: reportUnusedCallResult=false, reportWildcardImportFromLibrary=false
from build123d import *
length, width, thickness = 80.0, 60.0, 10.0
with BuildPart() as builder:
Box(length, width, thickness)
assert builder.part is not None
export_step(builder.part, "output.step")
+37
View File
@@ -0,0 +1,37 @@
{
description = "made with build123d/cadquery";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
project-templates = {
url = "git+https://git.krantz.one/reed/project-templates";
inputs.nixpkgs.follows = "nixpkgs";
inputs.flake-parts.follows = "flake-parts";
};
};
outputs = {
flake-parts,
project-templates,
...
} @ inputs:
flake-parts.lib.mkFlake {inherit inputs;} {
imports = [
project-templates.flakeModules.cad
];
systems = ["aarch64-linux" "x86_64-linux" "aarch64-darwin"];
perSystem = {pkgs, ...}: {
krantz.cad = {
enable = true;
builder = ./build.py;
outputName = "box";
};
};
};
}
Generated
+240 -11
View File
@@ -1,12 +1,105 @@
{ {
"nodes": { "nodes": {
"cadquery": {
"inputs": {
"cadquery-freecad-import-plugin-src": "cadquery-freecad-import-plugin-src",
"cadquery-src": "cadquery-src",
"cq-cli-src": "cq-cli-src",
"cq-editor-src": "cq-editor-src",
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs",
"ocp-src": "ocp-src",
"ocp-stubs-src": "ocp-stubs-src",
"pybind11-stubgen-src": "pybind11-stubgen-src",
"pywrap-src": "pywrap-src"
},
"locked": {
"lastModified": 1765891741,
"narHash": "sha256-71CHh2FMmmBlduyAw8LD+PLjLlm+k5wtBatF8F7aJpQ=",
"owner": "vinszent",
"repo": "cq-flake",
"rev": "6212f4f8155d03bb7ddd811d766fbcd23a8b338b",
"type": "github"
},
"original": {
"owner": "vinszent",
"repo": "cq-flake",
"type": "github"
}
},
"cadquery-freecad-import-plugin-src": {
"flake": false,
"locked": {
"lastModified": 1734615666,
"narHash": "sha256-/puHlsdDqdVbVdxOkkwMEW/S//BztFA8fNkTp9PbSYY=",
"owner": "jmwright",
"repo": "cadquery-freecad-import-plugin",
"rev": "a0f72aedafc80e40b486d991f8659ed4ce5eb147",
"type": "github"
},
"original": {
"owner": "jmwright",
"repo": "cadquery-freecad-import-plugin",
"type": "github"
}
},
"cadquery-src": {
"flake": false,
"locked": {
"lastModified": 1741533881,
"narHash": "sha256-LNzo356Chh52Soi91i/z5fD9mDlh3P0saUieS5f399g=",
"owner": "CadQuery",
"repo": "cadquery",
"rev": "471ab6fcc79b6ce64b857d33d06202c030cf5459",
"type": "github"
},
"original": {
"owner": "CadQuery",
"repo": "cadquery",
"rev": "471ab6fcc79b6ce64b857d33d06202c030cf5459",
"type": "github"
}
},
"cq-cli-src": {
"flake": false,
"locked": {
"lastModified": 1742395288,
"narHash": "sha256-aiLjhyQLeXy4kDW9C8n5XL2BqKGixufTgVKOPWiTZ9c=",
"owner": "CadQuery",
"repo": "cq-cli",
"rev": "6a6076a1659fe3cfd706cb353725e5cf3f4b4715",
"type": "github"
},
"original": {
"owner": "CadQuery",
"repo": "cq-cli",
"type": "github"
}
},
"cq-editor-src": {
"flake": false,
"locked": {
"lastModified": 1739812831,
"narHash": "sha256-6cFVT+HIRoht1XPY+mvk9iTQ50Q8kqx9XxgNsRMFQ9c=",
"owner": "CadQuery",
"repo": "CQ-editor",
"rev": "7c92ec9d967f0f1e295a0f2dcf779ea871338e08",
"type": "github"
},
"original": {
"owner": "CadQuery",
"ref": "0.4.0",
"repo": "CQ-editor",
"type": "github"
}
},
"crane": { "crane": {
"locked": { "locked": {
"lastModified": 1777149905, "lastModified": 1777335812,
"narHash": "sha256-WMC5ktOHtCyJL/jtlf46P+I4Vhw938+oLlSpM8gwQwU=", "narHash": "sha256-bEg5xoAxAwsyfnGhkEX7RJViTIBIYPd8ISg4O1c0HFc=",
"owner": "ipetkov", "owner": "ipetkov",
"repo": "crane", "repo": "crane",
"rev": "60c829383710f7e26454e6677c4d3adbc56dd3b8", "rev": "5e0fb2f64edff2822249f21293b8304dedaaf676",
"type": "github" "type": "github"
}, },
"original": { "original": {
@@ -33,17 +126,35 @@
"type": "github" "type": "github"
} }
}, },
"nixpkgs": { "flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": { "locked": {
"lastModified": 1776877367, "lastModified": 1731533236,
"narHash": "sha256-EHq1/OX139R1RvBzOJ0aMRT3xnWyqtHBRUBuO1gFzjI=", "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
"owner": "nixos", "owner": "numtide",
"repo": "nixpkgs", "repo": "flake-utils",
"rev": "0726a0ecb6d4e08f6adced58726b95db924cef57", "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
"type": "github" "type": "github"
}, },
"original": { "original": {
"owner": "nixos", "owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1742889210,
"narHash": "sha256-hw63HnwnqU3ZQfsMclLhMvOezpM7RSB0dMAtD5/sOiw=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "698214a32beb4f4c8e3942372c694f40848b360d",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-unstable", "ref": "nixos-unstable",
"repo": "nixpkgs", "repo": "nixpkgs",
"type": "github" "type": "github"
@@ -64,14 +175,132 @@
"type": "github" "type": "github"
} }
}, },
"nixpkgs_2": {
"locked": {
"lastModified": 1777268161,
"narHash": "sha256-bxrdOn8SCOv8tN4JbTF/TXq7kjo9ag4M+C8yzzIRYbE=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "1c3fe55ad329cbcb28471bb30f05c9827f724c76",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"ocp-src": {
"flake": false,
"locked": {
"lastModified": 1739132137,
"narHash": "sha256-vWAqCGgs7YnwHRhPAXkBQqCs+Y3zk4BMu1boZo3PLGA=",
"owner": "cadquery",
"repo": "ocp",
"rev": "01055e099a3b1a34da38bb1f5457f06a2d4c7a18",
"type": "github"
},
"original": {
"owner": "cadquery",
"ref": "7.8.1.2",
"repo": "ocp",
"type": "github"
}
},
"ocp-stubs-src": {
"flake": false,
"locked": {
"lastModified": 1672527176,
"narHash": "sha256-m9Rg36GYlYfwEfF0PQJWEXf8TyM5HmjeuhJCODiurvY=",
"owner": "cadquery",
"repo": "ocp-stubs",
"rev": "e838ff400d5ee2f4a0579d2a713b19311855288f",
"type": "github"
},
"original": {
"owner": "cadquery",
"repo": "ocp-stubs",
"type": "github"
}
},
"pybind11-stubgen-src": {
"flake": false,
"locked": {
"lastModified": 1700678104,
"narHash": "sha256-76u1GcHPPh8oYQeQZDJ4K/so0U7F6rznZ1xa6syqI9s=",
"owner": "CadQuery",
"repo": "pybind11-stubgen",
"rev": "6dc681d838d3ec9a8a9aa4260c8392d3fb700ff0",
"type": "github"
},
"original": {
"owner": "CadQuery",
"repo": "pybind11-stubgen",
"type": "github"
}
},
"pywrap-src": {
"flake": false,
"locked": {
"lastModified": 1736233855,
"narHash": "sha256-u+P/SUGpYhzA1oVbEv26DF8PBEpsotEk4iXIXZhgzHc=",
"owner": "CadQuery",
"repo": "pywrap",
"rev": "9c9ca5b8aa0d9a6687394897815a682b8c319fb0",
"type": "github"
},
"original": {
"owner": "CadQuery",
"repo": "pywrap",
"type": "github"
}
},
"root": { "root": {
"inputs": { "inputs": {
"cadquery": "cadquery",
"crane": "crane", "crane": "crane",
"flake-parts": "flake-parts", "flake-parts": "flake-parts",
"nixpkgs": "nixpkgs", "nixpkgs": "nixpkgs_2",
"rust-overlay": "rust-overlay",
"treefmt-nix": "treefmt-nix" "treefmt-nix": "treefmt-nix"
} }
}, },
"rust-overlay": {
"inputs": {
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1780197589,
"narHash": "sha256-FVCr2Ij/jKf59a4LW481eeOF6rJRreOBrVgW/aUBTrw=",
"owner": "oxalica",
"repo": "rust-overlay",
"rev": "21632e942d89bf1cce4e5a63d7e58a215a0cbfcc",
"type": "github"
},
"original": {
"owner": "oxalica",
"repo": "rust-overlay",
"type": "github"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
},
"treefmt-nix": { "treefmt-nix": {
"inputs": { "inputs": {
"nixpkgs": [ "nixpkgs": [
+46 -3
View File
@@ -12,16 +12,59 @@
}; };
crane.url = "github:ipetkov/crane"; crane.url = "github:ipetkov/crane";
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
cadquery = {
url = "github:vinszent/cq-flake";
# unfortunately dependencies are out of date so this needs it's own nixpkgs
# inputs.nixpkgs.follows = "nixpkgs";
};
}; };
outputs = {flake-parts, ...} @ inputs: outputs = {
self,
flake-parts,
...
} @ inputs:
flake-parts.lib.mkFlake {inherit inputs;} { flake-parts.lib.mkFlake {inherit inputs;} {
imports = [ imports = [
./cad
./rust ./rust
./rust-esp32-c6
inputs.treefmt-nix.flakeModule
flake-parts.flakeModules.flakeModules
# define the flake.templates option
({lib, ...}: {
options.flake.templates = lib.mkOption {
type = lib.types.lazyAttrsOf (lib.types.submodule {
options = {
path = lib.mkOption {type = lib.types.path;};
description = lib.mkOption {type = lib.types.str;};
};
});
default = {};
};
})
]; ];
systems = ["aarch64-linux" "x86_64-linux" "aarch64-darwin" "x86_64-darwin"]; flake.flakeModule = {
imports = builtins.attrValues (builtins.removeAttrs self.flakeModules ["default"]);
};
perSystem = {pkgs, ...}: {formatter = pkgs.alejandra;}; systems = ["aarch64-linux" "x86_64-linux" "aarch64-darwin"];
perSystem = {pkgs, ...}: {
treefmt.programs = {
alejandra.enable = true; # nix
taplo.enable = true; # toml
rumdl-check.enable = true; # markdown
rumdl-format.enable = true; # markdown
};
};
}; };
} }
+52
View File
@@ -0,0 +1,52 @@
{
flake-parts-lib,
inputs,
self,
...
}: {
flake = {
templates = {
rust-esp32-c6 = {
path = ./template;
description = "ESP32-C6 RISC-V rust project with a blink led example";
};
};
flakeModules.rust-esp32-c6 = {
imports = [
inputs.treefmt-nix.flakeModule
self.outputs.flakeModules.rust
];
options.perSystem = flake-parts-lib.mkPerSystemOption ({
lib,
config,
pkgs,
self',
...
}: let
cfg = config.krantz.rust.esp32-c6;
craneLib = config.krantz.rust.craneLib;
in {
options.krantz.rust.esp32-c6 = {
enable = lib.mkEnableOption "additional tooling for the esp32 RISC-V";
};
config = lib.mkIf cfg.enable {
krantz.rust.devDeps = lib.mkOptionDefault (with pkgs; [
espflash
]);
krantz.rust.cargoArtifacts.extraAttrs = lib.mkOptionDefault {
doCheck = false;
};
krantz.rust.package.extraAttrs = lib.mkOptionDefault {
doCheck = false;
};
};
});
};
};
}
+18
View File
@@ -0,0 +1,18 @@
[target.riscv32imac-unknown-none-elf]
runner = "espflash flash --monitor --chip esp32c6 --log-format defmt"
[env]
DEFMT_LOG = "info"
[build]
rustflags = [
# Required to obtain backtraces (e.g. when using the "esp-backtrace" crate.)
# NOTE: May negatively impact performance of produced code
"-C",
"force-frame-pointers",
]
target = "riscv32imac-unknown-none-elf"
[unstable]
build-std = ["alloc", "core"]
+1
View File
@@ -0,0 +1 @@
stack-size-threshold = 1024
+1
View File
@@ -0,0 +1 @@
use flake
@@ -0,0 +1,30 @@
name: "Flake.lock: update Nix dependencies for development environment only"
on:
workflow_dispatch: # allows manual triggering
schedule:
- cron: '00 00 02 1/2 *' # runs the first of day the month every 2 months at 7:00pm local time (midnight UTC)
jobs:
nix-flake-update:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: "install nix"
uses: cachix/install-nix-action@v31
- name: "setup git user"
uses: fregante/setup-git-user@v2
- name: "update flake.lock"
run: |
nix flake update --commit-lock-file
- name: "check flake for errors"
run: |
nix flake check
- name: "push update"
run: |
git push
+23
View File
@@ -0,0 +1,23 @@
# Generated by nix
.direnv/
result
# Generated by Cargo
# will have compiled files and executables
debug/
target/
# Editor configuration
.vscode/
.zed/
.helix/
.nvim.lua
# These are backup files generated by rustfmt
**/*.rs.bk
# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb
# Ignore .DS_Store file in mac
**/.DS_Store
+8
View File
@@ -0,0 +1,8 @@
[global]
disable = [
# line length limits
"MD013",
]
[MD057]
absolute-links = "relative_to_roots"
+48
View File
@@ -0,0 +1,48 @@
[package]
edition = "2024"
name = "rust-esp32-c6"
rust-version = "1.88"
version = "0.1.0"
[[bin]]
name = "rust-esp32-c6"
path = "./src/bin/main.rs"
[dependencies]
esp-hal = { version = "~1.1.0", features = ["defmt", "esp32c6", "unstable"] }
esp-rtos = { version = "0.3.0", features = [
"defmt",
"embassy",
"esp-alloc",
"esp32c6",
] }
defmt = "1.0.1"
esp-bootloader-esp-idf = { version = "0.5.0", features = ["defmt", "esp32c6"] }
embassy-executor = { version = "0.10.0", features = ["defmt"] }
embassy-time = { version = "0.5.0", features = ["defmt"] }
esp-alloc = { version = "0.10.0", features = ["defmt"] }
esp-backtrace = { version = "0.19.0", features = [
"defmt",
"esp32c6",
"panic-handler",
] }
esp-println = { version = "0.17.0", features = ["defmt-espflash", "esp32c6"] }
critical-section = "1.2.0"
static_cell = "2.1.1"
# For fine tuning these settings, please refer to https://doc.rust-lang.org/cargo/reference/profiles.html
[profile.dev]
# The default debug profile is too slow and too big for resource-constrained devices.
# Always build with some optimizations enabled.
opt-level = "s"
[profile.release]
codegen-units = 1 # LLVM can perform better optimizations using a single thread
debug = 2 # prefer slower builds but better debugging experience
lto = 'fat'
opt-level = 's'
+71
View File
@@ -0,0 +1,71 @@
fn main() {
linker_be_nice();
println!("cargo:rustc-link-arg=-Tdefmt.x");
// make sure linkall.x is the last linker script (otherwise might cause problems with flip-link)
println!("cargo:rustc-link-arg=-Tlinkall.x");
}
fn linker_be_nice() {
let args: Vec<String> = std::env::args().collect();
if args.len() > 1 {
let kind = &args[1];
let what = &args[2];
match kind.as_str() {
"undefined-symbol" => match what.as_str() {
what if what.starts_with("_defmt_") => {
eprintln!();
eprintln!(
"💡 `defmt` not found - make sure `defmt.x` is added as a linker script and you have included `use defmt_rtt as _;`"
);
eprintln!();
}
"_stack_start" => {
eprintln!();
eprintln!("💡 Is the linker script `linkall.x` missing?");
eprintln!();
}
what if what.starts_with("esp_rtos_") => {
eprintln!();
eprintln!(
"💡 `esp-radio` has no scheduler enabled. Make sure you have initialized `esp-rtos` or provided an external scheduler."
);
eprintln!();
}
"embedded_test_linker_file_not_added_to_rustflags" => {
eprintln!();
eprintln!(
"💡 `embedded-test` not found - make sure `embedded-test.x` is added as a linker script for tests"
);
eprintln!();
}
"free"
| "malloc"
| "calloc"
| "get_free_internal_heap_size"
| "malloc_internal"
| "realloc_internal"
| "calloc_internal"
| "free_internal" => {
eprintln!();
eprintln!(
"💡 Did you forget the `esp-alloc` dependency or didn't enable the `compat` feature on it?"
);
eprintln!();
}
_ => (),
},
// we don't have anything helpful for "missing-lib" yet
_ => {
std::process::exit(1);
}
}
std::process::exit(0);
}
println!(
"cargo:rustc-link-arg=--error-handling-script={}",
std::env::current_exe().unwrap().display()
);
}
+42
View File
@@ -0,0 +1,42 @@
{
description = "esp32 tool";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
project-templates = {
url = "git+https://git.krantz.one/reed/project-templates";
inputs.nixpkgs.follows = "nixpkgs";
inputs.flake-parts.follows = "flake-parts";
};
};
outputs = {
flake-parts,
project-templates,
...
} @ inputs:
flake-parts.lib.mkFlake {inherit inputs;} {
imports = [
project-templates.flakeModules.rust-esp32-c6
];
systems = ["aarch64-linux" "x86_64-linux" "aarch64-darwin"];
perSystem = {pkgs, ...}: {
krantz.rust = {
esp32-c6 = {
enable = true;
};
enable = true;
src = ./.;
# runtimeDeps = with pkgs; [];
# buildDeps = with pkgs; [];
};
};
};
}
@@ -0,0 +1,4 @@
[toolchain]
channel = "stable"
components = ["rust-src"]
targets = ["riscv32imac-unknown-none-elf"]
+54
View File
@@ -0,0 +1,54 @@
#![no_std]
#![no_main]
#![deny(
clippy::mem_forget,
reason = "mem::forget is generally not safe to do with esp_hal types, especially those \
holding buffers for the duration of a data transfer."
)]
#![deny(clippy::large_stack_frames)]
use defmt::info;
use embassy_executor::Spawner;
use embassy_time::{Duration, Timer};
use esp_backtrace as _;
use esp_hal::clock::CpuClock;
use esp_hal::timer::timg::TimerGroup;
use esp_println as _;
extern crate alloc;
// This creates a default app-descriptor required by the esp-idf bootloader.
// For more information see: <https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-reference/system/app_image_format.html#application-description>
esp_bootloader_esp_idf::esp_app_desc!();
#[allow(
clippy::large_stack_frames,
reason = "it's not unusual to allocate larger buffers etc. in main"
)]
#[esp_rtos::main]
async fn main(spawner: Spawner) -> ! {
// generator version: 1.3.0
// generator parameters: --chip esp32c6 -o alloc -o unstable-hal -o esp-backtrace -o embassy -o defmt
let config = esp_hal::Config::default().with_cpu_clock(CpuClock::max());
let peripherals = esp_hal::init(config);
esp_alloc::heap_allocator!(#[esp_hal::ram(reclaimed)] size: 65536);
let timg0 = TimerGroup::new(peripherals.TIMG0);
let sw_interrupt =
esp_hal::interrupt::software::SoftwareInterruptControl::new(peripherals.SW_INTERRUPT);
esp_rtos::start(timg0.timer0, sw_interrupt.software_interrupt0);
info!("Embassy initialized!");
// TODO: Spawn some tasks
let _ = spawner;
loop {
info!("Hello world!");
Timer::after(Duration::from_secs(1)).await;
}
// for inspiration have a look at the examples at https://github.com/esp-rs/esp-hal/tree/esp-hal-v1.1.0/examples
}
+1
View File
@@ -0,0 +1 @@
#![no_std]
+90 -28
View File
@@ -25,10 +25,17 @@
}: let }: let
cfg = config.krantz.rust; cfg = config.krantz.rust;
craneLib = inputs.crane.mkLib pkgs;
src = cfg.srcFiltered; src = cfg.srcFiltered;
manifest = (lib.importTOML "${src}/Cargo.toml").package; manifest = (lib.importTOML "${src}/Cargo.toml").package;
craneLib =
if cfg.srcToolchain != null && builtins.pathExists cfg.srcToolchain
then
(inputs.crane.mkLib (pkgs.extend inputs.rust-overlay.overlays.default)).overrideToolchain (
p: p.rust-bin.fromRustupToolchainFile cfg.srcToolchain
)
else inputs.crane.mkLib pkgs;
buildInputs = cfg.runtimeDeps; buildInputs = cfg.runtimeDeps;
# build dependencies # build dependencies
@@ -36,25 +43,46 @@
# Build *just* the cargo dependencies, so we can reuse # Build *just* the cargo dependencies, so we can reuse
# all of that work (e.g. via cachix) when running in CI # all of that work (e.g. via cachix) when running in CI
cargoArtifacts = craneLib.buildDepsOnly { cargoArtifacts = craneLib.buildDepsOnly ({
inherit src buildInputs nativeBuildInputs; inherit src buildInputs nativeBuildInputs;
}; }
// cfg.cargoArtifacts.extraAttrs);
in { in {
options.krantz.rust = { options.krantz.rust = {
enable = lib.mkEnableOption "building a cargo project with crane"; enable = lib.mkEnableOption "building a cargo project with crane";
src = lib.mkOption { src = lib.mkOption {
description = "The path to the root of the crate."; description = "The path to the root of the crate.";
type = lib.types.path; type = lib.types.nullOr lib.types.path;
default = null;
example = lib.literalExpression "./."; example = lib.literalExpression "./.";
}; };
srcFiltered = lib.mkOption { srcFiltered = lib.mkOption {
description = "A path to the filtered directory of the root of the crate."; description = "A path to the filtered directory of the root of the crate.";
type = lib.types.path; type = lib.types.path;
default = craneLib.cleanCargoSource cfg.src; default = craneLib.cleanCargoSource cfg.src;
defaultText = lib.literalExpression "config.krantz.rust.craneLib cfg.src"; defaultText = lib.literalExpression "config.krantz.rust.craneLib.cleanCargoSource cfg.src";
example = lib.literalExpression "./."; example = lib.literalExpression "./.";
}; };
srcToolchain = lib.mkOption {
description = "A path to the rust-toolchain(.toml) file for the repo. Will use the toolchain from nixpkgs if the file does not exist.";
type = lib.types.nullOr lib.types.path;
default =
if cfg.src != null
then cfg.src + "/rust-toolchain.toml"
else null;
defaultText =
lib.literalExpression
/*
nix
*/
''
if cfg.src != null
then cfg.src + "/rust-toolchain.toml"
else null;
'';
example = lib.literalExpression "./rust-toolchain";
};
runtimeDeps = lib.mkOption { runtimeDeps = lib.mkOption {
description = "Packages needed for the app to run."; description = "Packages needed for the app to run.";
@@ -81,6 +109,17 @@
]; ];
}; };
cargoArtifacts = {
extraAttrs = lib.mkOption {
description = "Extra attributes to merge into buildDepsOnly. See https://crane.dev/API.html#cranelibbuilddepsonly";
type = lib.types.attrs;
default = {};
example = {
doCheck = false;
};
};
};
devShell = { devShell = {
enable = lib.mkEnableOption "a rust development environment" // {default = true;}; enable = lib.mkEnableOption "a rust development environment" // {default = true;};
@@ -123,6 +162,21 @@
}; };
}; };
formatter = {
enable = lib.mkEnableOption "treefmt for formatting multiple types of files" // {default = true;};
nix = lib.mkEnableOption "formatting for nix files" // {default = true;};
rust = lib.mkEnableOption "formatting for rust files" // {default = true;};
toml = lib.mkEnableOption "formatting for toml files" // {default = true;};
markdown = lib.mkEnableOption "formatting for toml files" // {default = true;};
};
checks = {
enable = lib.mkEnableOption "checks for rust" // {default = true;};
linter = lib.mkEnableOption "lints for rust" // {default = true;};
};
craneLib = lib.mkOption { craneLib = lib.mkOption {
description = "The crane lib instance this module is using. Useful for overriding options"; description = "The crane lib instance this module is using. Useful for overriding options";
default = craneLib; default = craneLib;
@@ -135,37 +189,45 @@
# Dev Shell that lets you enter an environment with all the necessary utilites # Dev Shell that lets you enter an environment with all the necessary utilites
# Available through 'nix develop' # Available through 'nix develop'
# Also can be activated automatically if direnv is installed on the system with 'direnv allow' # Also can be activated automatically if direnv is installed on the system with 'direnv allow'
devShells.${cfg.devShell.name} = lib.mkIf cfg.devShell.enable (craneLib.devShell { devShells = lib.mkIf cfg.devShell.enable {
inherit (self') checks; ${cfg.devShell.name} =
craneLib.devShell {
inherit (self') checks;
# extra tooling dependencies # extra tooling dependencies
packages = cfg.devDeps; packages = cfg.devDeps;
inputsFrom = [self'.packages.${cfg.package.name}]; inputsFrom = [self'.packages.${cfg.package.name}];
} }
// cfg.devShell.extraAttrs); // cfg.devShell.extraAttrs;
# Formatter for nix files, available through 'nix fmt'
treefmt = {
programs.alejandra.enable = lib.mkDefault true;
programs.rustfmt = {
enable = true;
edition = manifest.edition;
};
}; };
# Your custom packages # Your custom packages
# Accessible through 'nix build', 'nix shell', 'nix run', etc # Accessible through 'nix build', 'nix shell', 'nix run', etc
packages.${cfg.package.name} = lib.mkIf cfg.package.enable (craneLib.buildPackage { packages = lib.mkIf cfg.package.enable {
inherit src buildInputs nativeBuildInputs cargoArtifacts; ${cfg.package.name} = craneLib.buildPackage ({
} inherit src buildInputs nativeBuildInputs cargoArtifacts;
// cfg.package.extraAttrs); }
// cfg.package.extraAttrs);
};
checks = { # Formatter for nix files, available through 'nix fmt'
clippy = craneLib.cargoClippy { treefmt.programs = lib.mkIf cfg.formatter.enable {
alejandra.enable = lib.mkIf cfg.formatter.nix true;
rustfmt = lib.mkIf cfg.formatter.rust {
enable = true;
edition = manifest.edition;
};
taplo.enable = lib.mkIf cfg.formatter.toml true;
rumdl-check.enable = lib.mkIf cfg.formatter.markdown true;
rumdl-format.enable = lib.mkIf cfg.formatter.markdown true;
};
checks = lib.mkIf cfg.checks.enable {
clippy = lib.mkIf cfg.checks.linter (craneLib.cargoClippy {
inherit src buildInputs nativeBuildInputs cargoArtifacts; inherit src buildInputs nativeBuildInputs cargoArtifacts;
cargoClippyExtraArgs = "-- --deny warnings"; cargoClippyExtraArgs = "-- --deny warnings";
}; });
}; };
}; };
}); });
+12
View File
@@ -7,5 +7,17 @@ result
debug/ debug/
target/ target/
# Editor configuration
.vscode/
.zed/
.helix/
.nvim.lua
# These are backup files generated by rustfmt # These are backup files generated by rustfmt
**/*.rs.bk **/*.rs.bk
# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb
# Ignore .DS_Store file in mac
**/.DS_Store
+8
View File
@@ -0,0 +1,8 @@
[global]
disable = [
# line length limits
"MD013",
]
[MD057]
absolute-links = "relative_to_roots"
-1
View File
@@ -15,4 +15,3 @@ tracing-subscriber = "*"
clap = { version = "*", features = ["derive"] } clap = { version = "*", features = ["derive"] }
figment = { version = "*", features = ["toml", "env", "json"] } figment = { version = "*", features = ["toml", "env", "json"] }
+1 -1
View File
@@ -7,7 +7,7 @@
flake-parts.url = "github:hercules-ci/flake-parts"; flake-parts.url = "github:hercules-ci/flake-parts";
project-templates = { project-templates = {
url = "git+ssh://gitea@git.krantz.one/reed/project-templates"; url = "git+https://git.krantz.one/reed/project-templates";
inputs.nixpkgs.follows = "nixpkgs"; inputs.nixpkgs.follows = "nixpkgs";
inputs.flake-parts.follows = "flake-parts"; inputs.flake-parts.follows = "flake-parts";
}; };