flake: cleanup, copper plate is common to both types

This commit is contained in:
Sebastien Bourdeauducq 2023-12-30 11:56:42 +08:00
parent b119e04c73
commit 05ca688af6
1 changed files with 62 additions and 68 deletions

130
flake.nix
View File

@ -9,96 +9,90 @@
let let
pkgs = import nixpkgs { system = "x86_64-linux"; }; pkgs = import nixpkgs { system = "x86_64-linux"; };
build = { variant }: adapter_production_files = variant: pkgs.stdenv.mkDerivation {
let name = "production-files";
adapter_production_files = pkgs.stdenv.mkDerivation { src = ./kirdy_LD_adapter_${variant};
name = "production-files";
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
TMP_DIR="$(mktemp --tmpdir -d kicad-kirdy.XXXXXXX)"
export HOME=$TMP_DIR
# kicad-cli requires the use of $HOME SCH=kirdy_LD_adapter_${variant}.kicad_sch
TMP_DIR="$(mktemp --tmpdir -d kicad-kirdy.XXXXXXX)" PCB=kirdy_LD_adapter_${variant}.kicad_pcb
export HOME=$TMP_DIR
SCH=kirdy_LD_adapter_${variant}.kicad_sch # Get Revision Number from the Title Block in KiCAD Top Schematics
PCB=kirdy_LD_adapter_${variant}.kicad_pcb REV=$(cat $SCH | grep rev | cut -d'"' -f 2)
PREFIX=kirdy_LD_adapter_${variant}_$REV
# Get Revision Number from the Title Block in KiCAD Top Schematics kicad-cli sch export python-bom $SCH -o $PREFIX"_bom".xml
REV=$(cat $SCH | grep rev | cut -d'"' -f 2) export PYTHONPATH=${pkgs.kicad.base}/share/kicad/plugins
PREFIX=kirdy_LD_adapter_${variant}_$REV python ${kicad_bom_generator}/generate_bom_from_xml.py $PREFIX"_bom".xml $PREFIX"_bom".csv
kicad-cli sch export python-bom $SCH -o $PREFIX"_bom".xml kicad-cli sch export pdf $SCH -o $PREFIX.pdf
export PYTHONPATH=${pkgs.kicad.base}/share/kicad/plugins kicad-cli pcb export pos $PCB --format csv --units mm -o $PREFIX"_pos".csv
python ${kicad_bom_generator}/generate_bom_from_xml.py $PREFIX"_bom".xml $PREFIX"_bom".csv
kicad-cli sch export pdf $SCH -o $PREFIX.pdf export KICAD7_3DMODEL_DIR=${pkgs.kicad.libraries.packages3d}/share/kicad/3dmodels
kicad-cli pcb export pos $PCB --format csv --units mm -o $PREFIX"_pos".csv kicad-cli pcb export step $PCB --subst-models --force -o $PREFIX.step
export KICAD7_3DMODEL_DIR=${pkgs.kicad.libraries.packages3d}/share/kicad/3dmodels mkdir -p $PREFIX"_gerber_drill"
kicad-cli pcb export step $PCB --subst-models --force -o $PREFIX.step kicad-cli pcb export gerbers $PCB -l 'F.Cu,B.Cu,F.Paste,B.Paste,F.Silkscreen,B.Silkscreen,F.Mask,B.Mask,Edge.Cuts' --no-x2 --subtract-soldermask -o ./$PREFIX"_gerber_drill"
mkdir -p $PREFIX"_gerber_drill" # The additional trailing slash is due to a bug in the kicad-cli tool. https://gitlab.com/kicad/code/kicad/-/issues/14438
kicad-cli pcb export gerbers $PCB -l 'F.Cu,B.Cu,F.Paste,B.Paste,F.Silkscreen,B.Silkscreen,F.Mask,B.Mask,Edge.Cuts' --no-x2 --subtract-soldermask -o ./$PREFIX"_gerber_drill" kicad-cli pcb export drill $PCB -u mm --generate-map --map-format gerberx2 -o ./$PREFIX"_gerber_drill"/
# The additional trailing slash is due to a bug in the kicad-cli tool. https://gitlab.com/kicad/code/kicad/-/issues/14438 zip -r -j $PREFIX"_gerber_drill" $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" installPhase = ''
''; mkdir -p $out/production_files
cp $PREFIX"_bom".csv $out/production_files/$PREFIX"_bom".csv
cp $PREFIX.pdf $out/production_files/$PREFIX.pdf
cp $PREFIX"_pos".csv $out/production_files/$PREFIX"_pos.csv"
cp $PREFIX.step $out/production_files/$PREFIX.step
cp $PREFIX"_gerber_drill".zip $out/production_files/$PREFIX"_gerber_drill".zip
installPhase = '' cp $PREFIX.step $out/production_files/$PREFIX.step
mkdir -p $out/production_files '';
cp $PREFIX"_bom".csv $out/production_files/$PREFIX"_bom".csv };
cp $PREFIX.pdf $out/production_files/$PREFIX.pdf
cp $PREFIX"_pos".csv $out/production_files/$PREFIX"_pos.csv"
cp $PREFIX.step $out/production_files/$PREFIX.step
cp $PREFIX"_gerber_drill".zip $out/production_files/$PREFIX"_gerber_drill".zip
cp $PREFIX.step $out/production_files/$PREFIX.step copper_plate_production_files = pkgs.stdenv.mkDerivation {
''; name = "production-files";
}; src = ./kirdy_LD_adapter_copper_plate;
copper_plate_production_files = pkgs.stdenv.mkDerivation { nativeBuildInputs = [ pkgs.kicad pkgs.python3 ];
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="$(mktemp --tmpdir -d kicad-kirdy.XXXXXXX)"
export HOME=$TMP_DIR
buildPhase = '' PCB=kirdy_LD_adapter_copper_plate.kicad_pcb
# kicad-cli requires the use of $HOME
TMP_DIR="$(mktemp --tmpdir -d kicad-kirdy.XXXXXXX)"
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
# Get Revision Number from the Title Block in KiCAD PCB export KICAD7_3DMODEL_DIR=${pkgs.kicad.libraries.packages3d}/share/kicad/3dmodels
REV=$(cat $PCB | grep rev | cut -d'"' -f 2) kicad-cli pcb export step $PCB --subst-models --force -o $PREFIX.step
PREFIX=kirdy_LD_adapter_copper_plate_$REV '';
export KICAD7_3DMODEL_DIR=${pkgs.kicad.libraries.packages3d}/share/kicad/3dmodels installPhase = ''
kicad-cli pcb export step $PCB --subst-models --force -o $PREFIX.step mkdir -p $out/production_files
''; cp $PREFIX.step $out/production_files/$PREFIX.step
'';
};
installPhase = '' in {
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 {
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_2"; }); "LD_adapter_type_1_PCB" = adapter_production_files "type_1";
"LD_adapter_type_2_PCB" = adapter_production_files "type_2";
"LD_adapter_copper_plate" = copper_plate_production_files;
};
devShells.x86_64-linux.default = devShells.x86_64-linux.default =
let pkgs = nixpkgs.legacyPackages.x86_64-linux; let pkgs = nixpkgs.legacyPackages.x86_64-linux;