From 7f5e8f7d7d467f6dd3321cfa7eb276396a21dc69 Mon Sep 17 00:00:00 2001 From: Nathan Perry Date: Tue, 13 Aug 2024 22:30:33 -0400 Subject: nix: rewrite expressions to be generic --- nix/svg.nix | 78 +++++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 48 insertions(+), 30 deletions(-) (limited to 'nix/svg.nix') diff --git a/nix/svg.nix b/nix/svg.nix index 3d93ecc..fc1a404 100644 --- a/nix/svg.nix +++ b/nix/svg.nix @@ -1,36 +1,47 @@ { runCommand, kicad, + nix-filter, + lib, + + pcb_path, + src, + + withSilk ? true, + withEdgeCuts ? true, + withMirrors ? true, + nLayer ? 2, + + boardName ? (lib.removeSuffix ".kicad_pcb" (builtins.baseNameOf pcb_path)), +}: let + sharePath = "share/npry/clef/svg"; - panel, -}: runCommand "ocularium.svg" { +in runCommand "${boardName}.svg" { nativeBuildInputs = [ kicad ]; src = nix-filter { - root = ./..; - - exclude = [ - "nix" - ".gitignore" - "flake.nix" - "flake.lock" - ".envrc" - "kikit" - "models" + root = src; + + include = [ + (nix-filter.matchExt "kicad_pcb") ]; }; + nInnerLayer = if nLayer < 2 then 0 else nLayer - 2; + allowedRequisites = []; } '' set -e export HOME=$(mktemp -d) - mkdir -p $out/share/npry/ocularium/svg - mkdir -p $out/share/npry/ocularium/panel/svg + echo "board: '${boardName}'" >&2 + + mkdir -p $out/${sharePath} + cd "$out/${sharePath}" mksvg() { local infile=$1 @@ -38,27 +49,34 @@ local outfile=$3 kicad-cli pcb export svg \ - "$infile.kicad_pcb" \ + "$infile" \ -l "$layers" \ - -o $outfile.svg \ + -o "$outfile.svg" \ --page-size-mode 2 \ --exclude-drawing-sheet - } - - readonly okm="$src/okm" - readonly panel="${panel}/share/npry/ocularium/panel" - cd $out/share/npry/ocularium/svg + ${if withMirrors then '' + kicad-cli pcb export svg \ + "$infile" \ + -m \ + -l "$layers" \ + -o "$outfile.mirror.svg" \ + --page-size-mode 2 \ + --exclude-drawing-sheet + '' else ""} + } - mksvg "$okm" "F.Cu,F.Silkscreen,Edge.Cuts" front - mksvg "$okm" "B.Cu,B.Silkscreen,Edge.Cuts" back - mksvg "$okm" "In1.Cu,Edge.Cuts" in1 - mksvg "$okm" "In2.Cu,Edge.Cuts" in2 + mksvg "$src/${pcb_path}" \ + "F.Cu,${if withSilk then "F.Silkscreen," else ""}${if withEdgeCuts then "Edge.Cuts," else ""}" \ + front - cd ../panel/svg + mksvg "$src/${pcb_path}" \ + "B.Cu,${if withSilk then "B.Silkscreen," else ""}${if withEdgeCuts then "Edge.Cuts," else ""}" \ + back - mksvg "$panel" "F.Cu,F.Silkscreen,Edge.Cuts" front - mksvg "$panel" "B.Cu,B.Silkscreen,Edge.Cuts" back - mksvg "$panel" "In1.Cu,Edge.Cuts" in1 - mksvg "$panel" "In2.Cu,Edge.Cuts" in2 + for i in $(seq 1 $nInnerLayer); do + mksvg "$src/${pcb_path}" \ + "In$i.Cu,${if withEdgeCuts then "Edge.Cuts," else ""}" \ + "in$i" + done '' -- cgit v1.3.1