flake: create diff deriv. for PCB & copper_plate

This commit is contained in:
linuswck 2023-12-21 16:02:54 +08:00
parent 082aa8521f
commit fa31ec4c41
1 changed files with 67 additions and 45 deletions

View File

@ -11,18 +11,19 @@
build = { variant }: build = { variant }:
let let
production_files = pkgs.stdenv.mkDerivation { adapter_production_files = pkgs.stdenv.mkDerivation {
name = "production-files"; name = "production-files";
src = ./kirdy_LD_adapter_${variant}; src = ./kirdy_LD_adapter_${variant};
nativeBuildInputs = [ pkgs.kicad pkgs.zip pkgs.python3 ]; nativeBuildInputs = [ pkgs.kicad pkgs.zip pkgs.python3 ];
buildPhase = '' buildPhase = ''
echo ${variant}
# kicad-cli requires the use of $HOME # kicad-cli requires the use of $HOME
TMP_DIR="$(pwd)/$(mktemp -d tmp.XXXX)" TMP_DIR="$(pwd)/$(mktemp -d tmp.XXXX)"
export HOME=$TMP_DIR export HOME=$TMP_DIR
if [ "${variant}" != "copper_plate" ]; then
SCH=kirdy_LD_adapter_${variant}.kicad_sch SCH=kirdy_LD_adapter_${variant}.kicad_sch
PCB=kirdy_LD_adapter_${variant}.kicad_pcb PCB=kirdy_LD_adapter_${variant}.kicad_pcb
@ -47,40 +48,61 @@
kicad-cli pcb export drill $PCB -u mm --generate-map --map-format gerberx2 -o ./$PREFIX"_gerber_drill"/ kicad-cli pcb export drill $PCB -u mm --generate-map --map-format gerberx2 -o ./$PREFIX"_gerber_drill"/
zip -r -j $PREFIX"_gerber_drill" $PREFIX"_gerber_drill" zip -r -j $PREFIX"_gerber_drill" $PREFIX"_gerber_drill"
else
PCB=kirdy_LD_adapter_${variant}.kicad_pcb
# Get Revision Number from the Title Block in KiCAD PCB
REV=$(cat $PCB | grep rev | cut -d'"' -f 2)
PREFIX=kirdy_LD_adapter_${variant}_$REV
export KICAD7_3DMODEL_DIR=${pkgs.kicad.libraries.packages3d}/share/kicad/3dmodels
kicad-cli pcb export step $PCB --subst-models --force -o $PREFIX.step
fi
rm -r $TMP_DIR rm -r $TMP_DIR
''; '';
installPhase = '' installPhase = ''
mkdir -p $out/production_files mkdir -p $out/production_files
if [ ${variant} != "copper_plate" ]; then
cp $PREFIX"_bom".csv $out/production_files/$PREFIX"_bom".csv cp $PREFIX"_bom".csv $out/production_files/$PREFIX"_bom".csv
cp $PREFIX.pdf $out/production_files/$PREFIX.pdf cp $PREFIX.pdf $out/production_files/$PREFIX.pdf
cp $PREFIX"_pos".csv $out/production_files/$PREFIX"_pos.csv" cp $PREFIX"_pos".csv $out/production_files/$PREFIX"_pos.csv"
cp $PREFIX.step $out/production_files/$PREFIX.step cp $PREFIX.step $out/production_files/$PREFIX.step
cp $PREFIX"_gerber_drill".zip $out/production_files/$PREFIX"_gerber_drill".zip cp $PREFIX"_gerber_drill".zip $out/production_files/$PREFIX"_gerber_drill".zip
else
cp $PREFIX.step $out/production_files/$PREFIX.step cp $PREFIX.step $out/production_files/$PREFIX.step
fi
''; '';
}; };
in { "LD_adapter_${variant}" = production_files; };
copper_plate_production_files = pkgs.stdenv.mkDerivation {
name = "production-files";
src = ./kirdy_LD_adapter_copper_plate;
nativeBuildInputs = [ pkgs.kicad pkgs.zip pkgs.python3 ];
buildPhase = ''
# kicad-cli requires the use of $HOME
TMP_DIR="$(pwd)/$(mktemp -d tmp.XXXX)"
export HOME=$TMP_DIR
PCB=kirdy_LD_adapter_copper_plate.kicad_pcb
# Get Revision Number from the Title Block in KiCAD PCB
REV=$(cat $PCB | grep rev | cut -d'"' -f 2)
PREFIX=kirdy_LD_adapter_copper_plate_$REV
export KICAD7_3DMODEL_DIR=${pkgs.kicad.libraries.packages3d}/share/kicad/3dmodels
kicad-cli pcb export step $PCB --subst-models --force -o $PREFIX.step
rm -r $TMP_DIR
'';
installPhase = ''
mkdir -p $out/production_files
cp $PREFIX.step $out/production_files/$PREFIX.step
'';
};
in {
"LD_adapter_${variant}_PCB" = adapter_production_files;
"LD_adapter_${variant}_copper_plate" = copper_plate_production_files;
};
in rec { in rec {
formatter.x86_64-linux = nixpkgs.legacyPackages.x86_64-linux.nixfmt; formatter.x86_64-linux = nixpkgs.legacyPackages.x86_64-linux.nixfmt;
packages.x86_64-linux = (build { variant = "type_1"; }) packages.x86_64-linux = (build { variant = "type_1"; })
// (build { variant = "type_2"; }) // (build { variant = "type_2"; });
// (build { variant = "copper_plate"; });
devShells.x86_64-linux.default = devShells.x86_64-linux.default =
let pkgs = nixpkgs.legacyPackages.x86_64-linux; let pkgs = nixpkgs.legacyPackages.x86_64-linux;