feat(build123d): support multiple outputs from the builder script and replace the objectName and outputFileName with just outputName
This commit is contained in:
+41
-17
@@ -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 ""
|
||||
}
|
||||
'');
|
||||
};
|
||||
});
|
||||
|
||||
@@ -28,9 +28,9 @@
|
||||
perSystem = {pkgs, ...}: {
|
||||
krantz.build123d = {
|
||||
enable = true;
|
||||
|
||||
objectName = "box";
|
||||
builder = ./build3d.py;
|
||||
|
||||
outputName = "box";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user