blob: e931dd431976ed59d8add0efd35720259736677f (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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
''
|