aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--flake.lock13
-rw-r--r--flake.nix28
-rw-r--r--nix/board.nix34
-rw-r--r--nix/default.nix60
-rw-r--r--nix/fabrication.nix73
-rw-r--r--nix/model.nix41
-rw-r--r--nix/panel.nix45
-rw-r--r--nix/schematic.nix51
-rw-r--r--nix/schematics.nix0
-rw-r--r--nix/svg.nix76
10 files changed, 306 insertions, 115 deletions
diff --git a/flake.lock b/flake.lock
index c1dfe1e..5f3d9ad 100644
--- a/flake.lock
+++ b/flake.lock
@@ -17,6 +17,18 @@
"type": "github"
}
},
+ "clef": {
+ "flake": false,
+ "locked": {
+ "narHash": "sha256-VsarKxUotDEPzjyw+fa6gK3snk0XXObTlplS86PvhpM=",
+ "type": "file",
+ "url": "https://pub.npry.dev/clef"
+ },
+ "original": {
+ "type": "file",
+ "url": "https://pub.npry.dev/clef"
+ }
+ },
"cq": {
"inputs": {
"cadquery-src": "cadquery-src",
@@ -182,6 +194,7 @@
},
"root": {
"inputs": {
+ "clef": "clef",
"cq": "cq",
"flake-utils": "flake-utils",
"nix-filter": "nix-filter",
diff --git a/flake.nix b/flake.nix
index 2059ac7..8cc182a 100644
--- a/flake.nix
+++ b/flake.nix
@@ -10,6 +10,11 @@
inputs.nixpkgs.follows = "nixpkgs";
inputs.flake-utils.follows = "flake-utils";
};
+
+ clef = {
+ url = "https://pub.npry.dev/clef";
+ flake = false;
+ };
};
description = "tiny kite-borne sensor node";
@@ -66,21 +71,28 @@
];
};
- mkPackages = pkgs: pkgs.callPackages ./nix {};
+ mkPkg = pkgs: pkgs.callPackage ./nix {
+ name = "ocularium";
+
+ src = ./.;
+
+ main_pcb = "okm.kicad_pcb";
+ main_sch = "okm.kicad_sch";
+
+ layers = 4;
+
+ outPath = "share/npry/ocularium";
+ };
in (flake-utils.lib.eachDefaultSystem (system:
let
pkgs = mkPkgs system;
- packages = mkPackages pkgs;
-
- full_package = (pkgs.emptyFile).overrideAttrs ({
- passthru = packages;
- });
+ pkg = mkPkg pkgs;
in {
packages = {
- default = full_package;
- ocularium = full_package;
+ default = pkg;
+ ocularium = pkg;
};
devShells.default = pkgs.mkShell {
diff --git a/nix/board.nix b/nix/board.nix
new file mode 100644
index 0000000..49418f0
--- /dev/null
+++ b/nix/board.nix
@@ -0,0 +1,34 @@
+{
+ runCommand,
+
+ svg,
+ model,
+ fabrication,
+ schematic,
+ panel,
+ panelSrc,
+
+ name,
+ outPath,
+}: let
+ pkg = runCommand name {} ''
+ set -e
+
+ mkdir -p "$out/${outPath}"
+ cd "$out/${outPath}"
+
+ echo "populating $(pwd)"
+
+ cp --reflink=auto -vr "${schematic}/share/npry/clef/schematic" ./
+ cp --reflink=auto -vr "${svg}/share/npry/clef/svg" ./
+ cp --reflink=auto -vr "${fabrication}/share/npry/clef/fab" ./
+ cp --reflink=auto -vr "${model}/share/npry/clef/model" ./
+ cp --reflink=auto -vr "${panelSrc}/share/npry/clef/panel" ./
+ '';
+
+in pkg.overrideAttrs (prevAttrs: {
+ passthru = (prevAttrs.passthru or {}) // {
+ inherit schematic fabrication svg model panel panelSrc;
+ fab = fabrication;
+ };
+})
diff --git a/nix/default.nix b/nix/default.nix
index 2c5ac7a..eee258c 100644
--- a/nix/default.nix
+++ b/nix/default.nix
@@ -1,22 +1,52 @@
{
pkgs,
+
+ src,
+ main_pcb,
+ main_sch,
+
+ name,
+ outPath ? "share/npry/clef",
+ layers ? 2,
}: let
- panel = pkgs.callPackage ./panel.nix {};
- svgs = pkgs.callPackage ./svg.nix { inherit panel; };
- model = pkgs.callPackage ./model.nix { inherit panel; };
- fabrication = pkgs.callPackage ./fabrication.nix { inherit panel; };
+ pcb_path = main_pcb;
+ sch_path = main_sch;
+
+ pcb_args = {
+ inherit pcb_path src;
+ };
+
+ panelSrc = pkgs.callPackage ./panel.nix pcb_args;
+ panel = pkgs.callPackage ./. {
+ src = "${panelSrc}/share/npry/clef/panel";
+ main_pcb = "panel.kicad_pcb";
+
+ name = "${name}.sub.panel";
+ outPath = "${outPath}/panel";
+
+ inherit main_sch layers;
+ };
+
+ svg = pkgs.callPackage ./svg.nix (pcb_args // { nLayer = layers; });
+ model = pkgs.callPackage ./model.nix pcb_args;
+
+ fabrication = pkgs.callPackage ./fabrication.nix (pcb_args // {
+ inherit sch_path;
+ });
- full = pkgs.symlinkJoin {
- name = "ocularium";
- paths = [
- panel
- svgs
- model
- fabrication
- ];
+ schematic = pkgs.callPackage ./schematic.nix {
+ inherit sch_path src;
};
-in {
- inherit panel svgs model fabrication full;
- fab = fabrication;
+in pkgs.callPackage ./board.nix {
+ inherit
+ svg
+ model
+ fabrication
+ schematic
+ name
+ outPath
+ panel
+ panelSrc
+ ;
}
diff --git a/nix/fabrication.nix b/nix/fabrication.nix
index 82a5d3f..18bc6f6 100644
--- a/nix/fabrication.nix
+++ b/nix/fabrication.nix
@@ -4,62 +4,79 @@
zip,
runCommand,
+
nix-filter,
+ lib,
- panel,
-}: let
- schSrc = nix-filter {
- root = ./..;
+ src,
+ pcb_path,
+ sch_path,
- include = [
- (nix-filter.matchExt "kicad_sch")
- ];
- };
+ boardName ? (lib.removeSuffix ".kicad_pcb" (builtins.baseNameOf pcb_path)),
+
+ fabHouse ? "jlcpcb",
+ withAssembly ? true,
+}: let
+ sharePath = "share/npry/clef/fab";
- pcbSrc = nix-filter {
- root = ./..;
+ fabSrc = nix-filter {
+ root = src;
include = [
+ (nix-filter.matchExt "kicad_sch")
+ (nix-filter.matchExt "kicad_wks")
(nix-filter.matchExt "kicad_pcb")
(nix-filter.matchExt "kicad_pro")
+
+ (_args: path: type: type == "directory")
];
};
-in runCommand "ocularium.fab" {
+in runCommand "${boardName}.fab" {
nativeBuildInputs = [
kicad
kikit
zip
];
- src = panel;
+ src = fabSrc;
allowedRequisites = [];
} ''
set -e
- mkdir -p $out/share/npry/ocularium/fab
- mkdir -p $out/share/npry/ocularium/panel/fab
-
export HOME=$(mktemp -d)
- cd $out/share/npry/ocularium/fab
+ echo "board: '${boardName}'" >&2
+
+ mkdir -p "$out/${sharePath}"
+ cd "$src"
- kikit fab jlcpcb --assembly \
+ kikit fab ${fabHouse} \
+ ${if withAssembly then "--assembly" else ""} \
--no-drc \
- --schematic ${schSrc}/okm.kicad_sch \
+ --schematic "${sch_path}" \
--field 'LCSC Part #,LCSC Part No' \
--missingError \
- ${pcbSrc}/okm.kicad_pcb .
- rm -rf gerber
+ "${pcb_path}" \
+ "$out/${sharePath}"
- cd ../panel
+ cd "$out/${sharePath}"
+ rm -vf "gerbers.zip"
- kikit fab jlcpcb --assembly \
- --no-drc \
- --schematic ${schSrc}/okm.kicad_sch \
- --field 'LCSC Part #,LCSC Part No' \
- --missingError \
- $src/share/npry/ocularium/panel.kicad_pcb .
- rm -rf gerber
+ pushd gerber
+
+ # normalize
+ for f in ${boardName}-*; do
+ mv -nv "$f" "''${f#${boardName}-}"
+ done
+
+ for f in ${boardName}.*; do
+ mv -nv "$f" "board''${f#${boardName}}"
+ done
+
+ popd
+
+ zip -vj "gerbers.zip" gerber/*
+ rm -vrf gerber
''
diff --git a/nix/model.nix b/nix/model.nix
index daa86ca..04bf1b1 100644
--- a/nix/model.nix
+++ b/nix/model.nix
@@ -3,30 +3,34 @@
runCommand,
nix-filter,
-
- panel,
+ lib,
withTracks ? false,
withZones ? false,
+
+ src,
+ pcb_path,
+
+ boardName ? (lib.removeSuffix ".kicad_pcb" (builtins.baseNameOf pcb_path)),
}: let
zonesArg = if withZones then "--include-zones" else "";
tracksArg = if withTracks then "--include-tracks" else "";
+ sharePath = "share/npry/clef/model";
-in runCommand "ocularium.model" {
+in runCommand "${boardName}.model" {
nativeBuildInputs = [
kicad
];
src = nix-filter {
- root = ./..;
+ root = src;
- exclude = [
- "nix"
- ".gitignore"
- "flake.nix"
- "flake.lock"
- ".envrc"
- "kikit"
+ include = [
+ (nix-filter.matchExt "kicad_pcb")
+
+ (nix-filter.matchExt "stp")
+ (nix-filter.matchExt "step")
+ (nix-filter.matchExt "wrl")
];
};
@@ -36,18 +40,13 @@ in runCommand "ocularium.model" {
} ''
set -e
- mkdir -p $out/share/npry/ocularium/model
- mkdir -p $out/share/npry/ocularium/panel/model
-
export HOME=$(mktemp -d)
- cd $out/share/npry/ocularium/model
-
- kicad-cli pcb export step --subst-models --no-dnp ${tracksArg} ${zonesArg} $src/okm.kicad_pcb -o ocularium.step
- kicad-cli pcb export glb --subst-models --no-dnp ${tracksArg} ${zonesArg} $src/okm.kicad_pcb -o ocularium.glb
+ echo "board: '${boardName}'" >&2
- cd ../panel/model
+ mkdir -p $out/${sharePath}
+ cd "$out/${sharePath}"
- kicad-cli pcb export step --subst-models --no-dnp ${tracksArg} ${zonesArg} ${panel}/share/npry/ocularium/panel.kicad_pcb -o panel.step
- kicad-cli pcb export glb --subst-models --no-dnp ${tracksArg} ${zonesArg} ${panel}/share/npry/ocularium/panel.kicad_pcb -o panel.glb
+ kicad-cli pcb export step --subst-models --no-dnp ${tracksArg} ${zonesArg} "$src/${pcb_path}" -o "${boardName}.step"
+ kicad-cli pcb export glb --subst-models --no-dnp ${tracksArg} ${zonesArg} "$src/${pcb_path}" -o "${boardName}.glb"
''
diff --git a/nix/panel.nix b/nix/panel.nix
index 41f55dd..a56539a 100644
--- a/nix/panel.nix
+++ b/nix/panel.nix
@@ -1,29 +1,46 @@
{
- kicad,
kikit,
- nix-filter,
runCommand,
-}: runCommand "ocularium.panel" {
- nativeBuildInputs = [
- kicad
- kikit
- ];
- src = nix-filter {
- root = ./..;
+ nix-filter,
+ lib,
+
+ panelizeConfigs ? [":jlcTooling"],
+ src,
+ pcb_path,
+
+ boardName ? (lib.removeSuffix ".kicad_pcb" (builtins.baseNameOf pcb_path)),
+}: let
+ sharePath = "share/npry/clef/panel";
+
+ panelSrc = nix-filter {
+ root = src;
include = [
- "kikit"
(nix-filter.matchExt "kicad_pcb")
];
};
+
+in runCommand "${boardName}.panel" {
+ nativeBuildInputs = [
+ kikit
+ ];
+
+ allowedRequisites = [];
} ''
set -e
export HOME=$(mktemp -d)
- mkdir -p $out/share/npry/ocularium
- cd $HOME
+ mkdir -p "$out/${sharePath}"
+
+ # do the panelize here rather than in $out because it creates junk we don't want
+ cd $HOME
+
+ kikit panelize \
+ ${lib.concatMapStrings (conf: "-p ${conf} \\\n") panelizeConfigs} \
+ "${panelSrc}/${pcb_path}" \
+ "panel.kicad_pcb"
- kikit panelize -p :jlcTooling -p $src/kikit/jlc_edge_rails.json $src/okm.kicad_pcb panel.kicad_pcb
- cp panel.kicad_{pcb,pro} $out/share/npry/ocularium
+ cp -v panel.kicad_{pcb,pro} "$out/${sharePath}"
+ cp -v "${src}/"*.kicad_{sch,pro} "$out/${sharePath}"
''
diff --git a/nix/schematic.nix b/nix/schematic.nix
new file mode 100644
index 0000000..acc136f
--- /dev/null
+++ b/nix/schematic.nix
@@ -0,0 +1,51 @@
+{
+ 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")
+ ];
+ };
+} ''
+ set -e
+ export HOME=$(mktemp -d)
+
+ echo "schematic: '${schName}'" >&2
+
+ mkdir -p "$out/${sharePath}/svg"
+ cd "$out/${sharePath}"
+
+ kicad-cli sch export pdf -o schematic.pdf $src/${sch_path}
+ kicad-cli sch export svg -n -o svg $src/${sch_path}
+
+ cd 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
+''
diff --git a/nix/schematics.nix b/nix/schematics.nix
deleted file mode 100644
index e69de29..0000000
--- a/nix/schematics.nix
+++ /dev/null
diff --git a/nix/svg.nix b/nix/svg.nix
index 3d93ecc..fc1a404 100644
--- a/nix/svg.nix
+++ b/nix/svg.nix
@@ -1,36 +1,47 @@
{
runCommand,
kicad,
+
nix-filter,
+ lib,
+
+ pcb_path,
+ src,
+
+ withSilk ? true,
+ withEdgeCuts ? true,
+ withMirrors ? true,
+ nLayer ? 2,
+
+ boardName ? (lib.removeSuffix ".kicad_pcb" (builtins.baseNameOf pcb_path)),
+}: let
+ sharePath = "share/npry/clef/svg";
- panel,
-}: runCommand "ocularium.svg" {
+in runCommand "${boardName}.svg" {
nativeBuildInputs = [
kicad
];
src = nix-filter {
- root = ./..;
+ root = src;
- exclude = [
- "nix"
- ".gitignore"
- "flake.nix"
- "flake.lock"
- ".envrc"
- "kikit"
- "models"
+ include = [
+ (nix-filter.matchExt "kicad_pcb")
];
};
+ nInnerLayer = if nLayer < 2 then 0 else nLayer - 2;
+
allowedRequisites = [];
} ''
set -e
export HOME=$(mktemp -d)
- mkdir -p $out/share/npry/ocularium/svg
- mkdir -p $out/share/npry/ocularium/panel/svg
+ echo "board: '${boardName}'" >&2
+
+ mkdir -p $out/${sharePath}
+ cd "$out/${sharePath}"
mksvg() {
local infile=$1
@@ -38,27 +49,34 @@
local outfile=$3
kicad-cli pcb export svg \
- "$infile.kicad_pcb" \
+ "$infile" \
-l "$layers" \
- -o $outfile.svg \
+ -o "$outfile.svg" \
--page-size-mode 2 \
--exclude-drawing-sheet
- }
- readonly okm="$src/okm"
- readonly panel="${panel}/share/npry/ocularium/panel"
-
- cd $out/share/npry/ocularium/svg
+ ${if withMirrors then ''
+ kicad-cli pcb export svg \
+ "$infile" \
+ -m \
+ -l "$layers" \
+ -o "$outfile.mirror.svg" \
+ --page-size-mode 2 \
+ --exclude-drawing-sheet
+ '' else ""}
+ }
- mksvg "$okm" "F.Cu,F.Silkscreen,Edge.Cuts" front
- mksvg "$okm" "B.Cu,B.Silkscreen,Edge.Cuts" back
- mksvg "$okm" "In1.Cu,Edge.Cuts" in1
- mksvg "$okm" "In2.Cu,Edge.Cuts" in2
+ mksvg "$src/${pcb_path}" \
+ "F.Cu,${if withSilk then "F.Silkscreen," else ""}${if withEdgeCuts then "Edge.Cuts," else ""}" \
+ front
- cd ../panel/svg
+ mksvg "$src/${pcb_path}" \
+ "B.Cu,${if withSilk then "B.Silkscreen," else ""}${if withEdgeCuts then "Edge.Cuts," else ""}" \
+ back
- mksvg "$panel" "F.Cu,F.Silkscreen,Edge.Cuts" front
- mksvg "$panel" "B.Cu,B.Silkscreen,Edge.Cuts" back
- mksvg "$panel" "In1.Cu,Edge.Cuts" in1
- mksvg "$panel" "In2.Cu,Edge.Cuts" in2
+ for i in $(seq 1 $nInnerLayer); do
+ mksvg "$src/${pcb_path}" \
+ "In$i.Cu,${if withEdgeCuts then "Edge.Cuts," else ""}" \
+ "in$i"
+ done
''