aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan Perry <np@nathanperry.dev>2024-08-15 04:25:39 -0400
committerNathan Perry <np@nathanperry.dev>2024-08-15 04:25:39 -0400
commitf081aa9e2f243ffe6ea13024e3777626a8243aed (patch)
treec1ec687b1953a7f3e78d667ba09fbb5872917b50
parent9332cf7c0eac27ed5c00ec19e87d4d76b56f223a (diff)
clef/nix: support generating interactivehtmlbom
-rw-r--r--clef/flake.nix12
-rw-r--r--clef/nix/board.nix14
-rw-r--r--clef/nix/bom.nix38
-rw-r--r--clef/nix/default.nix3
-rw-r--r--clef/nix/pkgs/default.nix5
-rw-r--r--clef/nix/pkgs/interactive_html_bom.nix62
6 files changed, 124 insertions, 10 deletions
diff --git a/clef/flake.nix b/clef/flake.nix
index 66e350f..f20b1b8 100644
--- a/clef/flake.nix
+++ b/clef/flake.nix
@@ -16,17 +16,21 @@
outputs = { self, nixpkgs, flake-utils, ... } @ inputs: (flake-utils.lib.eachDefaultSystem (system: {
packages = let
+ packages = nixpkgs.legacyPackages.${system}.callPackages ./nix/pkgs {};
+
pkgs = import nixpkgs {
inherit system;
overlays = with self.overlays; [
kicad
nix-filter
+
+ (final: prev: packages)
];
};
clef = pkgs.callPackage ./nix;
- in {
+ in packages // {
inherit clef;
default = clef;
};
@@ -56,14 +60,14 @@
in base // {
# clef built against its own nixpkgs import with its required overlay
- # deps (cadquery, kicad, occt).
+ # deps (kicad, occt).
#
# _This will cause another evaluation of nixpkgs_, which is generally
# undesirable. However, this provides for the most hassle-free way to
# use clef, as you don't need to include all of the overlay dependencies
# in your nixpkgs.
default = final: prev: {
- clef = self.packages.${prev.system}.default;
+ inherit (self.packages.${prev.system}) clef;
};
# No overlay dependencies included -- clef will not work by default.
@@ -73,7 +77,7 @@
#
# Assuming you've pinned clef's nixpkgs to the same version as yours.
# This functionality is provided to give you an option
- freestanding = final: prev: {
+ freestanding = final: prev: (prev.callPackage ./nix/pkgs {}) {
clef = prev.callPackage ./nix;
};
};
diff --git a/clef/nix/board.nix b/clef/nix/board.nix
index d67417b..5de46e0 100644
--- a/clef/nix/board.nix
+++ b/clef/nix/board.nix
@@ -7,6 +7,7 @@
schematic,
panel,
panelSrc,
+ bom,
name,
outPath,
@@ -19,19 +20,20 @@
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 "${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 "${bom}/share/npry/clef/bom" ./
${if panelSrc != null then ''
- cp --reflink=auto -vr "${panelSrc}/share/npry/clef/panel" ./
+ cp --reflink=auto -vr "${panelSrc}/share/npry/clef/panel" ./
'' else ""}
'';
in pkg.overrideAttrs (prevAttrs: {
passthru = (prevAttrs.passthru or {}) // {
- inherit schematic fabrication svg model panel panelSrc;
+ inherit schematic fabrication svg model panel panelSrc bom;
fab = fabrication;
};
})
diff --git a/clef/nix/bom.nix b/clef/nix/bom.nix
new file mode 100644
index 0000000..7644939
--- /dev/null
+++ b/clef/nix/bom.nix
@@ -0,0 +1,38 @@
+{
+ runCommand,
+ interactiveHtmlBom,
+
+ nix-filter,
+ lib,
+
+ pcb_path,
+ src,
+
+ boardName ? (lib.removeSuffix ".kicad_pcb" (builtins.baseNameOf pcb_path)),
+ extraArgs ? [],
+}: let
+ sharePath = "share/npry/clef/bom";
+
+in runCommand "${boardName}.bom" {
+ nativeBuildInputs = [
+ interactiveHtmlBom
+ ];
+
+ INTERACTIVE_HTML_BOM_NO_DISPLAY = 1;
+
+ src = nix-filter {
+ root = src;
+
+ include = [
+ (nix-filter.matchExt "kicad_pcb")
+ (nix-filter.matchExt "kicad_pro")
+ ];
+ };
+} ''
+ mkdir -p "$out/${sharePath}"
+
+ generate_interactive_bom \
+ --dest-dir "$out/${sharePath}" \
+ ${lib.concatMapStrings (arg: "${arg} \\n") extraArgs} \
+ "$src/${pcb_path}"
+''
diff --git a/clef/nix/default.nix b/clef/nix/default.nix
index 4438bbe..419c8fd 100644
--- a/clef/nix/default.nix
+++ b/clef/nix/default.nix
@@ -36,6 +36,8 @@
svg = pkgs.callPackage ./svg.nix (pcb_args // { nLayer = layers; });
model = pkgs.callPackage ./model.nix pcb_args;
+ bom = pkgs.callPackage ./bom.nix pcb_args;
+
fabrication = pkgs.callPackage ./fabrication.nix (pcb_args // {
inherit sch_path;
});
@@ -48,6 +50,7 @@ in pkgs.callPackage ./board.nix {
inherit
svg
model
+ bom
fabrication
schematic
name
diff --git a/clef/nix/pkgs/default.nix b/clef/nix/pkgs/default.nix
new file mode 100644
index 0000000..a0a9f92
--- /dev/null
+++ b/clef/nix/pkgs/default.nix
@@ -0,0 +1,5 @@
+{
+ pkgs,
+}: {
+ interactiveHtmlBom = pkgs.callPackage ./interactive_html_bom.nix {};
+}
diff --git a/clef/nix/pkgs/interactive_html_bom.nix b/clef/nix/pkgs/interactive_html_bom.nix
new file mode 100644
index 0000000..2ed69ed
--- /dev/null
+++ b/clef/nix/pkgs/interactive_html_bom.nix
@@ -0,0 +1,62 @@
+{
+ python3Packages,
+ writeText,
+ kicad-small,
+
+ fetchFromGitHub,
+
+ version ? "v2.9.0",
+ thisSrc ? fetchFromGitHub {
+ owner = "openscopeproject";
+ repo = "interactivehtmlbom";
+ rev = version;
+ hash = "sha256-jUHEI0dWMFPQlXei3+0m1ruHzpG1hcRnxptNOXzXDqQ=";
+ },
+
+ dummySetupPy ? writeText "setup.py" ''
+ #!/usr/bin/env python3
+ # vim: set ft=python :
+
+ from setuptools import setup, find_packages
+ import sys
+
+ packages = find_packages(include=['InteractiveHtmlBom', 'InteractiveHtmlBom.*'])
+
+ setup(
+ name="InteractiveHtmlBom",
+ version='${version}',
+ packages=packages,
+ install_requires=['wxpython>=4.0', 'jsonschema>=4.1'],
+ entry_points={
+ 'console_scripts': [
+ 'generate_interactive_bom=InteractiveHtmlBom.generate_interactive_bom:main'
+ ]
+ }
+ )
+ '',
+}:
+
+let
+ src = thisSrc;
+
+in python3Packages.buildPythonApplication {
+ pname = "interactive_html_bom";
+
+ inherit
+ version
+ src
+ ;
+
+ preBuild = ''
+ cp -nv ${dummySetupPy} setup.py
+ rm pyproject.toml
+ '';
+
+ dependencies = with python3Packages; [
+ wxpython
+ jsonschema
+ kicad-small.base
+ ];
+
+ doCheck = false;
+}