feat(build123d): support multiple outputs from the builder script and replace the objectName and outputFileName with just outputName

This commit is contained in:
2026-04-27 19:03:26 -05:00
parent 28b32ca0fa
commit 4c00d7762b
2 changed files with 43 additions and 19 deletions
+41 -17
View File
@@ -33,25 +33,36 @@
cadquery cadquery
build123d build123d
]); ]);
outputExt = [
"step"
"stl"
"3mf"
];
in { in {
options.krantz.build123d = { options.krantz.build123d = {
enable = lib.mkEnableOption "executing a python build123d/cadquery file to get a 3d file"; enable = lib.mkEnableOption "executing a python build123d/cadquery file to generate 3d files";
objectName = lib.mkOption {
description = "What to name this object.";
type = lib.types.str;
example = "box";
};
builder = lib.mkOption { 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; type = lib.types.path;
example = lib.literalExpression "./build3d.py"; 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; type = lib.types.str;
default = "output.step"; default = "";
example = "box_for_stuf";
}; };
devShell = { devShell = {
@@ -83,7 +94,7 @@
description = "The name of the attribute in packages to configure"; description = "The name of the attribute in packages to configure";
type = lib.types.str; type = lib.types.str;
default = "default"; default = "default";
example = "step"; example = "3dfiles";
}; };
}; };
}; };
@@ -106,18 +117,31 @@
# 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 (pkgs.runCommand cfg.objectName {} packages.${cfg.package.name} = lib.mkIf cfg.package.enable (pkgs.runCommand cfg.outputName {}
/* /*
bash bash
*/ */
'' ''
RESULT_FILE_NAME=${cfg.objectName}.${lib.last (lib.splitString "." cfg.outputFileName)} mkdir $out
cd $out
${pyEnv}/bin/python ${cfg.builder} ${pyEnv}/bin/python ${cfg.builder}
mkdir $out ${
mv ${cfg.outputFileName} $out/$RESULT_FILE_NAME if cfg.outputName != ""
ln -s ./$RESULT_FILE_NAME $out/${cfg.outputFileName} then
/*
bash
*/
''
for ext in ${lib.concatStringsSep " " outputExt}; do
if [[ -f output.$ext ]]; then
mv output.$ext ${cfg.outputName}.$ext
fi
done
''
else ""
}
''); '');
}; };
}); });
+2 -2
View File
@@ -28,9 +28,9 @@
perSystem = {pkgs, ...}: { perSystem = {pkgs, ...}: {
krantz.build123d = { krantz.build123d = {
enable = true; enable = true;
objectName = "box";
builder = ./build3d.py; builder = ./build3d.py;
outputName = "box";
}; };
}; };
}; };