diff --git a/build123d/default.nix b/build123d/default.nix index 25ddb33..78a9890 100644 --- a/build123d/default.nix +++ b/build123d/default.nix @@ -7,7 +7,7 @@ templates = { build123d = { 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, pkgs, self', + system, ... }: let cfg = config.krantz.build123d; - python = pkgs.python3.override { - self = python; - packageOverrides = pyfinal: pyprev: { - build123d = pyfinal.callPackage ./packages/build123d.nix {}; - cadquery-ocp = pyfinal.callPackage ./packages/cadquery-ocp.nix {}; - cadquery-ocp-proxy = pyfinal.callPackage ./packages/cadquery-ocp-proxy.nix {}; - ocp-gordon = pyfinal.callPackage ./packages/ocp-gordon.nix {}; - ocpsvg = pyfinal.callPackage ./packages/ocpsvg.nix {}; - trianglesolver = pyfinal.callPackage ./packages/trianglesolver.nix {}; - }; - }; + cq = inputs.cadquery.packages.${system}; + + pyEnv = cq.python3.withPackages (p: + with p; [ + cadquery + build123d + ]); in { 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 { - # description = "The path to the root of the crate."; - # type = lib.types.path; - # example = lib.literalExpression "./."; - # }; - # srcFiltered = lib.mkOption { - # description = "A path to the filtered directory of the root of the crate."; - # type = lib.types.path; - # default = craneLib.cleanCargoSource cfg.src; - # defaultText = lib.literalExpression "config.krantz.rust.craneLib cfg.src"; - # example = lib.literalExpression "./."; - # }; - # - # runtimeDeps = lib.mkOption { - # description = "Packages needed for the app to run."; - # type = lib.types.listOf lib.types.package; - # default = []; - # example = with pkgs; [ - # openssl - # ]; - # }; - # buildDeps = lib.mkOption { - # description = "Packages needed for the app to build."; - # type = lib.types.listOf lib.types.package; - # default = []; - # example = with pkgs; [ - # pkg-config - # rustPlatform.bindgenHook - # ]; - # }; - # devDeps = lib.mkOption { - # description = "Packages to include only in the devShell."; - # type = lib.types.listOf lib.types.package; - # default = with pkgs; [ - # rust-analyzer - # ]; - # }; - # - # devShell = { - # enable = lib.mkEnableOption "a rust development environment" // {default = true;}; - # - # name = lib.mkOption { - # description = "The name of the attribute in devShells to configure"; - # type = lib.types.str; - # default = "default"; - # example = "rust"; - # }; - # - # 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; - # }; + objectName = lib.mkOption { + description = "What to name this object."; + type = lib.types.str; + example = "box"; + }; + + builder = lib.mkOption { + description = "The path to python cad script that generates the 3d file."; + type = lib.types.path; + example = lib.literalExpression "./build3d.py"; + }; + 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."; + type = lib.types.str; + default = "output.step"; + }; + + 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 = "step"; + }; + }; }; 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 { - # # extra tooling dependencies - # packages = cfg.devDeps; - # - # inputsFrom = [self'.packages.${cfg.package.name}]; - # } - # // cfg.devShell.extraAttrs); - devShells.default = pkgs.mkShell { - # extra tooling dependencies - packages = [ - (python.withPackages (p: - with p; [ - build123d - ])) - ]; - }; + 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 = { @@ -156,10 +106,19 @@ # Your custom packages # Accessible through 'nix build', 'nix shell', 'nix run', etc - # packages.${cfg.package.name} = lib.mkIf cfg.package.enable ( { - # inherit src buildInputs nativeBuildInputs cargoArtifacts; - # } - # // cfg.package.extraAttrs); + packages.${cfg.package.name} = lib.mkIf cfg.package.enable (pkgs.runCommand cfg.objectName {} + /* + bash + */ + '' + 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} + ''); }; }); }; diff --git a/build123d/packages/build123d.nix b/build123d/packages/build123d.nix deleted file mode 100644 index 9104f63..0000000 --- a/build123d/packages/build123d.nix +++ /dev/null @@ -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 - ]; -} diff --git a/build123d/packages/cadquery-ocp-proxy.nix b/build123d/packages/cadquery-ocp-proxy.nix deleted file mode 100644 index d3f3a34..0000000 --- a/build123d/packages/cadquery-ocp-proxy.nix +++ /dev/null @@ -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 - ]; -} diff --git a/build123d/packages/cadquery-ocp.nix b/build123d/packages/cadquery-ocp.nix deleted file mode 100644 index 892f78d..0000000 --- a/build123d/packages/cadquery-ocp.nix +++ /dev/null @@ -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 - ]; -} diff --git a/build123d/packages/ocp-gordon.nix b/build123d/packages/ocp-gordon.nix deleted file mode 100644 index c3dc456..0000000 --- a/build123d/packages/ocp-gordon.nix +++ /dev/null @@ -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 - ]; -} diff --git a/build123d/packages/ocpsvg.nix b/build123d/packages/ocpsvg.nix deleted file mode 100644 index af38bf8..0000000 --- a/build123d/packages/ocpsvg.nix +++ /dev/null @@ -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 - ]; -} diff --git a/build123d/packages/trianglesolver.nix b/build123d/packages/trianglesolver.nix deleted file mode 100644 index 0a72a3b..0000000 --- a/build123d/packages/trianglesolver.nix +++ /dev/null @@ -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 - ]; -} diff --git a/build123d/template/build3d.py b/build123d/template/build3d.py new file mode 100644 index 0000000..edcb619 --- /dev/null +++ b/build123d/template/build3d.py @@ -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") diff --git a/build123d/template/flake.nix b/build123d/template/flake.nix index 43d7908..3c474c9 100644 --- a/build123d/template/flake.nix +++ b/build123d/template/flake.nix @@ -28,10 +28,9 @@ perSystem = {pkgs, ...}: { krantz.build123d = { enable = true; - # src = ./.; - # runtimeDeps = with pkgs; []; - # buildDeps = with pkgs; []; + objectName = "box"; + builder = ./build3d.py; }; }; }; diff --git a/flake.lock b/flake.lock index c2be861..a4e6713 100644 --- a/flake.lock +++ b/flake.lock @@ -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": [ diff --git a/flake.nix b/flake.nix index 83e73cd..ead7755 100644 --- a/flake.nix +++ b/flake.nix @@ -12,6 +12,12 @@ }; 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: