Skip to content

Linux packages: let an app declare its own Depends / Recommends (core.Video needs GStreamer plug-ins the packages never pull in) #139

Closed

Description

@houko

Context

The Linux packages nsgo build writes have a fixed dependency list that an app cannot extend:

  • The Debian control file is written in one fmt.Sprintf in debPackage, with Depends: libgtk-4-1 and Recommends: libwebkitgtk-6.0-4 hard-coded (cmd/nsgo/linuxpkg.go:218).
  • The Arch .PKGINFO is written the same way in archPackage, with depend = gtk4 and optdepend = webkitgtk-6.0: web views hard-coded (cmd/nsgo/linuxpkg.go:257).
  • The linux section of nsgo.yaml only has maintainer, summary, license and flatpak_runtime (cmd/nsgo/project.go:185-190), so there is nowhere to add more.
  • The tests pin these strings (cmd/nsgo/installer_test.go:251, :274).

On Linux, core.Video is a GtkMediaFile that GTK backs with GStreamer (internal/platform/linux/video.go:16-23). GTK's GStreamer media backend itself usually arrives, because Debian's and Ubuntu's libgtk-4-1 recommends libgtk-4-media-gstreamer, but the GStreamer plug-ins that actually demux and decode the formats an app plays do not. NSGo already knows this at runtime: mediaError appends "No installed GStreamer plug-in can play this format (H.264 / AAC need gst-libav or gst-plugins-ugly / -bad)." (internal/platform/linux/video.go:343-357), and the getting-started guide says videos need GStreamer plug-ins (docs/public/en/getting-started.md:15). The package the user installs never pulls any of them in.

The same applies to libsoup 3, which the backend loads at run time for images from the network (internal/platform/linux/http.go:58) and which neither package declares. There is no RPM output, the AppImage takes GTK from the system by design (cmd/nsgo/appimage.go:13-18), and the Flatpak manifest takes everything from org.gnome.Platform with only the runtime version configurable (cmd/nsgo/flatpak.go:199-201), so the .deb and the Arch package are the only places where the system's package manager could install these.

Small doc mismatch along the way: docs/architecture/tool.md:73 says the packages "suggest WebKitGTK 6", but the .deb uses Recommends, which apt installs by default, not Suggests.

Why it matters for real apps

Kando (github.com/yldm-tech/kando), an open-source desktop video player we are moving to NSGo, plays local files through core.Video. A user who installs its .deb with the generated install.sh (which runs apt-get install -y on the downloaded package, or dpkg -i without apt, cmd/nsgo/install/install.sh:105-108) gets GTK 4 and WebKitGTK, but not gstreamer1.0-plugins-good, gstreamer1.0-plugins-bad or gstreamer1.0-libav. On a system that does not already have them, the first MP4 they open fails with OnError, and the only fix is a manual apt install that the user has to find in the app's docs. The app cannot fix this itself: the control file is generated and there is no setting or hook to add a line.

Any app that shells out to a tool (Kando also uses ffmpeg and yt-dlp), plays audio, or loads remote images has the same need: one or two extra Depends / Recommends entries, and the matching depend / optdepend on Arch.

Minimal repro (any NSGo app with a video, built with nsgo build for linux/amd64):

package main

import (
	"log"

	"github.com/nsgo-dev/nsgo"
	"github.com/nsgo-dev/nsgo/core"
)

func main() { nsgo.Run(Root, nsgo.WindowSize(640, 360)) }

func Root(cx *core.Scope) core.Node {
	return core.Video{
		Source:  "asset:clip.mp4", // H.264 / AAC
		Style:   core.Style{Width: core.Pct(100), Height: core.Pct(100)},
		OnError: func(err error) { log.Printf("video: %v", err) },
	}
}

Install the resulting .deb with apt-get install ./app-….deb on a minimal Debian 13 or Ubuntu 24.04 desktop that has none of gstreamer1.0-libav, gstreamer1.0-plugins-bad or gstreamer1.0-plugins-ugly: the package installs cleanly, the window opens, and OnError fires with the plug-in hint instead of OnLoad. dpkg -s on the package shows only Depends: libgtk-4-1 and Recommends: libwebkitgtk-6.0-4.

Proposal

Per-format dependency lists in nsgo.yaml, appended after NSGo's own and passed through verbatim, so that Debian alternatives and version constraints (a | b, foo (>= 1.2)) and Arch's name: reason optdepends work:

linux:
  maintainer: "Jane Doe <[email protected]>"
  depends:
    deb: [gstreamer1.0-plugins-good]
    arch: [gst-plugins-good]
  recommends:
    deb: [gstreamer1.0-plugins-bad, gstreamer1.0-libav, ffmpeg]
    arch: ["gst-libav: H.264 and AAC video", "ffmpeg: thumbnails"]

In project.go, next to the existing fields:

Linux struct {
	Maintainer     string `yaml:"maintainer"`
	Summary        string `yaml:"summary"`
	License        string `yaml:"license"`
	FlatpakRuntime string `yaml:"flatpak_runtime"`
	// Depends and Recommends add to the Debian package's Depends and Recommends and the Arch package's depend and optdepend, after NSGo's own, each entry as the format writes it.
	Depends    linuxDeps `yaml:"depends"`
	Recommends linuxDeps `yaml:"recommends"`
} `yaml:"linux"`

type linuxDeps struct {
	Deb  []string `yaml:"deb"`
	Arch []string `yaml:"arch"`
}

debPackage joins libgtk-4-1 with Depends.Deb (and libwebkitgtk-6.0-4 with Recommends.Deb) by , ; archPackage writes one depend = / optdepend = line per entry. An entry with a newline, or an empty entry, is a config error, so it cannot inject other control fields. Formats without a dependency model (AppImage, the Flatpak archive) ignore the lists; if an RPM output is added later it would take an rpm key the same way.

Optionally, since the framework knows what core.Video and network images need on Linux, NSGo could also add gstreamer1.0-plugins-good and libsoup-3.0-0 to its own default Recommends (and gst-plugins-good / libsoup3 to Arch's optdepend), the same way it already recommends WebKitGTK for web views. Apps that need more codecs would still use the settings above.

Acceptance

  • linux.depends.deb / linux.recommends.deb entries appear, in order and after NSGo's own, in the .deb control file's Depends: / Recommends: lines.
  • linux.depends.arch / linux.recommends.arch entries appear as depend = / optdepend = lines in .PKGINFO.
  • Without the new keys, both packages are byte-for-byte what they are today (apart from timestamps).
  • An entry containing a newline, or an empty entry, fails the build with a message naming the key.
  • installer_test.go covers both formats with and without extra entries.
  • docs/public/en/building.md and docs/public/zh/building.md document the keys next to linux.maintainer, and docs/architecture/tool.md says Recommends rather than "suggest".

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions