build: just use nix version as internal version
Alan Pearce alan@alanpearce.eu
Sat, 25 May 2024 02:31:40 +0200
8 files changed, 6 insertions(+), 38 deletions(-)
M cmd/searchix-web/main.go → cmd/searchix-web/main.go
@@ -13,8 +13,6 @@ "searchix" "searchix/internal/config" ) -var buildVersion string - var ( configFile = flag.String("config", "config.toml", "config `file` to use") printDefaultConfig = flag.Bool( @@ -31,11 +29,7 @@ func main() { flag.Parse() if *version { - fmt.Fprintf(os.Stderr, "searchix %s", buildVersion) - if buildVersion != config.CommitSHA && buildVersion != config.ShortSHA { - fmt.Fprintf(os.Stderr, " %s", config.CommitSHA) - } - _, err := fmt.Fprint(os.Stderr, "\n") + _, err := fmt.Fprintf(os.Stderr, "searchix %s\n", config.Version) if err != nil { panic("can't write to standard error?!") }
M internal/config/config.go → internal/config/config.go
@@ -11,10 +11,7 @@ "github.com/pelletier/go-toml/v2" "github.com/pkg/errors" ) -var ( - CommitSHA string - ShortSHA string -) +var Version string type URL struct { *url.URL
M internal/fetcher/http.go → internal/fetcher/http.go
@@ -47,7 +47,7 @@ return } - req.Header.Set("User-Agent", fmt.Sprintf("Searchix %s", config.ShortSHA)) + req.Header.Set("User-Agent", fmt.Sprintf("Searchix %s", config.Version)) if ifModifiedSince != "" { req.Header.Set("If-Modified-Since", ifModifiedSince)
M internal/server/error.go → internal/server/error.go
@@ -17,7 +17,6 @@ } indexData := TemplateData{ ExtraHeadHTML: config.Web.ExtraHeadHTML, Sources: config.Importer.Sources, - Version: *versionInfo, Code: code, Message: message, }
M internal/server/headers.go → internal/server/headers.go
@@ -11,7 +11,7 @@ for h, v := range config.Web.Headers { w.Header().Add(h, v) } w.Header().Add("Content-Security-Policy", config.Web.ContentSecurityPolicy.String()) - w.Header().Add("Server", "searchix/"+cfg.ShortSHA) + w.Header().Add("Server", "searchix/"+cfg.Version) next.ServeHTTP(w, r) })
M internal/server/mux.go → internal/server/mux.go
@@ -34,11 +34,6 @@ } const jsSnippet = template.HTML(livereload.JsSnippet) // #nosec G203 -type VersionInfo struct { - ShortSHA string - CommitSHA string -} - type TemplateData struct { Sources map[string]*config.Source Source config.Source @@ -46,7 +41,6 @@ Query string Results bool SourceResult *bleve.SearchResult ExtraHeadHTML template.HTML - Version VersionInfo Code int Message string } @@ -60,11 +54,6 @@ Prev string Next string } -var versionInfo = &VersionInfo{ - ShortSHA: config.ShortSHA, - CommitSHA: config.CommitSHA, -} - var templates TemplateCollection func applyDevModeOverrides(cfg *config.Config) { @@ -105,7 +94,6 @@ mux.HandleFunc("/{$}", func(w http.ResponseWriter, r *http.Request) { indexData := TemplateData{ ExtraHeadHTML: cfg.Web.ExtraHeadHTML, Sources: cfg.Importer.Sources, - Version: *versionInfo, } w.Header().Add("Cache-Control", "max-age=86400") err := templates["index"].Execute(w, indexData) @@ -154,7 +142,6 @@ TemplateData: TemplateData{ ExtraHeadHTML: cfg.Web.ExtraHeadHTML, Source: *source, Sources: cfg.Importer.Sources, - Version: *versionInfo, }, ResultsPerPage: search.ResultsPerPage, Query: qs, @@ -218,7 +205,6 @@ ExtraHeadHTML: cfg.Web.ExtraHeadHTML, Sources: cfg.Importer.Sources, Source: *source, SourceResult: sourceResult, - Version: *versionInfo, }) if err != nil { errorHandler(w, r, err.Error(), http.StatusInternalServerError)
M nix/package.nix → nix/package.nix
@@ -11,12 +11,8 @@ } ) , buildGoApplication ? pkgs.buildGoApplication , css -, self -, testers }: let - inherit (builtins) concatStringsSep match; - version = "0.1.4"; in buildGoApplication { @@ -47,11 +43,7 @@ ldflags = [ "-s" "-w" "-X" - "searchix/internal/config.CommitSHA=${self.rev or self.dirtyRev or "unknown"}" - "-X" - "searchix/internal/config.ShortSHA=${self.shortRev or self.dirtyShortRev or "unknown"}" - "-X" - "main.buildVersion=${version}" + "searchix/internal/config.Version=${version}" ]; modules = ../gomod2nix.toml;
M nix/pre-commit-checks.nix → nix/pre-commit-checks.nix
@@ -107,7 +107,7 @@ types_or = [ "go" "toml" ]; entry = let script = pkgs.writeShellScript "generate-default-config" '' - ${pkgs.wgo}/bin/wgo run -exit searchix.go --print-default-config > defaults.toml + ${pkgs.wgo}/bin/wgo run -exit ./cmd/searchix-web --print-default-config > defaults.toml ''; in builtins.toString script;