Writing the program is half the work. The other half is making it installable by somebody who did not build it, on a machine you have never seen, with a toolchain you do not control.
That second half is packaging, and it is where a lot of free software quietly stops. A repository with a good README and no package asks every user to become a builder. Most people will not. The ones who do will build a slightly different thing than you did, in a slightly different environment, and some of them will file bugs that are really installation bugs. A package is how you stop guessing which of those happened.
This post is about how I package the projects in ~/Hacking/: one directory per format, one version written by hand, one release loop, and a set of habits that came from watching a package build succeed on my machine and fail in a chroot. It covers Debian, Arch, openSUSE/Fedora, Void, Homebrew and Flatpak, with Guix and Nix as the two I treat as first-class rather than as an afterthought.
Why packaging is part of the software #
A package is a promise with three parts: this is what the program is, these are the files it installs, and these are the things it needs to run. The distribution’s job is to make that promise fit its own rules – the filesystem layout, the package database, the security model, the update policy. Your job is to make the promise true without lying about the first part.
That framing explains most of the work. The program may be correct and still be a bad package: a launcher with a shebang that points at a path the distribution does not have, a library installed where the distribution’s interpreter does not look, a man page that never gets installed, a licence file that is missing, a test suite that needs the network, a build that silently uses a dependency that is not declared. None of those are bugs in the code. All of them are bugs in the package.
The habit that catches them is simple: build the package in the distribution’s own clean environment, install it there, and run the installed program. Not the build tree, not a wrapper script in the repository – the files the package actually puts on disk.
The layout #
Every repository keeps its distribution recipes under packaging/, one directory per format, beside the two files that are packages in their own right: guix.scm and the Nix expression.
| Path | What it is |
|---|---|
packaging/debian/ |
debian/control, rules, changelog, copyright, watch, tests/ |
packaging/arch/PKGBUILD |
The Arch recipe |
packaging/opensuse/*.spec + *.rpmlintrc + _service |
openSUSE and Fedora/RHEL |
packaging/voidlinux/template |
The Void template |
packaging/homebrew/Formula/*.rb |
The Homebrew formula |
packaging/flatpak/*.yaml |
The Flatpak manifest |
guix.scm, manifest.scm, channels.scm |
The Guix package, environment and pin |
flake.nix, package.nix or default.nix |
The Nix flake and derivation |
The reason to keep them all in one tree is not tidiness. It is that they share a version, a source archive and a set of facts (the program’s name, its licence, its data files, its completions, its manual page). When one of those facts changes, all of them have to change, and a review that sees them together is a review that can notice.
One version, written once #
The version is the first thing that goes wrong in a multi-format repository. It appears in the Arch recipe’s pkgver, the RPM spec’s Version, the Void template’s version, the AppStream metadata’s <release version=...>, the language package manager’s manifest, the Debian changelog, the manual page and the changelog’s newest heading. Seven copies and one truth.
The arrangement I use is: one version source, a pattern for every copy, and a task that writes them.
(define version-source "package.nix") (define version-source-pattern "version[ \t]*=[ \t]*\"([0-9]+\\.[0-9]+\\.[0-9]+)\"") (define version-copies '( ("data/org.jointhefreeworld.lambdock.metainfo.xml" . "<release version=\"([0-9]+\\.[0-9]+\\.[0-9]+)\"") ("packaging/arch/PKGBUILD" . "pkgver=([0-9]+\\.[0-9]+\\.[0-9]+)") ("packaging/opensuse/lambdock.spec" . "Version:[ \t]+([0-9]+\\.[0-9]+\\.[0-9]+)") ("packaging/voidlinux/template" . "version=([0-9]+\\.[0-9]+\\.[0-9]+)") ("rust/Cargo.toml" . "\\[package\\][^[]*version = \"([0-9]+\\.[0-9]+\\.[0-9]+)\"")))
maak sync-version rewrites only the captured span, so a recipe keeps its alignment and a document keeps its wording. maak version-check is the reading half: it fails when a copy disagrees, and a release refuses to proceed while any of them does. The pattern is found rather than assumed, and a pattern that stops matching is an error instead of a check that silently passes on nothing.
The one thing the task cannot know is the checksum. The source archive is published by the forge after the tag is pushed, and its hash does not exist until then. So the sequence is: release, wait for the archive, refresh the checksums from the published file. That step is written down in each recipe’s comment rather than hidden in a task that pretends to do it. A release process that lies about one step is worse than one that admits a step.
Debian #
Debian is the format with the most paperwork, and the paperwork is the point: it is what makes a package reviewable by somebody who has never met you.
debian/control #
Source: maak Section: devel Priority: optional Maintainer: Josep Bigorra <jjbigorra@gmail.com> Build-Depends: debhelper-compat (= 13), guile-3.0, guile-3.0-dev, pkg-config, Standards-Version: 4.7.0 Homepage: https://github.com/jjba23/maak Vcs-Git: https://github.com/jjba23/maak.git -b trunk Vcs-Browser: https://github.com/jjba23/maak Rules-Requires-Root: no Package: maak Architecture: any Depends: ${misc:Depends}, ${shlibs:Depends}, guile-3.0, Suggests: curl, git, tar, unzip, zip, Description: command runner whose task list is a Guile Scheme file ...
Two details are not decoration. Rules-Requires-Root: no says the build does not need root, which is a claim the build has to keep true. And ${shlibs:Depends} is there even though the program is interpreted: it is the hook that picks up any shared library the packaging helper finds, and removing it because “it is only Scheme” is how a dependency goes missing on another architecture.
debian/rules #
The interesting part of a Guile package is where the modules and their compiled forms go. Debian does not use one directory for both: modules live under /usr/share/guile/site, and the byte-compiled .go files live under the multiarch libdir. Hard-coding either is a package that installs and then cannot start.
SITE_DIR := $(shell $(PKG_CONFIG) --variable=sitedir $(GUILE_PC) 2>/dev/null) CCACHE_DIR := $(shell $(PKG_CONFIG) --variable=siteccachedir $(GUILE_PC) 2>/dev/null) GUILD := $(or $(shell command -v guild-3.0 2>/dev/null),$(shell command -v guild 2>/dev/null))
Asking guile-3.0.pc rather than writing the pair down is what puts the compiled files where the Guile this package depends on looks for them. guild is found rather than assumed, because Debian ships it under the versioned name in guile-3.0-dev and has no plain guild.
The build byte-compiles every module, and a module that does not compile fails the build. That is deliberate: a package that ships sources without their compiled form runs slower on first use and hides the reason. The install then asks the installed tree the question an installer asks it:
env -u GUILE_LOAD_PATH -u GUILE_LOAD_COMPILED_PATH \ ./debian/maak/usr/bin/maak --version env -u GUILE_LOAD_PATH -u GUILE_LOAD_COMPILED_PATH \ ./debian/maak/usr/bin/maak --completion bash > /dev/null
The Guile paths are cleared for the run so that what is being asked is what this tree holds, not what a profile elsewhere on the build machine carries. That is the whole trick of packaging: make the test unable to see your development environment.
override_dh_auto_test is empty, and the emptiness is explained in the file. The project’s test framework is not in Debian, and a test suite that needs packages the distribution does not carry would either be disabled silently or fail for the wrong reason. What can be asked of the installed package without them is asked in debian/tests/ instead.
debian/tests/ #
An autopkgtest that runs the installed program is worth more than a build-time unit test for one reason: it tests the thing the user gets. This is the core of Maak’s debian/tests/smoke, with the helper functions and the cleanup trap left out:
maak --version | head -n 1 | grep -qE '^maak [0-9]+\.[0-9]+\.[0-9]+$' maak --version | grep -q '^License: MIT$' work=$(mktemp -d) trap 'rm -rf "$work"' EXIT cat >"${work}/maak.scm" <<'EOF' (define-module (maak) #:declarative? #t #:use-module (maak maak)) (define (greet name) "Greet NAME." (run (list "echo" "hello" name))) EOF cd "${work}" maak --list | grep -q 'greet' maak --plan greet world | grep -q 'echo hello world' maak --dry-run greet world | grep -q 'echo hello world' [ ! -e hello ] || fail "the dry run wrote a file" maak --completion bash | grep -q 'complete'
It checks that the launcher starts the interpreter under the name Debian installs it by, that it reads a Maak file of its own in a directory of its own, that the listing prints the docstring, that a plan shows the argv without running it, that a dry run leaves nothing behind, that the completion is generated from the installed library, and that an unknown task fails with a non-zero status. Every answer is read from the installed program; nothing reaches the source tree.
The remaining Debian files are small but not optional: watch tells uscan where the tag archive is and how to rename it into the tarball dpkg-source expects; copyright is the machine-readable licence record, including the fact that a generated file contains text from two other MIT projects; source/format is 3.0 (quilt); maak.docs and maak.manpages install the documentation and the manual page; dh_missing --fail-missing refuses a package that leaves a staged file behind.
When the language is Rust #
Lambdock is Rust plus Guile plus GTK, and its debian/rules records two lessons:
override_dh_clean: dh_clean -X 'rust/vendor/*' override_dh_auto_build: cargo build --offline --locked --release override_dh_auto_test: cargo test --offline --locked override_dh_auto_install: cargo run --offline --locked -p xtask -- install --prefix /usr --destdir debian/lambdock
--offline --locked because a Debian build must not fetch crates. dh_clean -X 'rust/vendor/*' because dh_clean deletes *.orig files across the tree, and vendored crates ship Cargo.toml.orig, which cargo’s checksum files name: cleaning them breaks the next build. And the crate asks for a newer rustc than Debian 13 has, which is stated in the file rather than discovered by the first user who tries to build it.
Arch #
The Arch recipe is a shell script with three functions and a metadata block, and it is the format that most rewards being explicit.
pkgname=maak pkgver=1.6.6 pkgrel=1 pkgdesc="Command runner à la Make using Guile Scheme" arch=('any') url="https://github.com/jjba23/maak" license=('MIT') depends=('bash' 'coreutils' 'guile' 'util-linux') makedepends=('guile' 'pkgconf') checkdepends=('veritas' 'unzip' 'zip') source=("$pkgname-$pkgver.tar.gz::https://github.com/jjba23/maak/archive/refs/tags/v$pkgver.tar.gz") sha256sums=('d1779a169480b8e851a6734615f4eb9651b24bdcd7c63a32f2bd7fbbf0558c7f')
The same pkg-config question is asked in _site_dir and _compiled_dir, with a fallback for a machine where the .pc file is absent. build byte-compiles the modules into a staging directory, mirroring the source tree. check runs the project’s own test suite with the environment variables that tell it where the tests are. package installs the launcher, the modules, the compiled forms, the help screen, the three completions, the man page, the licence, the README, the NEWS and the docs.
namcap is run on the PKGBUILD because it catches the things a human reviewer of a small package tends to skip: a dependency that is used but not declared, a file installed outside the expected prefix, a missing licence. It is not a substitute for reading the recipe. It is a cheap second pair of eyes.
openSUSE and Fedora/RHEL #
The spec file is older than most of the projects it packages, and it shows in useful ways. The build starts from a source archive, unpacks it with %autosetup, and rewrites the shebangs:
%prep
%autosetup -n %{name}-%{version}
sed -i '1s|^#!%{_bindir}/env \(.*\)$|#!%{_bindir}/\1|' scripts/maak
#!/usr/bin/env guile is right in a checkout and wrong in an RPM: the package’s interpreter is a declared dependency at an absolute path, and the build should fail if it is missing rather than pick up whatever env finds. The install then uses the distribution’s own macros:
%install SITE_DIR="%{buildroot}%{_datadir}/guile/site/3.0" CCACHE_DIR="%{buildroot}%{_libdir}/guile/3.0/site-ccache"
%{_datadir} and %{_libdir} are not cosmetic. On a 64-bit openSUSE, %{_libdir} is /usr/lib64, and a recipe that writes /usr/lib installs a compiled file the interpreter will not read on that architecture. This is the same class of bug as the Debian one, in a different syntax.
The spec’s %changelog is maintained by the release task: maak release inserts an entry with a C-locale date, so rpm -q --changelog reads the same on every machine. rpmlint and a .rpmlintrc that documents the accepted exceptions are part of the work, and a _service file records how the source archive is fetched for the openSUSE build service.
Void #
Void’s templates are short, and they make the split between host tools and runtime dependencies explicit:
pkgname=maak version=1.6.6 revision=1 depends="bash coreutils guile util-linux" hostmakedepends="guile" short_desc="Command runner à la Make using Guile Scheme" maintainer="Josep Bigorra <jjbigorra@gmail.com>" license="MIT" distfiles="${homepage}/archive/refs/tags/v${version}.tar.gz" checksum=d1779a169480b8e851a6734615f4eb9651b24bdcd7c63a32f2bd7fbbf0558c7f wrksrc="${pkgname}-${version}"
do_build compiles the modules; do_install uses vinstall, vcopy and vlicense so the package’s file list stays inside the template’s own vocabulary. hostmakedepends versus depends is the same distinction as Debian’s Build-Depends versus Depends, and getting it wrong is how a package acquires a build tool it does not need at runtime, or a runtime dependency it never declared.
Homebrew #
Homebrew is not a GNU/Linux distribution, but a project with macOS users needs it, and the formula is a good exercise in not assuming Linux. Maak’s formula is a formula rather than a cask or a gem, because the program is command-line Guile that builds from source: a cask installs a prebuilt macOS bundle, which this is not, and a gem is Ruby code for Ruby’s package manager, which this is not either.
The install keeps the library, the help screen and the compiled cache together under libexec, byte-compiles into the Cellar, and then writes small wrappers into bin:
path = [ "#{Formula["coreutils"].opt_libexec}/gnubin", Formula["gnu-getopt"].opt_bin, Formula["guile"].opt_bin, "$PATH", ].join(":") %w[maak maak-tasks maak-zed].each do |name| (bin/name).write <<~SH #!/bin/bash export PATH="#{path}" export GUILE_LOAD_PATH="#{site}" export GUILE_LOAD_COMPILED_PATH="#{cache}" exec "#{bin_dir/name}" "$@" SH (bin/name).chmod 0755 end
The wrapper is there because the launcher expects a GNU userland and a GNU getopt, and because the library’s load path has to be set before the program starts. The formula’s test block then does what the Debian autopkgtest does: it writes a tiny Maak file in a temporary directory and asserts that the installed program lists the task, reads the docstring, and prints its version. A package without a test block is a package nobody has run after installation.
Flatpak #
Flatpak is a different kind of package: not a file layout for a distribution, but a sandbox with a runtime and a permission list. Lambdock’s manifest starts with the identity and the runtime:
app-id: org.jointhefreeworld.lambdock runtime: org.gnome.Platform runtime-version: '50' sdk: org.gnome.Sdk sdk-extensions: - org.freedesktop.Sdk.Extension.rust-stable command: lambdock finish-args: - --socket=wayland - --share=ipc - --filesystem=host - --device=dri - --env=GDK_BACKEND=wayland
The SDK extension is how Rust gets into the sandbox, because the GNOME SDK does not carry it. The finish-args are the permission list, and every line is a decision: Wayland and IPC are what a dock needs to exist; --device=dri is what makes it draw with the GPU; --filesystem=host is broad, and it is a permission a manifest should justify rather than inherit from a neighbouring application. A manifest copied without reading those lines is how a sandbox becomes a formality.
The modules below build the dependencies the runtime lacks – Boehm GC for Guile, then the program – and the AppStream metadata carries the version the release task writes, so the software centre and the recipe agree about what is installed.
Guix and Nix are packaging too #
The two I use daily are also packages, and treating them as a separate universe is a mistake. guix.scm is a package definition, manifest.scm is an environment, and a Guix channel is a distribution of its own with an authenticated history. A Nix flake exposes packages, apps and devShells, and nix profile install is an installation.
What changes is who does the work. For Debian, Arch and the rest, I write the file layout, the dependency list and the post-install check. For Guix and Nix, the build system does most of the layout, and my job is to describe the inputs and the phases accurately. The distribution recipes still matter, because most users are not on either, and because writing them is what proves the program can be installed without my machine’s habits.
The previous post covers those two files in detail. The packaging lesson here is that they are the same kind of artifact as the .spec and the PKGBUILD: a description of how to get from a source archive to a working program, kept in the repository, reviewed with the code it packages.
What a packager knows that a developer does not #
These are the habits I would hand to anyone packaging their own software. Most of them were learned by watching a build fail in an environment I did not control.
- The shebang is part of the interface.
#!/usr/bin/envis right for a checkout and wrong for a package with an absolute dependency. Rewrite it, and let the build fail if the interpreter is absent. - Ask the tool where its directories are. pkg-config,
%{_datadir},%{_libdir}and the interpreter’s own load path are facts about the target, not about your laptop. Hard-coded paths are the most common “works here” bug in packaging. - The build must not use the network. Fetch sources before the build; declare every input. A build that downloads works on the machine with the network and fails on the builder, the CI runner and the distribution’s infrastructure.
- Do not vendor what you can depend on, and declare what you do vendor. A vendored tree is a licence question and a security question, and both need an answer in the recipe.
- Install the boring files. Licence, README, changelog, man page, completions, desktop file, AppStream metadata, icons. They are what makes a program feel native in a distribution, and
dh_missing --fail-missing,rpmlintandnamcapall notice when they are absent. - Test the installed artifact. A build-time unit test is not an installation test. Run the installed binary, in a temporary directory, with the development environment’s variables cleared.
- Do not silently patch upstream. If a change is needed, carry it as a patch with a header that says why, and send it upstream. A distribution that has to maintain a private fork of your build is a distribution that will eventually drop the package.
- Say what you did not test. A recipe that has never been built on a clean chroot is a draft. The honest README line is “tested on X”, not “supports all distributions”.
The release loop #
All of this meets in one loop, and the loop is the reason to automate the parts that can be automated:
- Write the version in the version source, and cut the release with
maak release. The task writes the copies, the changelogs and the spec entry, runs the gate, commits, tags and pushes. - Wait for the forge to publish the tag archive.
- Refresh every checksum from the published archive and commit that follow-up. It is the one step no task can know.
- Build each format in its own environment:
maak deb-build,maak arch-build,maak rpm-build,maak flatpak-build,maak nix-build,guix build -f guix.scm. The tasks are also what CI runs. - Install at least one of the results and run it. A package that builds and does not start is a package that failed.
- Publish the recipes with the tag, and let the distributions pick them up. If a package is in a distribution’s repository, the same loop produces the update the maintainer needs.
The loop is deliberately boring. The interesting decisions – the licence, the dependency list, the sandbox permissions, the file layout – are made once, written down in the recipe, and then reviewed like code. That is the whole discipline: packaging is not a chore that follows the software; it is the part of the software that decides whether anyone else can use it.
If you take one habit away: build the package, install it in a clean environment, and run the installed program before you tell anyone it is packaged. Everything else in this post is a detail that habit will eventually teach you.
The rest of this series: developing inside Emacs, the Guix and Nix environments the recipes are built in, and the Maak tasks that drive every build and release.