diff options
Diffstat (limited to 'hw/clef/nix/fabrication.nix')
| -rw-r--r-- | hw/clef/nix/fabrication.nix | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/hw/clef/nix/fabrication.nix b/hw/clef/nix/fabrication.nix new file mode 100644 index 0000000..18bc6f6 --- /dev/null +++ b/hw/clef/nix/fabrication.nix @@ -0,0 +1,82 @@ +{ + kicad, + kikit, + zip, + + runCommand, + + nix-filter, + lib, + + src, + pcb_path, + sch_path, + + boardName ? (lib.removeSuffix ".kicad_pcb" (builtins.baseNameOf pcb_path)), + + fabHouse ? "jlcpcb", + withAssembly ? true, +}: let + sharePath = "share/npry/clef/fab"; + + fabSrc = nix-filter { + root = src; + + include = [ + (nix-filter.matchExt "kicad_sch") + (nix-filter.matchExt "kicad_wks") + (nix-filter.matchExt "kicad_pcb") + (nix-filter.matchExt "kicad_pro") + + (_args: path: type: type == "directory") + ]; + }; + +in runCommand "${boardName}.fab" { + nativeBuildInputs = [ + kicad + kikit + zip + ]; + + src = fabSrc; + + allowedRequisites = []; +} '' + set -e + + export HOME=$(mktemp -d) + + echo "board: '${boardName}'" >&2 + + mkdir -p "$out/${sharePath}" + cd "$src" + + kikit fab ${fabHouse} \ + ${if withAssembly then "--assembly" else ""} \ + --no-drc \ + --schematic "${sch_path}" \ + --field 'LCSC Part #,LCSC Part No' \ + --missingError \ + "${pcb_path}" \ + "$out/${sharePath}" + + cd "$out/${sharePath}" + rm -vf "gerbers.zip" + + pushd gerber + + # normalize + for f in ${boardName}-*; do + mv -nv "$f" "''${f#${boardName}-}" + done + + for f in ${boardName}.*; do + mv -nv "$f" "board''${f#${boardName}}" + done + + popd + + zip -vj "gerbers.zip" gerber/* + rm -vrf gerber +'' |
