Compare commits

...

3 Commits

6 changed files with 644 additions and 8 deletions
+150
View File
@@ -0,0 +1,150 @@
{
flake-parts-lib,
inputs,
...
}: {
flake = {
templates = {
build123d = {
path = ./template;
description = "A python flake with a build132d/cadquery parametric cad setup";
};
};
flakeModules.build123d = {
imports = [
inputs.treefmt-nix.flakeModule
];
options.perSystem = flake-parts-lib.mkPerSystemOption ({
lib,
config,
pkgs,
self',
system,
...
}: let
cfg = config.krantz.build123d;
cq = inputs.cadquery.packages.${system};
pyEnv = cq.python3.withPackages (p:
with p; [
cadquery
build123d
]);
outputExt = [
"step"
"stl"
"3mf"
];
in {
options.krantz.build123d = {
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 development environment" // {default = true;};
name = lib.mkOption {
description = "The name of the attribute in devShells to configure";
type = lib.types.str;
default = "default";
example = "build123d";
};
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";
};
};
};
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.${cfg.devShell.name} = lib.mkIf cfg.devShell.enable (pkgs.mkShell {
packages = [
pyEnv
];
}
// cfg.devShell.extraAttrs);
# Formatter for nix files, available through 'nix fmt'
treefmt = {
programs.alejandra.enable = lib.mkDefault true;
};
# Your custom packages
# Accessible through 'nix build', 'nix shell', 'nix run', etc
packages.${cfg.package.name} = lib.mkIf cfg.package.enable (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 ""
}
'');
};
});
};
};
}
+224
View File
@@ -0,0 +1,224 @@
# 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
.envrc
.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
+8
View File
@@ -0,0 +1,8 @@
from build123d import * # pyright: ignore[reportWildcardImportFromLibrary]
length, width, thickness = 80.0, 60.0, 10.0
with BuildPart() as builder:
Box(length, width, thickness)
export_step(builder.part, "output.step")
+37
View File
@@ -0,0 +1,37 @@
{
description = "made with build123d";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
project-templates = {
url = "path:///home/reed/code/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.build123d
];
systems = ["aarch64-linux" "x86_64-linux" "aarch64-darwin"];
perSystem = {pkgs, ...}: {
krantz.build123d = {
enable = true;
builder = ./build3d.py;
outputName = "box";
};
};
};
}
Generated
+216 -8
View File
@@ -1,5 +1,98 @@
{
"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": {
"locked": {
"lastModified": 1777149905,
@@ -33,17 +126,35 @@
"type": "github"
}
},
"nixpkgs": {
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1776877367,
"narHash": "sha256-EHq1/OX139R1RvBzOJ0aMRT3xnWyqtHBRUBuO1gFzjI=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "0726a0ecb6d4e08f6adced58726b95db924cef57",
"lastModified": 1731533236,
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
"type": "github"
},
"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",
"repo": "nixpkgs",
"type": "github"
@@ -64,14 +175,111 @@
"type": "github"
}
},
"nixpkgs_2": {
"locked": {
"lastModified": 1776877367,
"narHash": "sha256-EHq1/OX139R1RvBzOJ0aMRT3xnWyqtHBRUBuO1gFzjI=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "0726a0ecb6d4e08f6adced58726b95db924cef57",
"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": {
"inputs": {
"cadquery": "cadquery",
"crane": "crane",
"flake-parts": "flake-parts",
"nixpkgs": "nixpkgs",
"nixpkgs": "nixpkgs_2",
"treefmt-nix": "treefmt-nix"
}
},
"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": {
"inputs": {
"nixpkgs": [
+9
View File
@@ -12,11 +12,20 @@
};
crane.url = "github:ipetkov/crane";
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:
flake-parts.lib.mkFlake {inherit inputs;} {
imports = [
flake-parts.flakeModules.flakeModules
./build123d
./rust
];