diff options
| author | Nathan Perry <np@nathanperry.dev> | 2024-08-15 04:25:39 -0400 |
|---|---|---|
| committer | Nathan Perry <np@nathanperry.dev> | 2024-08-15 04:25:39 -0400 |
| commit | f081aa9e2f243ffe6ea13024e3777626a8243aed (patch) | |
| tree | c1ec687b1953a7f3e78d667ba09fbb5872917b50 /clef/nix | |
| parent | 9332cf7c0eac27ed5c00ec19e87d4d76b56f223a (diff) | |
clef/nix: support generating interactivehtmlbom
Diffstat (limited to 'clef/nix')
| -rw-r--r-- | clef/nix/board.nix | 14 | ||||
| -rw-r--r-- | clef/nix/bom.nix | 38 | ||||
| -rw-r--r-- | clef/nix/default.nix | 3 | ||||
| -rw-r--r-- | clef/nix/pkgs/default.nix | 5 | ||||
| -rw-r--r-- | clef/nix/pkgs/interactive_html_bom.nix | 62 |
5 files changed, 116 insertions, 6 deletions
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; +} |
