config

package
v0.1.12 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 4, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UnknownFetcher = iota
	Channel
	ChannelNixpkgs
	Download
)
View Source
const (
	All = iota - 1
	UnknownType
	Packages
	Options
)
View Source
const (
	UnknownRepoType = iota
	GitHub
)

Variables

View Source
var DefaultConfig = Config{
	DataPath: "./data",
	Web: &Web{
		ListenAddress: "localhost",
		Port:          3000,
		BaseURL:       mustURL("http://localhost:3000"),
		Environment:   "development",
		ContentSecurityPolicy: CSP{
			DefaultSrc: []string{none},
			BaseURI:    []string{none},
			ImgSrc:     []string{self},
			StyleSrc:   []string{self},

			ScriptSrc:  []string{},
			FormAction: []string{self},
			ConnectSrc: []string{self},
		},
		Headers: map[string]string{
			"strict-transport-security": "max-age=" + strconv.FormatFloat(
				maxAge.Seconds(),
				'f',
				0,
				64,
			),
			"x-content-type-options": "nosniff",
			"x-frame-options":        "DENY",
		},
	},
	Importer: &Importer{
		LowMemory: false,
		Timeout:   Duration{30 * time.Minute},
		UpdateAt:  mustLocalTime("03:00:00"),
		Sources: map[string]*Source{
			"nixos": {
				Name:       "NixOS",
				Order:      0,
				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:  "docs.optionsJSON",
				OutputPath: "share/doc/nixos",
				Timeout:    Duration{5 * time.Minute},
				Repo:       nixpkgs,
			},
			"darwin": {
				Name:       "Darwin",
				Order:      1,
				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",
				Order:      2,
				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",
				Order:      3,
				Key:        "nixpkgs",
				Enable:     true,
				Importer:   Packages,
				Fetcher:    ChannelNixpkgs,
				Channel:    "nixos-unstable",
				OutputPath: "packages.json.br",
				Timeout:    Duration{5 * time.Minute},
				Repo:       nixpkgs,
			},
		},
	},
}
View Source
var Version string

Functions

func GetDefaultConfig

func GetDefaultConfig() string

Types

type CSP

type CSP struct {
	BaseURI                 []string                     `csp:"base-uri" toml:"base-uri"`
	BlockAllMixedContent    bool                         `csp:"block-all-mixed-content" toml:"block-all-mixed-content"`
	ChildSrc                []string                     `csp:"child-src" toml:"child-src"`
	ConnectSrc              []string                     `csp:"connect-src" toml:"connect-src"`
	DefaultSrc              []string                     `csp:"default-src" toml:"default-src"`
	FontSrc                 []string                     `csp:"font-src" toml:"font-src"`
	FormAction              []string                     `csp:"form-action" toml:"form-action"`
	FrameAncestors          []string                     `csp:"frame-ancestors" toml:"frame-ancestors"`
	FrameSrc                []string                     `csp:"frame-src" toml:"frame-src"`
	ImgSrc                  []string                     `csp:"img-src" toml:"img-src"`
	ManifestSrc             []string                     `csp:"manifest-src" toml:"manifest-src"`
	MediaSrc                []string                     `csp:"media-src" toml:"media-src"`
	NavigateTo              []string                     `csp:"navigate-to" toml:"navigate-to"`
	ObjectSrc               []string                     `csp:"object-src" toml:"object-src"`
	PluginTypes             []string                     `csp:"plugin-types" toml:"plugin-types"`
	PrefetchSrc             []string                     `csp:"prefetch-src" toml:"prefetch-src"`
	Referrer                csp.ReferrerPolicy           `csp:"referrer" toml:"referrer"`
	ReportTo                string                       `csp:"report-to" toml:"report-to"`
	ReportURI               string                       `csp:"report-uri" toml:"report-uri"`
	RequireSRIFor           []csp.RequireSRIFor          `csp:"require-sri-for" toml:"require-sri-for"`
	RequireTrustedTypesFor  []csp.RequireTrustedTypesFor `csp:"require-trusted-types-for" toml:"require-trusted-types-for"`
	Sandbox                 csp.Sandbox                  `csp:"sandbox" toml:"sandbox"`
	ScriptSrc               []string                     `csp:"script-src" toml:"script-src"`
	ScriptSrcAttr           []string                     `csp:"script-src-attr" toml:"script-src-attr"`
	ScriptSrcElem           []string                     `csp:"script-src-elem" toml:"script-src-elem"`
	StyleSrc                []string                     `csp:"style-src" toml:"style-src"`
	StyleSrcAttr            []string                     `csp:"style-src-attr" toml:"style-src-attr"`
	StyleSrcElem            []string                     `csp:"style-src-elem" toml:"style-src-elem"`
	TrustedTypes            []string                     `csp:"trusted-types" toml:"trusted-types"`
	UpgradeInsecureRequests bool                         `csp:"upgrade-insecure-requests" toml:"upgrade-insecure-requests"`
	WorkerSrc               []string                     `csp:"worker-src" toml:"worker-src"`
}

func (*CSP) String

func (c *CSP) String() string

type Config

type Config struct {
	DataPath string        `comment:"Path to store index data."`
	LogLevel zapcore.Level `comment:"How much information to log, one of 'debug', 'info', 'warn', 'error', 'panic', 'fatal'."`
	Web      *Web          `comment:"Settings for the web server"`
	Importer *Importer     `comment:"Settings for the import job"`
}

func GetConfig

func GetConfig(filename string, log *log.Logger) (*Config, error)

type Duration

type Duration struct {
	time.Duration
}

func (*Duration) MarshalText

func (d *Duration) MarshalText() ([]byte, error)

func (*Duration) UnmarshalText

func (d *Duration) UnmarshalText(text []byte) (err error)

type Fetcher

type Fetcher int

func ParseFetcher

func ParseFetcher(name string) (Fetcher, error)

func (*Fetcher) MarshalText

func (f *Fetcher) MarshalText() ([]byte, error)

func (Fetcher) String

func (f Fetcher) String() string

func (*Fetcher) UnmarshalText

func (f *Fetcher) UnmarshalText(text []byte) error

type Importer

type Importer struct {
	Sources   map[string]*Source
	LowMemory bool      `comment:"Use less memory at the expense of import performance"`
	Timeout   Duration  `comment:"Abort fetch and import process for all jobs if it takes longer than this value."`
	UpdateAt  LocalTime `comment:"Time of day (UTC) to run fetch/import process"`
}

type ImporterType

type ImporterType int

func ParseImporterType

func ParseImporterType(name string) (ImporterType, error)

func (*ImporterType) MarshalText

func (i *ImporterType) MarshalText() ([]byte, error)

func (ImporterType) Singular

func (i ImporterType) Singular() string

func (ImporterType) String

func (i ImporterType) String() string

func (*ImporterType) UnmarshalText

func (i *ImporterType) UnmarshalText(text []byte) error

type LocalTime

type LocalTime struct {
	toml.LocalTime
}

this type is necessary as nix's `fromTOML` doesn't support TOML date/time formats

func (*LocalTime) MarshalText

func (t *LocalTime) MarshalText() ([]byte, error)

func (*LocalTime) UnmarshalText

func (t *LocalTime) UnmarshalText(in []byte) (err error)

type RepoType

type RepoType int

func (*RepoType) MarshalText

func (f *RepoType) MarshalText() ([]byte, error)

func (RepoType) String

func (f RepoType) String() string

func (*RepoType) UnmarshalText

func (f *RepoType) UnmarshalText(text []byte) error

type Repository

type Repository struct {
	Type     RepoType `toml:""  default:"github" comment:"Currently only 'github' is supported."`
	Owner    string
	Repo     string
	Revision string `toml:"-"`
}

type Source

type Source struct {
	Name       string       `comment:"Human-readable name of source for generating links"`
	Order      uint         `comment:"Order in which to show source in web interface."`
	Key        string       `comment:"Machine-readable name of source. Must be URL- and path-safe."`
	Enable     bool         `comment:"Controls whether to show in the web interface and to run fetch/import jobs."`
	Fetcher    Fetcher      `comment:"How to fetch options.json. One of 'channel', 'channel-nixpkgs' or 'download'."`
	Importer   ImporterType `comment:"Kind of data available from source. Currently supports 'packages' and 'options'."`
	Channel    string       `comment:"(Fetcher=channel) Local name for channel, (Fetcher=channel-nixpkgs) Remote name of channel."`
	URL        string       `` /* 129-byte string literal not displayed */
	Attribute  string       `comment:"(Fetcher=channel) Nix attribute name (i.e. nix-build -A) that builds an {options,packages}.json"`
	ImportPath string       `comment:"(Fetcher=channel) Sub-path of imported channel which contains the attribute above, e.g. release.nix"`
	Timeout    Duration     `comment:"Abort import if it takes longer than this."`
	OutputPath string       `comment:"(Fetcher=channel) Path under ./result symlink to folder containing {options,packages}.json."`
	Repo       Repository   `comment:"Used to generate declaration/definition links"`
}

func (*Source) String

func (source *Source) String() string

type URL

type URL struct {
	*url.URL
}

func (*URL) AddRawQuery added in v0.1.8

func (u *URL) AddRawQuery(key, value string) *URL

func (*URL) JoinPath

func (u *URL) JoinPath(elems ...string) *URL

func (*URL) MarshalText

func (u *URL) MarshalText() ([]byte, error)

func (*URL) UnmarshalText

func (u *URL) UnmarshalText(text []byte) (err error)

type Web

type Web struct {
	ContentSecurityPolicy CSP               `comment:"Content-Security-Policy header to send with requests. Should only need changing if ExtraHeadHTML is used."`
	ListenAddress         string            `comment:"Which address or hostname to listen on. IPv6 addresses need square brackets."`
	Port                  int               `comment:"Port number to listen on."`
	BaseURL               URL               `comment:"Absolute URL to this instance, useful if behind a reverse proxy"`
	SentryDSN             string            `comment:"If set, will send server errors to Sentry"`
	Environment           string            `comment:"Affects logging parameters. One of 'development' or 'production'"`
	ExtraHeadHTML         string            `comment:"Content to add to HTML <head>. Can be used to override styling, add scripts, etc."`
	Headers               map[string]string `comment:"Extra headers to send with HTTP requests"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL