Mirror of @tangled.org/core. Running on a Raspberry Pi Zero 2

nix,dolly: subset input files to dolly derivation

this greatly improves build speed of derivations that depend on the
dolly derivation, because it no longer rebuilds everytime there is a
change to appview.

Signed-off-by: oppiliappan <me@oppi.li>

authored by oppi.li and committed by tangled.org 0c233644 d65eed2e

+48 -28
+23 -10
cmd/dolly/main.go
··· 2 3 import ( 4 "bytes" 5 "flag" 6 "fmt" 7 "image" ··· 17 "github.com/srwiley/oksvg" 18 "github.com/srwiley/rasterx" 19 "golang.org/x/image/draw" 20 - "tangled.org/core/appview/pages" 21 "tangled.org/core/ico" 22 ) 23 24 func main() { 25 var ( 26 - size string 27 - fillColor string 28 - output string 29 ) 30 31 flag.StringVar(&size, "size", "512x512", "Output size in format WIDTHxHEIGHT (e.g., 512x512)") 32 flag.StringVar(&fillColor, "color", "#000000", "Fill color in hex format (e.g., #FF5733)") 33 flag.StringVar(&output, "output", "dolly.svg", "Output file path (format detected from extension: .svg, .png, or .ico)") 34 flag.Parse() 35 36 width, height, err := parseSize(size) 37 if err != nil { ··· 59 os.Exit(1) 60 } 61 62 - svgData, err := dolly(fillColor) 63 if err != nil { 64 fmt.Fprintf(os.Stderr, "Error generating SVG: %v\n", err) 65 os.Exit(1) ··· 97 fmt.Printf("Successfully generated %s (%dx%d)\n", output, width, height) 98 } 99 100 - func dolly(hexColor string) ([]byte, error) { 101 - tpl, err := template.New("dolly"). 102 - ParseFS(pages.Files, "templates/fragments/dolly/logo.html") 103 if err != nil { 104 return nil, err 105 } 106 107 var svgData bytes.Buffer 108 - if err := tpl.ExecuteTemplate(&svgData, "fragments/dolly/logo", pages.DollyParams{ 109 - FillColor: hexColor, 110 }); err != nil { 111 return nil, err 112 }
··· 2 3 import ( 4 "bytes" 5 + _ "embed" 6 "flag" 7 "fmt" 8 "image" ··· 16 "github.com/srwiley/oksvg" 17 "github.com/srwiley/rasterx" 18 "golang.org/x/image/draw" 19 "tangled.org/core/ico" 20 ) 21 22 func main() { 23 var ( 24 + size string 25 + fillColor string 26 + output string 27 + templatePath string 28 ) 29 30 + flag.StringVar(&templatePath, "template", "", "Path to dolly go-html template") 31 flag.StringVar(&size, "size", "512x512", "Output size in format WIDTHxHEIGHT (e.g., 512x512)") 32 flag.StringVar(&fillColor, "color", "#000000", "Fill color in hex format (e.g., #FF5733)") 33 flag.StringVar(&output, "output", "dolly.svg", "Output file path (format detected from extension: .svg, .png, or .ico)") 34 flag.Parse() 35 + 36 + if templatePath == "" { 37 + fmt.Fprintf(os.Stderr, "Empty template path") 38 + os.Exit(1) 39 + } 40 41 width, height, err := parseSize(size) 42 if err != nil { ··· 52 os.Exit(1) 53 } 54 55 + tpl, err := os.ReadFile(templatePath) 56 + if err != nil { 57 + fmt.Fprintf(os.Stderr, "Failed to read template from path %s: %v\n", templatePath, err) 58 + os.Exit(1) 59 + } 60 + 61 + svgData, err := dolly(string(tpl), fillColor) 62 if err != nil { 63 fmt.Fprintf(os.Stderr, "Error generating SVG: %v\n", err) 64 os.Exit(1) ··· 84 fmt.Printf("Successfully generated %s (%dx%d)\n", output, width, height) 85 } 86 87 + func dolly(tplString, hexColor string) ([]byte, error) { 88 + tpl, err := template.New("dolly").Parse(tplString) 89 if err != nil { 90 return nil, err 91 } 92 93 var svgData bytes.Buffer 94 + if err := tpl.ExecuteTemplate(&svgData, "fragments/dolly/logo", map[string]any{ 95 + "FillColor": hexColor, 96 + "Classes": "", 97 }); err != nil { 98 return nil, err 99 }
+25 -18
nix/pkgs/dolly.nix
··· 1 { 2 buildGoApplication, 3 modules, 4 - src, 5 - }: 6 - buildGoApplication { 7 - pname = "dolly"; 8 - version = "0.1.0"; 9 - inherit src modules; 10 - 11 - # patch the static dir 12 - postUnpack = '' 13 - pushd source 14 - mkdir -p appview/pages/static 15 - touch appview/pages/static/x 16 - popd 17 - ''; 18 - 19 - doCheck = false; 20 - subPackages = ["cmd/dolly"]; 21 - }
··· 1 { 2 + lib, 3 buildGoApplication, 4 modules, 5 + writeShellScriptBin, 6 + }: let 7 + src = lib.fileset.toSource { 8 + root = ../..; 9 + fileset = lib.fileset.unions [ 10 + ../../go.mod 11 + ../../ico 12 + ../../cmd/dolly/main.go 13 + ../../appview/pages/templates/fragments/dolly/logo.html 14 + ]; 15 + }; 16 + dolly-unwrapped = buildGoApplication { 17 + pname = "dolly-unwrapped"; 18 + version = "0.1.0"; 19 + inherit src modules; 20 + doCheck = false; 21 + subPackages = ["cmd/dolly"]; 22 + }; 23 + in 24 + writeShellScriptBin "dolly" '' 25 + exec ${dolly-unwrapped}/bin/dolly \ 26 + -template ${src}/appview/pages/templates/fragments/dolly/logo.html \ 27 + "$@" 28 + ''