# Reproducible EDA toolchain for the PM_K-1 core board.
#
# Why this exists: the system KiCad is 7.0 (no CLI ERC). This pins a known,
# rebuildable environment so the design can be checked/simulated identically
# years from now — fitting for a device meant to outlive its tools.
#
#   KiCad 9  -> schematic capture, CLI ERC/DRC, netlist/PDF/Gerber export
#   ngspice  -> SPICE simulation of the analog audio circuits
#   python3  -> scripting / BOM / skidl-style helpers
#
# Build/run via ../eda/run.sh (or: podman build -t pmk1-eda:9.0 .)
FROM docker.io/library/ubuntu:24.04

ENV DEBIAN_FRONTEND=noninteractive
SHELL ["/bin/bash", "-o", "pipefail", "-c"]

RUN apt-get update && apt-get install -y --no-install-recommends \
        software-properties-common ca-certificates gnupg && \
    add-apt-repository -y ppa:kicad/kicad-9.0-releases && \
    apt-get update && apt-get install -y --no-install-recommends \
        kicad \
        kicad-symbols \
        kicad-footprints \
        ngspice \
        python3 python3-pip python3-venv \
        git make && \
    apt-get clean && rm -rf /var/lib/apt/lists/* && \
    pip3 install --no-cache-dir --break-system-packages skidl

# netlistsvg: render the SKiDL netlist as a (browsable) schematic SVG
RUN apt-get update && apt-get install -y --no-install-recommends nodejs npm && \
    npm install -g netlistsvg && \
    npm cache clean --force && apt-get clean && rm -rf /var/lib/apt/lists/*

# gnuplot: render ngspice simulation results as PNG plots
RUN apt-get update && apt-get install -y --no-install-recommends gnuplot-nox && \
    apt-get clean && rm -rf /var/lib/apt/lists/*

# Point SKiDL / KiCad CLI at the installed libraries (reproducible, not ad-hoc).
ENV KICAD9_SYMBOL_DIR=/usr/share/kicad/symbols \
    KICAD9_FOOTPRINT_DIR=/usr/share/kicad/footprints \
    KICAD_SYMBOL_DIR=/usr/share/kicad/symbols

WORKDIR /work
CMD ["bash"]
