Monorepo for Tangled

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

oppiliappan and committed by tangled.org 0c233644 d65eed2e

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