about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAlan Pearce2024-05-30 10:24:02 +0200
committerAlan Pearce2024-05-30 10:24:02 +0200
commitb02076363f979daa6ac313058eb140d1d67ce184 (patch)
tree99e3f803d1c737e6bab1b34d9605625b97d8f1f5
parentf3d97c5bd45bca868417d76196680288ae2d05ff (diff)
downloadsearchix-b02076363f979daa6ac313058eb140d1d67ce184.tar.lz
searchix-b02076363f979daa6ac313058eb140d1d67ce184.tar.zst
searchix-b02076363f979daa6ac313058eb140d1d67ce184.zip
refactor: extract default config to own file
-rw-r--r--internal/config/config.go98
-rw-r--r--internal/config/default.go105
2 files changed, 105 insertions, 98 deletions
diff --git a/internal/config/config.go b/internal/config/config.go
index 1ba5825..81c5f3c 100644
--- a/internal/config/config.go
+++ b/internal/config/config.go
@@ -90,104 +90,6 @@ func mustLocalTime(in string) (time LocalTime) {
 	return
 }
 
-var nixpkgs = Repository{
-	Type:  GitHub,
-	Owner: "NixOS",
-	Repo:  "nixpkgs",
-}
-
-var defaultConfig = Config{
-	DataPath: "./data",
-	Web: &Web{
-		ListenAddress: "localhost",
-		Port:          3000,
-		BaseURL:       mustURL("http://localhost:3000"),
-		Environment:   "development",
-		ContentSecurityPolicy: CSP{
-			DefaultSrc: []string{"'self'"},
-		},
-		Headers: map[string]string{
-			"x-content-type-options": "nosniff",
-		},
-	},
-	Importer: &Importer{
-		Timeout:  Duration{30 * time.Minute},
-		UpdateAt: mustLocalTime("04:00:00"),
-		Sources: map[string]*Source{
-			"nixos": {
-				Name:       "NixOS",
-				Key:        "nixos",
-				Enable:     true,
-				Importer:   Options,
-				Fetcher:    Channel,
-				Channel:    "nixpkgs",
-				URL:        "https://channels.nixos.org/nixos-unstable/nixexprs.tar.xz",
-				ImportPath: "nixos/release.nix",
-				Attribute:  "options",
-				OutputPath: "share/doc/nixos",
-				Timeout:    Duration{5 * time.Minute},
-				Repo:       nixpkgs,
-			},
-			"darwin": {
-				Name:       "Darwin",
-				Key:        "darwin",
-				Enable:     false,
-				Importer:   Options,
-				Fetcher:    Channel,
-				Channel:    "darwin",
-				URL:        "https://github.com/LnL7/nix-darwin/archive/master.tar.gz",
-				ImportPath: "release.nix",
-				Attribute:  "options",
-				OutputPath: "share/doc/darwin",
-				Timeout:    Duration{5 * time.Minute},
-				Repo: Repository{
-					Type:  GitHub,
-					Owner: "LnL7",
-					Repo:  "nix-darwin",
-				},
-			},
-			"home-manager": {
-				Name:       "Home Manager",
-				Key:        "home-manager",
-				Enable:     false,
-				Importer:   Options,
-				Channel:    "home-manager",
-				URL:        "https://github.com/nix-community/home-manager/archive/master.tar.gz",
-				Fetcher:    Channel,
-				ImportPath: "default.nix",
-				Attribute:  "docs.json",
-				OutputPath: "share/doc/home-manager",
-				Timeout:    Duration{5 * time.Minute},
-				Repo: Repository{
-					Type:  GitHub,
-					Owner: "nix-community",
-					Repo:  "home-manager",
-				},
-			},
-			"nixpkgs": {
-				Name:       "Nix Packages",
-				Key:        "nixpkgs",
-				Enable:     true,
-				Importer:   Packages,
-				Fetcher:    ChannelNixpkgs,
-				Channel:    "nixos-unstable",
-				OutputPath: "packages.json.br",
-				Timeout:    Duration{5 * time.Minute},
-				Repo:       nixpkgs,
-			},
-		},
-	},
-}
-
-func GetDefaultConfig() string {
-	out, err := toml.Marshal(&defaultConfig)
-	if err != nil {
-		panic("could not read default configuration")
-	}
-
-	return string(out)
-}
-
 func GetConfig(filename string) (*Config, error) {
 	config := defaultConfig
 	if filename != "" {
diff --git a/internal/config/default.go b/internal/config/default.go
new file mode 100644
index 0000000..370057e
--- /dev/null
+++ b/internal/config/default.go
@@ -0,0 +1,105 @@
+package config
+
+import (
+	"time"
+
+	"github.com/pelletier/go-toml/v2"
+)
+
+var nixpkgs = Repository{
+	Type:  GitHub,
+	Owner: "NixOS",
+	Repo:  "nixpkgs",
+}
+
+var defaultConfig = Config{
+	DataPath: "./data",
+	Web: &Web{
+		ListenAddress: "localhost",
+		Port:          3000,
+		BaseURL:       mustURL("http://localhost:3000"),
+		Environment:   "development",
+		ContentSecurityPolicy: CSP{
+			DefaultSrc: []string{"'self'"},
+		},
+		Headers: map[string]string{
+			"x-content-type-options": "nosniff",
+		},
+	},
+	Importer: &Importer{
+		Timeout:  Duration{30 * time.Minute},
+		UpdateAt: mustLocalTime("04:00:00"),
+		Sources: map[string]*Source{
+			"nixos": {
+				Name:       "NixOS",
+				Key:        "nixos",
+				Enable:     true,
+				Importer:   Options,
+				Fetcher:    Channel,
+				Channel:    "nixpkgs",
+				URL:        "https://channels.nixos.org/nixos-unstable/nixexprs.tar.xz",
+				ImportPath: "nixos/release.nix",
+				Attribute:  "options",
+				OutputPath: "share/doc/nixos",
+				Timeout:    Duration{5 * time.Minute},
+				Repo:       nixpkgs,
+			},
+			"darwin": {
+				Name:       "Darwin",
+				Key:        "darwin",
+				Enable:     false,
+				Importer:   Options,
+				Fetcher:    Channel,
+				Channel:    "darwin",
+				URL:        "https://github.com/LnL7/nix-darwin/archive/master.tar.gz",
+				ImportPath: "release.nix",
+				Attribute:  "options",
+				OutputPath: "share/doc/darwin",
+				Timeout:    Duration{5 * time.Minute},
+				Repo: Repository{
+					Type:  GitHub,
+					Owner: "LnL7",
+					Repo:  "nix-darwin",
+				},
+			},
+			"home-manager": {
+				Name:       "Home Manager",
+				Key:        "home-manager",
+				Enable:     false,
+				Importer:   Options,
+				Channel:    "home-manager",
+				URL:        "https://github.com/nix-community/home-manager/archive/master.tar.gz",
+				Fetcher:    Channel,
+				ImportPath: "default.nix",
+				Attribute:  "docs.json",
+				OutputPath: "share/doc/home-manager",
+				Timeout:    Duration{5 * time.Minute},
+				Repo: Repository{
+					Type:  GitHub,
+					Owner: "nix-community",
+					Repo:  "home-manager",
+				},
+			},
+			"nixpkgs": {
+				Name:       "Nix Packages",
+				Key:        "nixpkgs",
+				Enable:     true,
+				Importer:   Packages,
+				Fetcher:    ChannelNixpkgs,
+				Channel:    "nixos-unstable",
+				OutputPath: "packages.json.br",
+				Timeout:    Duration{5 * time.Minute},
+				Repo:       nixpkgs,
+			},
+		},
+	},
+}
+
+func GetDefaultConfig() string {
+	out, err := toml.Marshal(&defaultConfig)
+	if err != nil {
+		panic("could not read default configuration")
+	}
+
+	return string(out)
+}