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
+78 -119
View File
@@ -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}
'');
};
});
};