aboutsummaryrefslogtreecommitdiff
path: root/nix/svg.nix
diff options
context:
space:
mode:
Diffstat (limited to 'nix/svg.nix')
-rw-r--r--nix/svg.nix76
1 files changed, 47 insertions, 29 deletions
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 = ./..;
+ root = src;
- exclude = [
- "nix"
- ".gitignore"
- "flake.nix"
- "flake.lock"
- ".envrc"
- "kikit"
- "models"
+ 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
''