bonito

package
v0.0.0-...-dd43fab Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2024 License: GPL-3.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ChannelResolvers = map[string]ChannelResolver{
	"git":     resolveGit,
	"github":  resolveGit,
	"gitlab":  resolveGit,
	"gitsrht": resolveGit,
}

ChannelResolvers maps URL schemes to resolvers.

Functions

func CombineChannelRegistries

func CombineChannelRegistries(registries []ChannelRegistry) (map[string]ChannelInput, error)

CombineChannelRegistries combines the given ChannelRegistries into a single channel input map. It also resolves the aliases. Channels defined later in the list will override the ones defined earlier.

func WithVerbose

func WithVerbose(ctx context.Context) context.Context

WithVerbose enables verbose mode for all invokations that use the returned context.

Types

type ChannelInput

type ChannelInput struct {
	// URL is the source URL of the channel.
	URL ChannelURL
	// Version is the respective version string corresponding to the VCS defined
	// in the channel URL. For example, if the VCS is Git, then the URL's scheme
	// might be git+https, and the version string would imply a branch name,
	// tag, or commit hash.
	//
	// If the Version string is empty, then it is not included in the marshaled
	// text at all.
	Version string
}

ChannelInput is the input declaration of a channel. It is marshaled to TOML as a string of two parts, the URL and the version, separated by a space.

func ParseChannelInput

func ParseChannelInput(chInput string) (ChannelInput, error)

ParseChannelInput parses the channel input string into ChannelInput.

func (ChannelInput) CanResolve

func (in ChannelInput) CanResolve() bool

CanResolve returns true if the channel input's URL scheme is recognized.

func (ChannelInput) MarshalJSON

func (in ChannelInput) MarshalJSON() ([]byte, error)

func (ChannelInput) MarshalText

func (in ChannelInput) MarshalText() ([]byte, error)

func (ChannelInput) Resolve

func (in ChannelInput) Resolve(ctx context.Context) (string, error)

Resolve resolves the channel input using one of the ChannelResolvers.

func (ChannelInput) String

func (in ChannelInput) String() string

String returns the ChannelInput formatted as a string.

func (*ChannelInput) UnmarshalJSON

func (in *ChannelInput) UnmarshalJSON(b []byte) error

func (*ChannelInput) UnmarshalText

func (in *ChannelInput) UnmarshalText(text []byte) error

type ChannelLock

type ChannelLock struct {
	// URL is the resolved channel URL that's used for Nix. This URL must always
	// point to the same file, and the store hash guarantees that.
	URL string `json:"url"`
	// StoreHash is the hash part of the /nix/store output path of the channel.
	StoreHash nixutil.StoreHash `json:"store_hash"`
	// StorePath is the path of the /nix/store output path of the channel.
	StorePath string `json:"store_path,omitempty"`
}

ChannelLock describes the locking checksums for a single channel.

func (ChannelLock) HashChanged

func (l ChannelLock) HashChanged(newer ChannelLock) bool

HashChanged returns true if the channel URL is the same, but the store hash is different.

type ChannelRegistry

type ChannelRegistry struct {
	// Channels maps the channel names to its respective input strings.
	Channels map[string]ChannelInput `toml:"channels"`
	// Aliases maps a channel name to another channel name as aliases. The
	// aliasing channel will have the same channel input as the aliased.
	Aliases map[string]string `toml:"aliases"`
}

ChannelRegistry is a common structure holding configured channels and its aliases.

func (ChannelRegistry) FilterChannels

func (r ChannelRegistry) FilterChannels(names []string) ChannelRegistry

FilterChannels returns a new ChannelRegistry with only the channels that are present in the given names.

type ChannelResolver

type ChannelResolver func(context.Context, ChannelInput) (string, error)

ChannelResolver is a function type that resolves a channel URL to the URL that's actually used for adding into nix-channel.

type ChannelURL

type ChannelURL string

ChannelURL is the URL to the source of a channel.

func (ChannelURL) Parse

func (u ChannelURL) Parse() (*url.URL, error)

Parse parses the channel URL string. An invalid URL will cause an error.

func (ChannelURL) Validate

func (u ChannelURL) Validate() error

Validate validates the ChannelURL string.

type Config

type Config struct {
	// Global is the global channels.
	Global struct {
		// PreferredUser is the preferred user to use for nix-channel invocations.
		// If this is empty, then it will be picked automatically.
		PreferredUser string `toml:"preferred_user,omitempty"`
		ChannelRegistry
	} `toml:"global"`

	// Flakes is the flakes channels.
	Flakes struct {
		Enable bool   `toml:"enable"`
		Output string `toml:"output"` // ("nix") or "flakes"
		ChannelRegistry
	} `toml:"flakes"`

	// Users maps the usernames to their respective UserConfig.
	Users map[Username]UserConfig `toml:"users"`
}

Config is the root structure of the host configuration file. It maps the usernames to their corresponding config.

func NewConfigFromReader

func NewConfigFromReader(r io.Reader) (Config, error)

NewConfigFromReader creates a new Config by decoding the given reader as a TOML file.

func (Config) ChannelInputs

func (cfg Config) ChannelInputs() map[ChannelInput]struct{}

ChannelInputs returns all channel inputs within the current config.

func (Config) FilterChannels

func (cfg Config) FilterChannels(names []string) Config

FilterChannels returns a new Config with only the channels that are present in the given names.

func (Config) UserChannels

func (cfg Config) UserChannels(user string) (map[string]ChannelInput, error)

UserChannels returns the ChannelRegistry for the given user combined with the global channels.

type LockFile

type LockFile struct {
	// Channels maps channel URLs to its lock.
	Channels map[ChannelInput]ChannelLock `json:"channels"`
}

LockFile describes a file containing hashes (or checksums) of the channels fetched.

func NewLockFileFromReader

func NewLockFileFromReader(r io.Reader) (LockFile, error)

NewLockFileFromReader creates a new LockFile containing data from the given reader parsed as JSON.

func (LockFile) Eq

func (l LockFile) Eq(old LockFile) bool

Eq returns true if l == old.

func (LockFile) String

func (l LockFile) String() string

String formats the LockFile as a pretty JSON string.

func (*LockFile) Update

func (l *LockFile) Update(newer LockFile)

Update updates the lock file to have hashes from the given LockFile.

type State

type State struct {
	Config Config
	Lock   LockFile
}

State encapsulates the current configuration and the locks of it. A State can be applied onto the current system.

func (*State) Apply

func (s *State) Apply(ctx context.Context) error

Apply applies the state onto the current system.

func (*State) GenerateNixRegistry

func (s *State) GenerateNixRegistry() (json.RawMessage, error)

GenerateNixRegistry generates the nix.registry attributes as JSON for the current configuration.

func (*State) Update

func (s *State) Update(ctx context.Context) error

Update updates the inputs and locks for the current configuration. It is not to be confused with UpdateLocks which only updates the lock hashes, UpdateInputs will also update the input URLs to the latest versions.

func (*State) UpdateLocks

func (s *State) UpdateLocks(ctx context.Context) error

UpdateLocks updates just the locks for the current configuration.

type UserConfig

type UserConfig struct {
	// UseSudo, if true, will use sudo if the current user is not the user that
	// this config belongs to. If it's false and the current user is not this
	// user, then an error will be thrown.
	UseSudo bool `toml:"use-sudo"`
	// OverrideChannels, if true, will cause all channels not defined in the
	// configuration file to be deleted.
	OverrideChannels bool `toml:"override-channels"`
	ChannelRegistry
}

UserConfig is the structure of the user configuration.

type Username

type Username = string

Username is the name of the user in a local machine. It is a type alias for documentation purposes.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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