Skip to content

sow init

Create a workspace for standard repositories, or create the repositories and Dists that sow.yml declares but that do not exist yet.

sow init turns a directory into a workspace, the home of one or more standard repositories: it creates the private .sow/ state directory, reads an existing sow.yml or sow.yaml, and writes a default sow.yml if neither configuration file exists. If the configuration already declares repositories and Dists, it creates the ones that are missing, so you can write sow.yml first (or keep it in version control) and let init build everything it describes. It is safe to rerun at any time. To add one repository or Dist to an existing workspace, sow repo new and sow dist new do the same work for a single object.

Synopsis

sow init [DIR] [--json] [--passfile PATH]

DIR defaults to the current directory. init takes the directory as an argument; it does not accept -C/--workdir. An existing workspace configured with either sow.yml or sow.yaml is accepted.

Options

Flag Description Default
--passfile PATH Password file for this invocation per-key config, then SOW_GPG_PASSFILE
--json Output JSON false
-h, --help Show help —

Examples

Start an empty workspace in the current directory:

sow init .
initialized /srv/repo: config_created=true repositories_initialized=0 dists_initialized=0
cat sow.yml
schema: sow/v3
architectures:
  - x86_64
  - aarch64
ls -a /srv/repo
.  ..  .sow  sow.yml

.sow/ holds private state, locks, and recovery records, with directory mode 0700. Serve the repository directories over HTTP, never .sow/.

Then add repositories and Dists by hand:

sow repo new infra
sow repo new pgsql
sow dist new el9 --format rpm -r pgsql
sow dist new trixie --format deb -r pgsql

Or install a configuration kept under version control, initialize everything it declares, and validate it:

install -m 0644 sow.yml /srv/repo/sow.yml
sow init /srv/repo
sow config check -C /srv/repo

Idempotence rules

A new configuration uses schema: sow/v3, the architectures x86_64 and aarch64, and no repository. An existing configuration is never rewritten: init only creates declared objects that do not exist yet, and reports zero counters when there is nothing left to create. The directory does not have to be empty, as long as no existing file collides with a path SOW reserves.

Apply a declared configuration

When sow.yml describes repositories and Dists, init creates their directory trees, SQLite databases, and empty indexes, and skips objects that already exist. The counters tell you what this run created:

schema: sow/v3
architectures: [x86_64, aarch64]

repos:
  pgsql:
    dists:
      el9:
        format: rpm
        limit: 1
        exclude:
          - kind: [debuginfo, debugsource]
      trixie:
        format: deb
  infra:
    protected: true
    dists:
      el9:
        format: rpm
sow init .
initialized /srv/repo: config_created=false repositories_initialized=2 dists_initialized=3
sow repo ls
NAME	PROTECTED	DISTS	GENERATION	STATUS	PACKAGES	MEMBERSHIPS
infra	true	1	1	clean	0	0
pgsql	false	2	2	clean	0	0

Each new Dist gets valid empty indexes right away, so clients can be pointed at it before it has packages: an RPM Dist gets an empty repodata/ in each architecture view, and a DEB Dist gets empty Packages and Packages.gz, by-hash entries, and a Release file.

A second run changes nothing:

sow init . --json
{"schema":"sow.cli/v1","command":"init","ok":true,"repository":null,"operation":null,"result":{"workspace":"/srv/repo","config_created":false,"repositories_initialized":0,"dists_initialized":0,"existing":["sow.yml"]},"errors":[]}

Locking and recovery

init waits for other workspace writers to finish; it has no timeout option. If an init is interrupted, run it again on the same directory. SOW first completes or rolls back the interrupted operation, recreates any missing per-repository lock files under .sow/repo-locks/, and then initializes the remaining declared objects.

If a populated .sow/ has lost .sow/workspace.lock, init stops with an integrity error rather than guess whether a writer is active. Stop every writer, create an empty .sow/workspace.lock with mode 0600, and rerun sow init.

Exit codes

Code Trigger
0 Workspace initialized, or already initialized (no-op)
1 Runtime I/O error writing the config or state directory
2 Usage error, or an existing sow.yml that fails to parse or validate
3 Partial success — some declared repositories/Dists were committed and at least one failed
5 The workspace journal could not be recovered to a terminal state, or a populated .sow/ lost workspace.lock
6 An existing file collides with a SOW reserved path, or a declared repository database requires sow repo migrate

See also

Table reader