Skip to the text
KDOS
Menu
kdos.dev KDOS from Scratch KDOS 0.2 · 4dd4a10 · 2026-11-30 Contents Index

109.5. syncthing-2.1.5

Continuous peer-to-peer file synchronisation

Version 2.1.5, release 1
Shelf transfer — File transfer, synchronisation, backup and BitTorrent
Phase 41_system (System), 980 of 1047 in build order
Licence MPL-2.0
Homepage https://syncthing.net/
Build time 0.7 SBU
Installed size 30.3 MiB in 20 files
Recipe ports/core/transfer/syncthing/kpkgbuild

About

Syncthing keeps folders the same on several machines, peer to peer. The package ships it with a starting configuration that keeps it on the local network: the machines find each other by local discovery; global discovery and relays, which reach servers on the internet, are off, and so is NAT traversal, which asks the router by UPnP or NAT-PMP to forward a port to the machine. The launcher entry File Sync runs kdos-syncthing, a wrapper the recipe writes, in a terminal; the web interface is on 127.0.0.1:8384, and closing the terminal stops the sync.

Why it is in KDOS

The comment above it in script/phases/41_system/packages.d/transfer.txt:

localAnnounce on, global/relay/NAT off: two machines on one LAN find each other with no server anywhere, and nothing reaches outside it.

Sources

Dependencies

Depends on: go.

Required by (1): syncthingtray.

Installation

From the repository root, inside the build container, this is the line kdosbuild runs for the port:

script/chroot/exec.sh bash -c 'source script/phases/41_system/phase.env && kpkg install syncthing'

What kpkg does

kpkg runs these steps, in this order, as root inside the chroot. The port directory is /ports/core/transfer/syncthing.

1. Verify every declared source. Each file a sha256 = line names, found in the port directory or in /var/cache/kpkg/sources, must hash to its line; a mismatch stops the build before anything is unpacked.

cd /ports/core/transfer/syncthing
echo '1b3e217022848b65a1b7ececa4d5e752fc044b4e8643befa1f9a8a9dc9b2bbbf  syncthing-2.1.5.tar.gz' | sha256sum -c -
echo '40aca993d620a42b04ef36e4f700092bdbba7b0fa083eaae50e56950366d0696  syncthing-vendor-2.1.5.tar.xz' | sha256sum -c -

2. Unpack. The work directory is emptied and the first source is unpacked into $SRC with its top directory stripped; any later tarball lands unstripped beside it in $SRC_ROOT, and a file that is not a tarball is copied into $SRC.

SRC_ROOT=/var/cache/kpkg/work/syncthing
SRC=$SRC_ROOT/syncthing-2.1.5
PKG=$SRC_ROOT/pkg
rm -rf "$SRC_ROOT"
mkdir -p "$SRC" "$PKG"
tar --no-same-permissions --warning=no-unknown-keyword -xf syncthing-2.1.5.tar.gz -C "$SRC" --strip-components=1

Every config.guess and config.sub older than automake’s is then replaced with automake’s, so a configure script recognises the musl target.

3. Build. build.sh is sourced in a subshell under set -e, from $SRC, with name, version, release and the five paths PKGNAME, PORT_SRC, SRC_ROOT, SRC and PKG set as shell variables. Its body, verbatim:

tar xf $PORT_SRC/${name}-vendor-${version}.tar.xz

export CGO_ENABLED=0
export EXTRA_LDFLAGS=-s
go run -mod=vendor build.go -no-upgrade -version "v$version" build syncthing
install -Dm755 syncthing $PKG/usr/bin/syncthing
for s in 1 5 7; do
	for m in man/syncthing*.$s; do
		[ -e "$m" ] || continue
		install -Dm644 "$m" $PKG/usr/share/man/man$s/$(basename "$m")
	done
done

install -Dm644 /dev/stdin $PKG/usr/share/kdos/syncthing-offline.xml <<'XML'
<!-- The configuration kdos-syncthing gives a user who has none. These keys
     are what keep a sync between two machines on one LAN from reaching
     anything outside it. -->
<configuration version="52">
    <options>
        <localAnnounceEnabled>true</localAnnounceEnabled>
        <globalAnnounceEnabled>false</globalAnnounceEnabled>
        <relaysEnabled>false</relaysEnabled>
        <natEnabled>false</natEnabled>
        <urAccepted>-1</urAccepted>
        <autoUpgradeIntervalH>0</autoUpgradeIntervalH>
    </options>
</configuration>
XML

install -d "$PKG/usr/bin"
cat > "$PKG/usr/bin/kdos-syncthing" <<'KDOS_SH'
#!/bin/sh
if [ -n "$STHOMEDIR" ]; then
	dir=$STHOMEDIR
elif [ -n "$STCONFDIR" ]; then
	dir=$STCONFDIR
elif [ -n "$XDG_CONFIG_HOME" ] && [ -f "$XDG_CONFIG_HOME/syncthing/config.xml" ]; then
	dir=$XDG_CONFIG_HOME/syncthing
elif [ -f "$HOME/.config/syncthing/config.xml" ]; then
	dir=$HOME/.config/syncthing
else
	case "$XDG_STATE_HOME" in
	/*) dir=$XDG_STATE_HOME/syncthing ;;
	*) dir=$HOME/.local/state/syncthing ;;
	esac
fi
if [ ! -e "$dir/config.xml" ]; then
	mkdir -p "$dir" && chmod 700 "$dir" &&
		install -m600 /usr/share/kdos/syncthing-offline.xml "$dir/config.xml"
fi
exec syncthing serve "$@"
KDOS_SH
chmod 755 "$PKG/usr/bin/kdos-syncthing"

install -d "$PKG/usr/share/applications"
cat > "$PKG/usr/share/applications/syncthing.desktop" <<'EOF'
[Desktop Entry]
Type=Application
Name=File Sync
GenericName=Syncthing
Comment=Keep folders the same on the machines on this network
Exec=kdos-syncthing
Icon=syncthing
Terminal=true
Categories=Network;FileTransfer;
Keywords=sync;syncthing;folder;share;backup;
EOF
chmod 644 "$PKG/usr/share/applications/syncthing.desktop"
install -Dm644 assets/logo-only.svg "$PKG/usr/share/icons/hicolor/scalable/apps/syncthing.svg"

The switches, and why each is set:

The common switches of each build system are explained in the Flag glossary.

4. Package. kpkg removes libtool archives, the info directory index, mimeinfo.cache and every fonts.dir from $PKG, copies the source’s licence files into /usr/share/licenses/syncthing, prunes what the image does not ship, lints the tree and rolls it reproducibly:

tar --sort=name --format=gnu --numeric-owner --owner=0 --group=0 \
    --mtime=@$SOURCE_DATE_EPOCH \
    --use-compress-program='xz -9 -T0 --block-size=32MiB --no-adjust' \
    -cf syncthing-2.1.5-1.tar.xz -C "$PKG" .

5. Adopt. kpkgadd installs the package’s files over the root, refusing a path another package owns, records the file list in /var/lib/kpkg/db/syncthing, and runs the triggers its paths call for.

Contents

Installed programs: kdos-syncthing, syncthing.

Installed directories: /usr/share/licenses/syncthing.

Short descriptions

syncthing Syncthing

Notes

The modules come from the vendor bundle, syncthing-vendor-<version>.tar.xz, made by ports/fetch with go mod vendor; go run -mod=vendor build.go runs upstream’s build script against it (see Vendoring). Only the manual pages named syncthing* are installed: the tarball’s stdiscosrv.1 and strelaysrv.1 describe the discovery and relay servers, which are not built.

/usr/share/kdos/syncthing-offline.xml is a whole configuration with only an <options> block. Syncthing reads a config.xml over its own defaults, so every key it does not name keeps upstream’s value, and the device’s identity and keys are made on first start. Besides the three network switches it declines usage reporting (urAccepted of -1) and sets the automatic upgrade interval to zero. Its version="52" is the configuration schema this release writes, so no migration runs over the file; a version bump that moves Syncthing’s CurrentVersion should move it too.

kdos-syncthing looks for an existing configuration where Syncthing itself does: $STHOMEDIR, $STCONFDIR, $XDG_CONFIG_HOME/syncthing and ~/.config/syncthing when a config.xml is there, otherwise $XDG_STATE_HOME/syncthing or ~/.local/state/syncthing. It copies the shipped file there only when no config.xml exists, so a configuration already made is never touched, and then runs syncthing serve.