Skip to content

Patching ​

This guide covers how to create and manage patches for Garden Linux packages, following the best practices from PATCHING.MD.

When to Create Patches ​

Patches are needed when:

  • Fixing bugs in upstream source code
  • Applying security fixes from upstream to older versions
  • Customizing package behavior for Garden Linux
  • Updating the debian/ folder configuration
  • Backporting features or fixes to a specific version

Prerequisites ​

To create patches, you need:

  • The package-build tools installed locally
  • Git
  • Access to the package repository
  • Basic understanding of quilt

Step1: Prepare Your Local Sources ​

First, you need the complete package sources with all patches applied exactly as the GitHub Actions pipeline would do.

bash
./package-build/build --leave-artifacts --source-only package-<package_name>

This command:

  • Calls the package-build/bin/source script in a container
  • Places the source in package-<package_name>/output/run-<datetime>/a
  • Creates a copy in package-<package_name>/output/run-<datetime>/b
  • Keeps the sources even if patch application fails

WARNING

If building for arm64, include --arch arm64 in the build command. Cross-build for generating sources may cause issues.

INFO

If the source build fails to apply a patch, the sources are kept in the state where the process stopped, allowing you to fix the issue.

Step2: Spawn a Patch Environment ​

Use the edit mode to spawn a container with quilt already configured correctly:

bash
./package-build/build --edit package-<package_name>

This starts a Debian container with the output folder from the previous step mounted. The container has quilt pre-configured according to Debian standards, which is important for maintaining compatibility with patches pulled from salsa.debian.org.

The preparation is defined in package-build/bin/patchenv-init, so you can review those settings and use your local machine if preferred.

Step3: Make Your Changes ​

When working on patches, keep the a directory unchanged and make all your changes in the b directory. This allows you to create a proper diff between the original and modified sources.

Using Quilt ​

Quilt is the recommended tool for managing patches. Key commands:

CommandDescription
quilt pushApply a single patch
quilt push -aApply all patches
quilt push -fForce apply patches
quilt refreshUpdate patch files after manual edits
quilt add <file>Add a new file to be patched
quilt remove <file>Remove a file from the patch

TIP

Use quilt series to see all patches in order and quilt applied to see which are already applied.

External Quilt References ​

Step4: Create the Patch ​

The diff between the original a directory and your modified b directory becomes your patch.

bash
diff -Naur a/ b/ > <name-of-your-patch>.patch

TIP

If you know which file was modified, create a focused patch:

bash
diff -Naur a/path/to/file b/path/to/file > fixes_debian/my-fix.patch

Step5: Add the Patch to the Package ​

Depending on the type of patch, place it in the appropriate directory and update the prepare_source script.

For debian/ folder patches ​

Place patches in a fixes_debian directory and apply them in prepare_source:

bash
apply_patches fixes_debian

For upstream source patches ​

Place patches in an upstream_patches directory and import them in prepare_source:

bash
import_upstream_patches# upstream_patches

Creating the directory ​

If the directory doesn't exist, create it and add the patch:

bash
mkdir -p fixes_debian
mv <name-of-your-patch>.patch fixes_debian/

Then add the patch to the series file:

bash
echo "<name-of-your-patch>" >> fixes_debian/series

INFO

The series file lists all patches in the order they should be applied.

Patch Organization ​

Follow these conventions for patch organization:

Patch TypeDirectoryApplication Method
debian/ folder changesfixes_debianapply_patches
upstream source changesupstream_patchesimport_upstream_patches#
build dependency patchesfixes_build_depapply_patches
local customization patchesgardenlinux_patchesimport_upstream_patches#