config

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: MIT Imports: 17 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package config reads and writes the hub's data dir: homed.yaml, the instance id, the instance lock and the paths of the other files homed keeps there.

homed.yaml holds only what homed needs before its database opens: listen, setup_listen and the tunnel (how homed reaches the internet through Cloudflare). Plugins, people, the home name and the language live in homie.db.

listen: 127.0.0.1:8080        # loopback only; cloudflared, run by homed, forwards to it
setup_listen: 0.0.0.0:8090    # the first-run page; default: the home network while no tunnel is configured
tunnel:
  mode: named                 # named (your domain), quick (a trycloudflare.com link, for trying) or off
  hostname: home.example.com  # named only; written by `homed cloudflare connect`
  cloudflared: /usr/local/bin/cloudflared   # optional; default: PATH, then next to homed

homed.yaml is edited in place: Update rewrites only the top-level sections that changed, so comments and the order of untouched sections survive a `homed cloudflare connect`.

MigrateV01 turns a v0.1 data dir into this one: v0.1's relay section goes, and so do the phase-1 sections of a v0.1 that never ran (its homed.yaml is kept as homed.yaml.v0.1), the relay token file is deleted and a tunnel section is added.

Index

Constants

View Source
const (
	FileName       = "homed.yaml"
	InstanceIDFile = "instance-id"
	// SocketFile is the admin socket (the gatekeeper's adminsock): the homed CLI's way into the running hub.
	SocketFile = "homed.sock"
	// DBFile is the database: the gatekeeper's tables and the hub's (plugins, settings, activity).
	DBFile = "homie.db"
	// OldDBFile is v0.1's database; homed imports it once and renames it to OldDBFile + ".v0.1".
	OldDBFile = "homed.db"
	// TunnelDir holds the Cloudflare tunnel: config.yml, credentials.json and tunnel.json of a named tunnel, and the
	// private HOME of the cloudflared child.
	TunnelDir = "tunnel"
	// LogsDir holds the plugins' logs and cloudflared.log.
	LogsDir = "logs"
	// InstanceLockFile is flocked by the running homed for its whole life (LockInstance).
	InstanceLockFile = ".homed.lock"
	// V01Backup receives v0.1's homed.yaml as it was before MigrateV01 rewrote it.
	V01Backup = FileName + ".v0.1"
)

Files in the data dir.

View Source
const (
	// TunnelOff: no tunnel; the hub is not reachable from the internet (the first-run page connects one).
	TunnelOff = "off"
	// TunnelNamed: the owner's own domain through a named Cloudflare Tunnel (`homed cloudflare connect <host>`).
	TunnelNamed = "named"
	// TunnelQuick: a Cloudflare quick tunnel, a random trycloudflare.com link that changes at every restart; for trying.
	TunnelQuick = "quick"
)

Tunnel modes.

View Source
const DefaultListen = "127.0.0.1:8080"

DefaultListen is the hub's address when homed.yaml sets none.

Variables

View Source
var ErrAlreadyRunning = errors.New("homed is already running on this data dir")

ErrAlreadyRunning means another homed holds the instance lock of the data dir.

Functions

func CheckHostname

func CheckHostname(host string) error

CheckHostname reports whether host is a full lower-case host name, e.g. home.example.com.

func DataDirWarning

func DataDirWarning(dir string) string

DataDirWarning returns a warning when the data dir is readable or writable by group or others, "" otherwise. Its secret files are 0600 either way, but others could list them or, with write access, swap them.

func DefaultDataDir

func DefaultDataDir() (string, error)

DefaultDataDir is ~/Library/Application Support/homie on macOS and $XDG_DATA_HOME/homie (or ~/.local/share/homie) elsewhere.

func InstanceID

func InstanceID(dir string) (string, error)

InstanceID returns the hub's persistent random id, creating it on first use. Every answer of the public listener carries it (X-Homie-Instance), so the tunnel's self-check can tell that https://<host> reaches this hub.

func LockInstance

func LockInstance(dir string) (func(), error)

LockInstance takes the data dir's instance lock (<dir>/.homed.lock, flock, non-blocking) and returns its release func. The daemon holds it for its whole life: the kernel drops it when the process ends, crash included, so there is no stale-lock cleanup and no window in which two daemons both see "nobody runs here".

func LoopbackPort

func LoopbackPort(addr string) (int, error)

LoopbackPort checks that addr is 127.0.0.1:<port> or localhost:<port> and returns the port. cloudflared forwards to 127.0.0.1:<port> and the Host guard knows only that address, so other loopback addresses (127.0.0.2, [::1]) would leave the hub unreachable through the tunnel; nothing else should reach the hub directly.

func ResolveDataDir

func ResolveDataDir(flagValue string) (string, error)

ResolveDataDir applies the flag value, then HOMED_DATA_DIR, then the platform default. A dir it has to create is made 0700. An existing dir keeps its mode, so a mistaken --data-dir (a home dir, /var/lib) is never chmodded; the one exception is the platform default dir, which is homed's own and is tightened back to 0700. DataDirWarning reports an existing dir that is open to others.

func Update

func Update(dir string, fn func(*Config) error) error

Update loads homed.yaml under an exclusive lock, lets fn change it, validates the result and writes it back atomically (0600). Only the top-level sections fn changed are rewritten; the rest of the file, comments included, stays as it was. When fn returns an error nothing is written.

func WriteFileAtomic

func WriteFileAtomic(path string, data []byte, perm os.FileMode) error

WriteFileAtomic writes through a temp file in the same dir and renames it over path.

Types

type Config

type Config struct {
	Listen string `yaml:"listen,omitempty"`
	// SetupListen is the first-run page's address; empty means firstrun.DefaultListen (0.0.0.0:8090 while no tunnel
	// is configured, 127.0.0.1:8090 with one).
	SetupListen string `yaml:"setup_listen,omitempty"`
	Tunnel      Tunnel `yaml:"tunnel,omitempty"`
	// Relay is v0.1's relay section, read only so that an old file still loads: homed ignores it (with a warning,
	// HasRelay) and MigrateV01 removes it.
	Relay any `yaml:"relay,omitempty"`
	// HomeName, Plugins and People are v0.1's phase-1 sections. v0.1 moved them into its database at its first start,
	// so only a v0.1 data dir that never ran still has them. They are read only so that such a file still loads: homed
	// ignores them (HasPhase1) and MigrateV01 removes them, keeping them in homed.yaml.v0.1.
	HomeName any `yaml:"home_name,omitempty"`
	Plugins  any `yaml:"plugins,omitempty"`
	People   any `yaml:"people,omitempty"`
}

Config is homed.yaml.

func Load

func Load(dir string) (*Config, error)

Load reads and validates homed.yaml in dir. A missing file is an empty config. Unknown keys are errors, so a typo does not silently switch something off; v0.1's relay and phase-1 sections are the exceptions (HasRelay, HasPhase1).

func (*Config) HasPhase1

func (c *Config) HasPhase1() bool

HasPhase1 reports whether homed.yaml still has v0.1's phase-1 sections (home_name, plugins, people), which homed ignores.

func (*Config) HasRelay

func (c *Config) HasRelay() bool

HasRelay reports whether homed.yaml still has v0.1's relay section, which homed ignores.

func (*Config) ListenAddr

func (c *Config) ListenAddr() string

ListenAddr returns Listen or DefaultListen.

func (*Config) Validate

func (c *Config) Validate() error

Validate checks the whole config.

type MigrateResult

type MigrateResult struct {
	// Backup is where v0.1's homed.yaml was copied; "" when this call made no copy.
	Backup string
	// RelayRemoved is true when the relay section was removed from homed.yaml.
	RelayRemoved bool
	// Phase1Removed is true when v0.1's phase-1 sections (home_name, plugins, people) were removed from homed.yaml;
	// they are in the backup.
	Phase1Removed bool
	// TokenDeleted is true when the relay token file was deleted.
	TokenDeleted bool
}

MigrateResult says what MigrateV01 did.

func MigrateV01

func MigrateV01(dir string) (MigrateResult, error)

MigrateV01 turns a v0.1 data dir into a v0.2 one; homed calls it at every start, before Load, and it is a no-op once done. When homed.yaml has v0.1's relay section, or its phase-1 sections (a v0.1 data dir that never ran):

  1. homed.yaml as it is goes to homed.yaml.v0.1 (0600; an existing copy is kept, never overwritten);
  2. homed.yaml is rewritten without them and with a tunnel section (mode off), and, when it had a relay and set no setup_listen, with setup_listen 127.0.0.1:8090: the home had a relay, so its first-run page stays off the home network;
  3. the relay token file is deleted (also when homed.yaml had no relay left).

A crash between the steps leaves a state the next call finishes.

type Tunnel

type Tunnel struct {
	// Mode is TunnelNamed, TunnelQuick or TunnelOff; empty is off.
	Mode string `yaml:"mode,omitempty"`
	// Hostname is the named tunnel's public host, e.g. home.example.com: the passkeys' relying party and the OAuth
	// issuer. Required in named mode.
	Hostname string `yaml:"hostname,omitempty"`
	// Cloudflared is the cloudflared binary: an absolute path or a name looked up in PATH. Empty: "cloudflared" in
	// PATH, then next to the homed binary.
	Cloudflared string `yaml:"cloudflared,omitempty"`
}

Tunnel is how homed reaches the internet: cloudflared, run by homed as a child process.

func (Tunnel) Configured

func (t Tunnel) Configured() bool

Configured reports whether a tunnel is set up (named or quick). While it is not, the first-run page may listen on the home network.

func (Tunnel) ModeOrOff

func (t Tunnel) ModeOrOff() string

ModeOrOff is Mode, with empty read as TunnelOff.

Jump to

Keyboard shortcuts

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