feat(build123d): make the first working version of the build123d template

This commit is contained in:
2026-04-27 17:26:14 -05:00
parent e2f2abb1ac
commit 28b32ca0fa
11 changed files with 310 additions and 358 deletions
+76 -117
View File
@@ -7,7 +7,7 @@
templates = { templates = {
build123d = { build123d = {
path = ./template; path = ./template;
description = "A python flake with a build132d parametric cad setup"; description = "A python flake with a build132d/cadquery parametric cad setup";
}; };
}; };
@@ -21,133 +21,83 @@
config, config,
pkgs, pkgs,
self', self',
system,
... ...
}: let }: let
cfg = config.krantz.build123d; cfg = config.krantz.build123d;
python = pkgs.python3.override { cq = inputs.cadquery.packages.${system};
self = python;
packageOverrides = pyfinal: pyprev: { pyEnv = cq.python3.withPackages (p:
build123d = pyfinal.callPackage ./packages/build123d.nix {}; with p; [
cadquery-ocp = pyfinal.callPackage ./packages/cadquery-ocp.nix {}; cadquery
cadquery-ocp-proxy = pyfinal.callPackage ./packages/cadquery-ocp-proxy.nix {}; build123d
ocp-gordon = pyfinal.callPackage ./packages/ocp-gordon.nix {}; ]);
ocpsvg = pyfinal.callPackage ./packages/ocpsvg.nix {};
trianglesolver = pyfinal.callPackage ./packages/trianglesolver.nix {};
};
};
in { in {
options.krantz.build123d = { options.krantz.build123d = {
enable = lib.mkEnableOption "building a cargo project with crane"; enable = lib.mkEnableOption "executing a python build123d/cadquery file to get a 3d file";
# src = lib.mkOption { objectName = lib.mkOption {
# description = "The path to the root of the crate."; description = "What to name this object.";
# type = lib.types.path; type = lib.types.str;
# example = lib.literalExpression "./."; example = "box";
# }; };
# srcFiltered = lib.mkOption {
# description = "A path to the filtered directory of the root of the crate."; builder = lib.mkOption {
# type = lib.types.path; description = "The path to python cad script that generates the 3d file.";
# default = craneLib.cleanCargoSource cfg.src; type = lib.types.path;
# defaultText = lib.literalExpression "config.krantz.rust.craneLib cfg.src"; example = lib.literalExpression "./build3d.py";
# example = lib.literalExpression "./."; };
# }; outputFileName = lib.mkOption {
# description = "The name of the 3d file the builder script will output. After the builder is run this file must appear in the current working directory.";
# runtimeDeps = lib.mkOption { type = lib.types.str;
# description = "Packages needed for the app to run."; default = "output.step";
# type = lib.types.listOf lib.types.package; };
# default = [];
# example = with pkgs; [ devShell = {
# openssl enable = lib.mkEnableOption "a build123d development environment" // {default = true;};
# ];
# }; name = lib.mkOption {
# buildDeps = lib.mkOption { description = "The name of the attribute in devShells to configure";
# description = "Packages needed for the app to build."; type = lib.types.str;
# type = lib.types.listOf lib.types.package; default = "default";
# default = []; example = "build123d";
# example = with pkgs; [ };
# pkg-config
# rustPlatform.bindgenHook 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;
# devDeps = lib.mkOption { default = {};
# description = "Packages to include only in the devShell."; example = {
# type = lib.types.listOf lib.types.package; shellHook = ''
# default = with pkgs; [ export DEBUG=1
# rust-analyzer '';
# ]; };
# }; };
# };
# devShell = {
# enable = lib.mkEnableOption "a rust development environment" // {default = true;}; package = {
# enable = lib.mkEnableOption "a package output for the 3d file" // {default = true;};
# name = lib.mkOption {
# description = "The name of the attribute in devShells to configure"; name = lib.mkOption {
# type = lib.types.str; description = "The name of the attribute in packages to configure";
# default = "default"; type = lib.types.str;
# example = "rust"; default = "default";
# }; example = "step";
# };
# extraAttrs = lib.mkOption { };
# description = "Extra attributes to merge into the devshell. See https://crane.dev/API.html#cranelibdevshell";
# type = lib.types.attrs;
# default = {};
# example = {
# shellHook = ''
# export DEBUG=1
# '';
# };
# };
# };
#
# package = {
# enable = lib.mkEnableOption "the compiled cargo project" // {default = true;};
#
# name = lib.mkOption {
# description = "The name of the attribute in packages to configure";
# type = lib.types.str;
# default = "default";
# example = "lib";
# };
#
# extraAttrs = lib.mkOption {
# description = "Extra attributes to merge into the package. See https://crane.dev/API.html#cranelibbuildpackage";
# type = lib.types.attrs;
# default = {};
# example = {
# doCheck = false;
# };
# };
# };
#
# craneLib = lib.mkOption {
# description = "The crane lib instance this module is using. Useful for overriding options";
# default = craneLib;
# defaultText = lib.literalExpression "crane.mkLib pkgs";
# readOnly = true;
# };
}; };
config = lib.mkIf cfg.enable { config = lib.mkIf cfg.enable {
# 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 (pkgs.mkShell { devShells.${cfg.devShell.name} = lib.mkIf cfg.devShell.enable (pkgs.mkShell {
# # extra tooling dependencies
# packages = cfg.devDeps;
#
# inputsFrom = [self'.packages.${cfg.package.name}];
# }
# // cfg.devShell.extraAttrs);
devShells.default = pkgs.mkShell {
# extra tooling dependencies
packages = [ packages = [
(python.withPackages (p: pyEnv
with p; [
build123d
]))
]; ];
}; }
// cfg.devShell.extraAttrs);
# Formatter for nix files, available through 'nix fmt' # Formatter for nix files, available through 'nix fmt'
treefmt = { treefmt = {
@@ -156,10 +106,19 @@
# 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 ( { packages.${cfg.package.name} = lib.mkIf cfg.package.enable (pkgs.runCommand cfg.objectName {}
# inherit src buildInputs nativeBuildInputs cargoArtifacts; /*
# } bash
# // cfg.package.extraAttrs); */
''
RESULT_FILE_NAME=${cfg.objectName}.${lib.last (lib.splitString "." cfg.outputFileName)}
${pyEnv}/bin/python ${cfg.builder}
mkdir $out
mv ${cfg.outputFileName} $out/$RESULT_FILE_NAME
ln -s ./$RESULT_FILE_NAME $out/${cfg.outputFileName}
'');
}; };
}); });
}; };
-59
View File
@@ -1,59 +0,0 @@
{
lib,
buildPythonPackage,
fetchPypi,
setuptools,
setuptools-scm,
wheel,
# runtime deps
cadquery-ocp,
numpy,
svgpathtools,
anytree,
ezdxf,
ipython,
lib3mf,
ocpsvg,
ocp-gordon,
trianglesolver,
sympy,
scipy,
webcolors,
}:
buildPythonPackage
rec {
pname = "build123d";
version = "0.10.0";
src = fetchPypi {
inherit pname version;
hash = "sha256-c97Tjdyo67lefdB4rD16rMjKQvzo8dF28QQONfuk9gg=";
};
# do not run tests
doCheck = false;
buildInputs = [
cadquery-ocp
numpy
svgpathtools
anytree
ezdxf
ipython
lib3mf
ocpsvg
ocp-gordon
trianglesolver
sympy
scipy
webcolors
];
# specific to buildPythonPackage, see its reference
pyproject = true;
build-system = [
setuptools
setuptools-scm
wheel
];
}
-33
View File
@@ -1,33 +0,0 @@
{
lib,
buildPythonPackage,
fetchPypi,
setuptools,
setuptools-scm,
wheel,
# runtime deps
}:
buildPythonPackage
rec {
pname = "cadquery-ocp-proxy";
version = "7.9.3.1";
src = fetchPypi {
inherit pname version;
hash = "sha256-c97Tjdyo67lefdB4rD16rMjKQvzo8dF28QQONfuk9gg=";
};
# do not run tests
doCheck = false;
buildInputs = [
];
# specific to buildPythonPackage, see its reference
pyproject = true;
build-system = [
# setuptools
# setuptools-scm
# wheel
];
}
-33
View File
@@ -1,33 +0,0 @@
{
lib,
buildPythonPackage,
fetchPypi,
setuptools,
setuptools-scm,
wheel,
# runtime deps
}:
buildPythonPackage
rec {
pname = "cadquery-ocp";
version = "7.9.3.1";
src = fetchPypi {
inherit pname version;
hash = "sha256-c97Tjdyo67lefdB4rD16rMjKQvzo8dF28QQONfuk9gg=";
};
# do not run tests
doCheck = false;
buildInputs = [
];
# specific to buildPythonPackage, see its reference
pyproject = true;
build-system = [
# setuptools
# setuptools-scm
# wheel
];
}
-33
View File
@@ -1,33 +0,0 @@
{
lib,
buildPythonPackage,
fetchPypi,
setuptools,
setuptools-scm,
wheel,
# runtime deps
}:
buildPythonPackage
rec {
pname = "ocp-gordon";
version = "0.2.0";
src = fetchPypi {
inherit pname version;
hash = "sha256-c97Tjdyo67lefdB4rD16rMjKQvzo8dF28QQONfuk9gg=";
};
# do not run tests
doCheck = false;
buildInputs = [
];
# specific to buildPythonPackage, see its reference
pyproject = true;
build-system = [
# setuptools
# setuptools-scm
# wheel
];
}
-37
View File
@@ -1,37 +0,0 @@
{
lib,
buildPythonPackage,
fetchPypi,
setuptools,
setuptools-scm,
wheel,
# runtime deps
cadquery-ocp-proxy,
svgelements,
}:
buildPythonPackage
rec {
pname = "ocpsvg";
version = "0.6.0";
src = fetchPypi {
inherit pname version;
hash = "sha256-8I2kNHzJDs01ZTlem9pXRtRquKr9aiaBuwOpwyG1QDk=";
};
# do not run tests
doCheck = false;
buildInputs = [
cadquery-ocp-proxy
svgelements
];
# specific to buildPythonPackage, see its reference
pyproject = true;
build-system = [
setuptools
setuptools-scm
# wheel
];
}
-33
View File
@@ -1,33 +0,0 @@
{
lib,
buildPythonPackage,
fetchPypi,
setuptools,
setuptools-scm,
wheel,
# runtime deps
}:
buildPythonPackage
rec {
pname = "trianglesolver";
version = "1.2";
src = fetchPypi {
inherit pname version;
hash = "sha256-SvGKreV51cDWQ4mz5lrq8Gz/JjGXYszYWeMmhVmnauo=";
};
# do not run tests
doCheck = false;
buildInputs = [
];
# specific to buildPythonPackage, see its reference
pyproject = true;
build-system = [
setuptools
# setuptools-scm
# wheel
];
}
+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")
+2 -3
View File
@@ -28,10 +28,9 @@
perSystem = {pkgs, ...}: { perSystem = {pkgs, ...}: {
krantz.build123d = { krantz.build123d = {
enable = true; enable = true;
# src = ./.;
# runtimeDeps = with pkgs; []; objectName = "box";
# buildDeps = with pkgs; []; builder = ./build3d.py;
}; };
}; };
}; };
Generated
+216 -8
View File
@@ -1,5 +1,98 @@
{ {
"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": 1777149905,
@@ -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,111 @@
"type": "github" "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": { "root": {
"inputs": { "inputs": {
"cadquery": "cadquery",
"crane": "crane", "crane": "crane",
"flake-parts": "flake-parts", "flake-parts": "flake-parts",
"nixpkgs": "nixpkgs", "nixpkgs": "nixpkgs_2",
"treefmt-nix": "treefmt-nix" "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": { "treefmt-nix": {
"inputs": { "inputs": {
"nixpkgs": [ "nixpkgs": [
+6
View File
@@ -12,6 +12,12 @@
}; };
crane.url = "github:ipetkov/crane"; 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: outputs = {flake-parts, ...} @ inputs: