diff --git a/flake.nix b/flake.nix index e16937c9..e886c01b 100644 --- a/flake.nix +++ b/flake.nix @@ -25,6 +25,57 @@ # Python with required packages for build scripts pythonEnv = pkgs.python3.withPackages (ps: [ ps.pip ]); + # Python environment for fontconvert script + fontconvertPython = pkgs.python3.withPackages (ps: [ ps.freetype-py ]); + + # Wrapper script for fontconvert.py + fontconvertScript = pkgs.writeShellScriptBin "fontconvert" '' + exec ${fontconvertPython}/bin/python3 ${./lib/EpdFont/scripts/fontconvert.py} "$@" + ''; + + # Script to convert all builtin fonts + convertBuiltinFontsScript = pkgs.writeShellScriptBin "convert-builtin-fonts" '' + set -e + if [ ! -d "lib/EpdFont/scripts" ]; then + echo "Error: must be run from the project root (where platformio.ini is)" + exit 1 + fi + export PATH="${fontconvertPython}/bin:$PATH" + cd lib/EpdFont/scripts + exec ${pkgs.bash}/bin/bash ./convert-builtin-fonts.sh + ''; + + # Script to build font IDs (requires Ruby for SHA256 hashing) + buildFontIdsScript = pkgs.writeShellScriptBin "build-font-ids" '' + set -e + if [ ! -d "lib/EpdFont/scripts" ]; then + echo "Error: must be run from the project root (where platformio.ini is)" + exit 1 + fi + export PATH="${pkgs.ruby}/bin:$PATH" + cd lib/EpdFont/scripts + exec ${pkgs.bash}/bin/bash ./build-font-ids.sh "$@" + ''; + + # Combined script to regenerate all fonts (run after editing fontconvert.py) + regenerateFontsScript = pkgs.writeShellScriptBin "regenerate-fonts" '' + set -e + if [ ! -d "lib/EpdFont/scripts" ]; then + echo "Error: must be run from the project root (where platformio.ini is)" + exit 1 + fi + export PATH="${fontconvertPython}/bin:${pkgs.ruby}/bin:$PATH" + echo "Regenerating all builtin fonts..." + cd lib/EpdFont/scripts + ${pkgs.bash}/bin/bash ./convert-builtin-fonts.sh + echo "" + echo "Building font IDs..." + ${pkgs.bash}/bin/bash ./build-font-ids.sh > ../builtinFonts/font_ids.h + echo "Generated lib/EpdFont/builtinFonts/font_ids.h" + echo "" + echo "Done! All fonts regenerated." + ''; + # FHS environment to run PlatformIO with dynamically linked toolchains fhsEnv = pkgs.buildFHSEnv { name = "pio-env"; @@ -115,6 +166,26 @@ type = "app"; program = "${buildScript}/bin/build-firmware"; }; + + apps.fontconvert = { + type = "app"; + program = "${fontconvertScript}/bin/fontconvert"; + }; + + apps.convert-builtin-fonts = { + type = "app"; + program = "${convertBuiltinFontsScript}/bin/convert-builtin-fonts"; + }; + + apps.build-font-ids = { + type = "app"; + program = "${buildFontIdsScript}/bin/build-font-ids"; + }; + + apps.regenerate-fonts = { + type = "app"; + program = "${regenerateFontsScript}/bin/regenerate-fonts"; + }; }; }; }