diff options
| author | Nathan Perry <np@nathanperry.dev> | 2024-09-02 19:53:43 -0400 |
|---|---|---|
| committer | Nathan Perry <np@nathanperry.dev> | 2024-09-02 19:53:43 -0400 |
| commit | 982798292719a24bcbb4f9e17cd5c65c8a46ecda (patch) | |
| tree | 11800fcb5a70f21903aeebed407473420bbe0d41 /hw/clef/nix/schematic.nix | |
| parent | 5ddfa32166cee8b2f91f37f9037eb26c182c2125 (diff) | |
move hw into subdirectory
Diffstat (limited to 'hw/clef/nix/schematic.nix')
| -rw-r--r-- | hw/clef/nix/schematic.nix | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/hw/clef/nix/schematic.nix b/hw/clef/nix/schematic.nix new file mode 100644 index 0000000..e931dd4 --- /dev/null +++ b/hw/clef/nix/schematic.nix @@ -0,0 +1,54 @@ +{ + kicad, + runCommand, + + nix-filter, + lib, + + src, + sch_path, + + schName ? (lib.removeSuffix ".kicad_sch" (builtins.baseNameOf sch_path)), +}: let + sharePath = "share/npry/clef/schematic"; + +in runCommand "${schName}.schematic" { + nativeBuildInputs = [ + kicad + ]; + + src = nix-filter { + root = src; + + include = [ + (nix-filter.matchExt "kicad_sch") + (nix-filter.matchExt "kicad_pro") + (nix-filter.matchExt "kicad_wks") + + (_args: path: type: type == "directory") + ]; + }; +} '' + set -e + export HOME=$(mktemp -d) + + echo "schematic: '${schName}'" >&2 + + mkdir -p "$out/${sharePath}/svg" + cd "$src" + + kicad-cli sch export pdf -o "$out/${sharePath}/schematic.pdf" $src/${sch_path} + kicad-cli sch export svg -n -o "$out/${sharePath}/svg" $src/${sch_path} + + cd "$out/${sharePath}/svg" + + # normalize + for f in *.svg; do + if [ "$f" = "${schName}.svg" ]; then + mv -nv "$f" "root.svg" + continue + fi + + mv -nv "$f" "''${f#${schName}-}" + done +'' |
