about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAlan Pearce2024-05-09 18:18:59 +0200
committerAlan Pearce2024-05-09 19:27:57 +0200
commitfbc4c583a4e2759d6b8cdbb98de2c769918ddac8 (patch)
tree2b5bd7317e426746781071f771f5ad7979988503
parent8d5dfd90332facb2613b927cf32472915f87359d (diff)
downloadsearchix-fbc4c583a4e2759d6b8cdbb98de2c769918ddac8.tar.lz
searchix-fbc4c583a4e2759d6b8cdbb98de2c769918ddac8.tar.zst
searchix-fbc4c583a4e2759d6b8cdbb98de2c769918ddac8.zip
docs: embed defaults in app
-rw-r--r--config.toml29
-rw-r--r--import/main.go11
-rw-r--r--internal/config/config.go50
3 files changed, 45 insertions, 45 deletions
diff --git a/config.toml b/config.toml
index b865415..999c486 100644
--- a/config.toml
+++ b/config.toml
@@ -1,38 +1,9 @@
 [sources.nixos]
-  name = "NixOS"
   enable = true
-  type = "channel"
   channel = "nixos-unstable"
-  import-path = "nixos/release.nix"
-  attribute = "options"
-  output-path = "share/doc/nixos/options.json"
-  [sources.repo]
-    type = "github"
-    owner = "NixOS"
-    repo = "nixpkgs"
 
 [sources.darwin]
-  name = "darwin"
   enable = true
-  type = "channel"
-  channel = "darwin"
-  import-path = "release.nix"
-  attribute = "options"
-  output-path = "share/doc/darwin/options.json"
-  [sources.repo]
-    type = "github"
-    owner = "LnL7"
-    repo = "nix-darwin"
 
 [sources.home-manager]
-  name = "home-manager"
   enable = true
-  type = "channel"
-  channel = "home-manager"
-  import-path = "default.nix"
-  attribute = "docs.json"
-  output-path = "share/doc/home-manager/options.json"
-  [sources.repo]
-    type = "github"
-    owner = "nix-community"
-    repo = "home-manager"
diff --git a/import/main.go b/import/main.go
index de652c5..1e6b87d 100644
--- a/import/main.go
+++ b/import/main.go
@@ -11,7 +11,6 @@ import (
 	"searchix/internal/config"
 	"searchix/internal/importer"
 	"searchix/internal/search"
-	"slices"
 	"strings"
 	"time"
 )
@@ -27,11 +26,7 @@ func main() {
 		log.Fatal(err)
 	}
 
-	enabledSources := slices.DeleteFunc(cfg.Sources, func(s importer.Source) bool {
-		return !s.Enable
-	})
-
-	if len(enabledSources) == 0 {
+	if len(cfg.Sources) == 0 {
 		slog.Info("No sources enabled")
 
 		return
@@ -47,8 +42,8 @@ func main() {
 
 	var imp importer.Importer
 	var hadErrors bool
-	for _, source := range enabledSources {
-		logger := slog.With("name", source.Name, "importer", source.Type.String())
+	for name, source := range cfg.Sources {
+		logger := slog.With("name", name, "importer", source.Type.String())
 		logger.Debug("starting importer")
 
 		switch source.Type {
diff --git a/internal/config/config.go b/internal/config/config.go
index 94bf60e..2cf5def 100644
--- a/internal/config/config.go
+++ b/internal/config/config.go
@@ -7,6 +7,7 @@ import (
 	"os"
 	"searchix/internal/file"
 	"searchix/internal/importer"
+	"time"
 
 	"github.com/pelletier/go-toml/v2"
 	"github.com/pkg/errors"
@@ -42,20 +43,53 @@ var defaultConfig = Config{
 		"x-content-type-options": "nosniff",
 	},
 	Sources: map[string]importer.Source{
-		"nixos": importer.Source{
-			Name:       "NixOS",
-			Enable:     true,
-			Type:       importer.Channel,
-			Channel:    "nixos-unstable",
-			ImportPath: "nixos/release.nix",
-			Attribute:  "options",
-			OutputPath: "share/doc/nixos/options.json",
+		"nixos": {
+			Name:          "NixOS",
+			Enable:        true,
+			Type:          importer.Channel,
+			Channel:       "nixpkgs",
+			ImportPath:    "nixos/release.nix",
+			Attribute:     "options",
+			OutputPath:    "share/doc/nixos/options.json",
+			FetchTimeout:  5 * time.Minute,
+			ImportTimeout: 15 * time.Minute,
 			Repo: importer.Repository{
 				Type:  "github",
 				Owner: "NixOS",
 				Repo:  "nixpkgs",
 			},
 		},
+		"darwin": {
+			Name:          "darwin",
+			Enable:        false,
+			Type:          importer.Channel,
+			Channel:       "nix-darwin",
+			ImportPath:    "release.nix",
+			Attribute:     "options",
+			OutputPath:    "share/doc/darwin/options.json",
+			FetchTimeout:  5 * time.Minute,
+			ImportTimeout: 15 * time.Minute,
+			Repo: importer.Repository{
+				Type:  "github",
+				Owner: "LnL7",
+				Repo:  "nix-darwin",
+			},
+		},
+		"home-manager": {
+			Name:          "home-manager",
+			Enable:        false,
+			Type:          importer.Channel,
+			ImportPath:    "default.nix",
+			Attribute:     "docs.json",
+			OutputPath:    "share/doc/home-manager/options.json",
+			FetchTimeout:  5 * time.Minute,
+			ImportTimeout: 15 * time.Minute,
+			Repo: importer.Repository{
+				Type:  "github",
+				Owner: "nix-community",
+				Repo:  "home-manager",
+			},
+		},
 	},
 }