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