all repos — searchix @ fb07320a12f83ffaf80bf3c0aca94a720f865201

Search engine for NixOS, nix-darwin, home-manager and NUR users

build: just use nix version as internal version
Alan Pearce alan@alanpearce.eu
Sat, 25 May 2024 02:31:40 +0200
commit

fb07320a12f83ffaf80bf3c0aca94a720f865201

parent

4c4b980bff860dda725253438b499245338161df

M cmd/searchix-web/main.gocmd/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.gointernal/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.gointernal/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.gointernal/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.gointernal/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.gointernal/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.nixnix/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.nixnix/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;