feat!(cad): rename build123d template to cad

This commit is contained in:
2026-04-28 13:04:50 -05:00
parent 69f0dcbd66
commit 5683d7e84c
6 changed files with 11 additions and 11 deletions
+153
View File
@@ -0,0 +1,153 @@
{
flake-parts-lib,
inputs,
...
}: {
flake = {
templates = {
cad = {
path = ./template;
description = "A python flake with a build132d/cadquery parametric cad setup";
};
};
flakeModules.cad = {
imports = [
inputs.treefmt-nix.flakeModule
];
options.perSystem = flake-parts-lib.mkPerSystemOption ({
lib,
config,
pkgs,
system,
...
}: let
cfg = config.krantz.cad;
cq = inputs.cadquery.packages.${system};
pyEnv = cq.python3.withPackages (p:
with p; [
cadquery
build123d
]);
outputExt = [
"step"
"stl"
"3mf"
];
in {
options.krantz.cad = {
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(s).";
type = lib.types.path;
example = lib.literalExpression "./build3d.py";
};
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 = "";
example = "box_for_stuf";
};
devShell = {
enable = lib.mkEnableOption "a build123d/cadquery development environment" // {default = true;};
name = lib.mkOption {
description = "The name of the attribute in devShells to configure";
type = lib.types.str;
default = "default";
example = "cad";
};
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 = "3dfiles";
};
};
};
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 {
packages = [
pyEnv
];
shellHook = ''
export PYTHONPATH="${pyEnv}/${pyEnv.sitePackages}:$PYTHONPATH"
'';
}
// cfg.devShell.extraAttrs);
# Formatter for nix files, available through 'nix fmt'
treefmt = {
programs.alejandra.enable = lib.mkDefault true;
};
# Your custom packages
# Accessible through 'nix build', 'nix shell', 'nix run', etc
packages.${cfg.package.name} = lib.mkIf cfg.package.enable (pkgs.runCommand cfg.outputName {}
/*
bash
*/
''
mkdir $out
cd $out
${pyEnv}/bin/python ${cfg.builder}
${
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 ""
}
'');
};
});
};
};
}