From 4c00d7762beb8e9a310e4f17697d0295b9467404 Mon Sep 17 00:00:00 2001 From: Reed Krantz Date: Mon, 27 Apr 2026 19:03:26 -0500 Subject: [PATCH] feat(build123d): support multiple outputs from the builder script and replace the objectName and outputFileName with just outputName --- build123d/default.nix | 58 +++++++++++++++++++++++++----------- build123d/template/flake.nix | 4 +-- 2 files changed, 43 insertions(+), 19 deletions(-) diff --git a/build123d/default.nix b/build123d/default.nix index 78a9890..6c9cdfc 100644 --- a/build123d/default.nix +++ b/build123d/default.nix @@ -33,25 +33,36 @@ cadquery build123d ]); + + outputExt = [ + "step" + "stl" + "3mf" + ]; in { options.krantz.build123d = { - enable = lib.mkEnableOption "executing a python build123d/cadquery file to get a 3d file"; - - objectName = lib.mkOption { - description = "What to name this object."; - type = lib.types.str; - example = "box"; - }; + 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."; + description = "The path to python cad script that generates the 3d file(s)."; 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."; + + 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 = "output.step"; + default = ""; + example = "box_for_stuf"; }; devShell = { @@ -83,7 +94,7 @@ description = "The name of the attribute in packages to configure"; type = lib.types.str; default = "default"; - example = "step"; + example = "3dfiles"; }; }; }; @@ -106,18 +117,31 @@ # Your custom packages # Accessible through 'nix build', 'nix shell', 'nix run', etc - packages.${cfg.package.name} = lib.mkIf cfg.package.enable (pkgs.runCommand cfg.objectName {} + packages.${cfg.package.name} = lib.mkIf cfg.package.enable (pkgs.runCommand cfg.outputName {} /* bash */ '' - RESULT_FILE_NAME=${cfg.objectName}.${lib.last (lib.splitString "." cfg.outputFileName)} + mkdir $out + cd $out ${pyEnv}/bin/python ${cfg.builder} - mkdir $out - mv ${cfg.outputFileName} $out/$RESULT_FILE_NAME - ln -s ./$RESULT_FILE_NAME $out/${cfg.outputFileName} + ${ + 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 "" + } ''); }; }); diff --git a/build123d/template/flake.nix b/build123d/template/flake.nix index 3c474c9..4ad395d 100644 --- a/build123d/template/flake.nix +++ b/build123d/template/flake.nix @@ -28,9 +28,9 @@ perSystem = {pkgs, ...}: { krantz.build123d = { enable = true; - - objectName = "box"; builder = ./build3d.py; + + outputName = "box"; }; }; };