From 0c23364495fcf31716c2d3284ce0ac4c70f089f1 Mon Sep 17 00:00:00 2001 From: oppiliappan Date: Mon, 19 Jan 2026 06:37:29 +0000 Subject: [PATCH] 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 --- cmd/dolly/main.go | 33 +++++++++++++++++++++++---------- nix/pkgs/dolly.nix | 43 +++++++++++++++++++++++++------------------ 2 file(s) changed, 48 insertion(s)(+), 28 deletion(s)(-) diff --git a/cmd/dolly/main.go b/cmd/dolly/main.go --- a/cmd/dolly/main.go +++ b/cmd/dolly/main.go @@ -2,6 +2,7 @@ package main import ( "bytes" + _ "embed" "flag" "fmt" "image" @@ -16,21 +17,27 @@ "github.com/srwiley/oksvg" "github.com/srwiley/rasterx" "golang.org/x/image/draw" - "tangled.org/core/appview/pages" "tangled.org/core/ico" ) func main() { var ( - size string - fillColor string - output string + size string + fillColor string + output string + templatePath string ) + flag.StringVar(&templatePath, "template", "", "Path to dolly go-html template") flag.StringVar(&size, "size", "512x512", "Output size in format WIDTHxHEIGHT (e.g., 512x512)") flag.StringVar(&fillColor, "color", "#000000", "Fill color in hex format (e.g., #FF5733)") flag.StringVar(&output, "output", "dolly.svg", "Output file path (format detected from extension: .svg, .png, or .ico)") flag.Parse() + + if templatePath == "" { + fmt.Fprintf(os.Stderr, "Empty template path") + os.Exit(1) + } width, height, err := parseSize(size) if err != nil { @@ -52,7 +59,13 @@ fmt.Fprintf(os.Stderr, "Invalid color format: %s. Use hex format like #FF5733\n", fillColor) os.Exit(1) } - svgData, err := dolly(fillColor) + tpl, err := os.ReadFile(templatePath) + if err != nil { + fmt.Fprintf(os.Stderr, "Failed to read template from path %s: %v\n", templatePath, err) + os.Exit(1) + } + + svgData, err := dolly(string(tpl), fillColor) if err != nil { fmt.Fprintf(os.Stderr, "Error generating SVG: %v\n", err) os.Exit(1) @@ -84,16 +97,16 @@ fmt.Printf("Successfully generated %s (%dx%d)\n", output, width, height) } -func dolly(hexColor string) ([]byte, error) { - tpl, err := template.New("dolly"). - ParseFS(pages.Files, "templates/fragments/dolly/logo.html") +func dolly(tplString, hexColor string) ([]byte, error) { + tpl, err := template.New("dolly").Parse(tplString) if err != nil { return nil, err } var svgData bytes.Buffer - if err := tpl.ExecuteTemplate(&svgData, "fragments/dolly/logo", pages.DollyParams{ - FillColor: hexColor, + if err := tpl.ExecuteTemplate(&svgData, "fragments/dolly/logo", map[string]any{ + "FillColor": hexColor, + "Classes": "", }); err != nil { return nil, err } diff --git a/nix/pkgs/dolly.nix b/nix/pkgs/dolly.nix --- a/nix/pkgs/dolly.nix +++ b/nix/pkgs/dolly.nix @@ -1,21 +1,28 @@ { + lib, buildGoApplication, modules, - src, -}: -buildGoApplication { - pname = "dolly"; - version = "0.1.0"; - inherit src modules; - - # patch the static dir - postUnpack = '' - pushd source - mkdir -p appview/pages/static - touch appview/pages/static/x - popd - ''; - - doCheck = false; - subPackages = ["cmd/dolly"]; -} + writeShellScriptBin, +}: let + src = lib.fileset.toSource { + root = ../..; + fileset = lib.fileset.unions [ + ../../go.mod + ../../ico + ../../cmd/dolly/main.go + ../../appview/pages/templates/fragments/dolly/logo.html + ]; + }; + dolly-unwrapped = buildGoApplication { + pname = "dolly-unwrapped"; + version = "0.1.0"; + inherit src modules; + doCheck = false; + subPackages = ["cmd/dolly"]; + }; +in + writeShellScriptBin "dolly" '' + exec ${dolly-unwrapped}/bin/dolly \ + -template ${src}/appview/pages/templates/fragments/dolly/logo.html \ + "$@" + '' -- tangled.sh