Control: tags -1 + patch
I was looking to add a debusine repo to sbuild today to be able to use
Python 3.15-compatible packages to work on the next level of failures...
and came across this bug.
My perl is *very* rusty and so the attached patch is mostly based on
copying adjacent code to add a --extra-repository-file option. Tested with:
$ sbuild \
--extra-repository-file debusine-py315rebuilds.sources \
python-pyqtgraph_0.14.0*dsc
[...]
I: Setting up apt archive...
Installed extra repository file py315rebuilds.sources as
/etc/apt/sources.list.d/sbuild-extra-repository-rPpBuNLepQ.sources
[...]
Get:7 http://deb.debusine.debian.net/debian/r-python-python3.15
sid-python3.15 InRelease [2217 B]
[...]
Get:202 http://deb.debusine.debian.net/debian/r-python-python3.15
sid-python3.15/main amd64 python3-all amd64 3.14.7-4+py315.2 [1008 B]
[...]
Hope that helps!
Stuart
--
Stuart Prescott http://www.nanonanonano.net/ [email protected]
Debian Developer http://www.debian.org/ [email protected]
GPG fingerprint 90E2 D2C1 AD14 6A1B 7EBB 891D BBC1 7EBB 1396 F2F7
From 7d8e0eeb7bababf989ccf19d0a325a3bfdc18dfb Mon Sep 17 00:00:00 2001
From: Stuart Prescott <[email protected]>
Date: Thu, 22 Oct 2026 18:24:03 +1100
Subject: [PATCH] Add --extra-repository-file option to feed in repo
Add an extra command line option and associated config options to allow
an extra repository to be configured as a whole file from the CLI,
thereby allowing the Signed-By key to be passed at the same time.
Closes: #1089735
---
lib/Sbuild/Conf.pm | 9 ++++++
lib/Sbuild/Options.pm | 3 ++
lib/Sbuild/ResolverBase.pm | 53 ++++++++++++++++++++++++++++++++++-
man/sbuild.1.in | 22 ++++++++++++++-
test/sbuild-options-parsing.t | 4 +++
5 files changed, 89 insertions(+), 2 deletions(-)
diff --git a/lib/Sbuild/Conf.pm b/lib/Sbuild/Conf.pm
index 715ac011..2fa43b10 100644
--- a/lib/Sbuild/Conf.pm
+++ b/lib/Sbuild/Conf.pm
@@ -1809,6 +1809,15 @@ $external_commands = {
HELP => 'Additional per-build apt repositories.',
CLI_OPTIONS => ['--extra-repository']
},
+ 'EXTRA_REPOSITORY_FILES' => {
+ TYPE => 'ARRAY:STRING',
+ VARNAME => 'extra_repository_files',
+ GROUP => 'Dependency resolution',
+ DEFAULT => [],
+ HELP =>
+'Additional per-build apt repository configuration files. Each element is the path to a host-side apt source file in deb822 format (as used by files ending in .sources in /etc/apt/sources.list.d/). The file is copied into the chroot before the first apt update and removed again at the end of the build. This allows, for example, binding a repository key via the Signed-By field.',
+ CLI_OPTIONS => ['--extra-repository-file']
+ },
'SOURCE_ONLY_CHANGES' => {
TYPE => 'BOOL',
VARNAME => 'source_only_changes',
diff --git a/lib/Sbuild/Options.pm b/lib/Sbuild/Options.pm
index 54175f94..1fb68aad 100644
--- a/lib/Sbuild/Options.pm
+++ b/lib/Sbuild/Options.pm
@@ -712,6 +712,9 @@ sub set_options {
"extra-repository=s" => sub {
$self->push_conf('EXTRA_REPOSITORIES', $_[1]);
},
+ "extra-repository-file=s" => sub {
+ $self->push_conf('EXTRA_REPOSITORY_FILES', $_[1]);
+ },
"extra-repository-key=s" => sub {
$self->push_conf('EXTRA_REPOSITORY_KEYS', $_[1]);
},
diff --git a/lib/Sbuild/ResolverBase.pm b/lib/Sbuild/ResolverBase.pm
index 7458f3dd..39f472c5 100644
--- a/lib/Sbuild/ResolverBase.pm
+++ b/lib/Sbuild/ResolverBase.pm
@@ -76,6 +76,10 @@ sub new {
$extra_repositories_archive_list_file
);
+ # Chroot paths of deb822-style extra repository files copied in for
+ # the duration of the build (see add_extra_repositories()).
+ $self->set('Extra repository files', []);
+
my $extra_packages_archive_list_file
= '/etc/apt/sources.list.d/sbuild-extra-packages-archive.list';
$self->set(
@@ -96,6 +100,9 @@ sub add_extra_repositories {
# If this step would be done too late, extra repositories would only be
# considered when resolving build dependencies but not for upgrading the
# base chroot.
+
+ # First stage is to look at one-line style repository specifications
+ # configured via --extra-repository / EXTRA_REPOSITORIES.
if (scalar @{ $self->get_conf('EXTRA_REPOSITORIES') } > 0) {
my $extra_repositories_archive_list_file
= $self->get('Extra repositories archive list file');
@@ -135,6 +142,44 @@ sub add_extra_repositories {
}
}
}
+
+ # Second stage is to copy in entire files; this is for Deb822-style
+ # files specified via --extra-repository-file / EXTRA_REPOSITORY_FILES.
+ # The data is saved in a temporary file ending with ".sources" as
+ # expected by apt.
+ for my $hostfile (@{ $self->get_conf('EXTRA_REPOSITORY_FILES') }) {
+ if (!-f $hostfile) {
+ $self->log_error(
+"Failed to add extra repository file '${hostfile}' - it doesn't exist!\n"
+ );
+ return 0;
+ }
+ my $targetfile = $session->mktemp({
+ TEMPLATE =>
+"/etc/apt/sources.list.d/sbuild-extra-repository-XXXXXXXXXX.sources"
+ });
+ if (!$targetfile) {
+ $self->log_error(
+ "Can't create tempfile for extra repository file\n");
+ return 0;
+ }
+ if (!$session->copy_to_chroot($hostfile, $targetfile)) {
+ $self->log_error(
+"Failed to copy extra repository file $hostfile into chroot $targetfile\n"
+ );
+ $session->unlink($targetfile);
+ return 0;
+ }
+ if (!$session->chmod($targetfile, '0644')) {
+ $self->log_error(
+ "Failed to chmod $targetfile inside the chroot\n");
+ $session->unlink($targetfile);
+ return 0;
+ }
+ $self->log(
+ "Installed extra repository file $hostfile as $targetfile\n");
+ push @{ $self->get('Extra repository files') }, $targetfile;
+ }
}
sub setup {
@@ -736,7 +781,8 @@ sub update_archive {
for my $list_file (
$self->get('Dummy archive list file'),
$self->get('Extra packages archive list file'),
- $self->get('Extra repositories archive list file')
+ $self->get('Extra repositories archive list file'),
+ @{ $self->get('Extra repository files') }
) {
if (!$session->test_regular_file_readable($list_file)) {
next;
@@ -1588,6 +1634,11 @@ sub cleanup_apt_archive {
$session->unlink($self->get('Extra repositories archive list file'),
{ FORCE => 1 });
+ for my $file (@{ $self->get('Extra repository files') }) {
+ $session->unlink($file, { FORCE => 1 });
+ }
+ $self->set('Extra repository files', undef);
+
$session->unlink($self->get('Extra packages archive list file'),
{ FORCE => 1 });
diff --git a/man/sbuild.1.in b/man/sbuild.1.in
index 36f217fe..d8a6d40b 100644
--- a/man/sbuild.1.in
+++ b/man/sbuild.1.in
@@ -105,6 +105,7 @@ sbuild \- build debian packages from source
.RB [ \-\-resolve\-alternatives \[or] \-\-no\-resolve\-alternatives ]
.RB [ \-\-extra\-package=\fIpackage.deb|directory\fP ]
.RB [ \-\-extra\-repository=\fIspec\fP ]
+.RB [ \-\-extra\-repository\-file=\fIpath\fP ]
.RB [ \-\-extra\-repository\-key=\fIfile.asc\fP ]
.RB [ \-\-build\-path=\fIstring\fP ]
.RB [ \-\-dsc\-dir=\fIstring\fP ]
@@ -338,7 +339,8 @@ Run (or do not run) apt\-get update in the chroot before executing the build.
This option only applies to the default repositories of the chroot: the
internal sbuild apt repository, the repository for extra packages (see
\fB\-\-extra\-package\fP) and any repositories set via
-\fB\-\-extra\-repository\fP are always updated. It is not recommended to use
+\fB\-\-extra\-repository\fP or \fB\-\-extra\-repository-file\fP
+are always updated. It is not recommended to use
\fB\-\-no\-apt\-update\fP because you should build using the latest available
packages in each distribution. If you do disable updates you need to ensure
that the chroot contains downloaded package lists or apt will be unable to
@@ -1110,6 +1112,24 @@ This command line option appends to the \fBEXTRA_REPOSITORIES\fP configuration v
.BR sbuild.conf (5)
for more information.
.TP
+.BR \-\-extra\-repository\-file=\fIpath\fP
+Add the apt source file \fIpath\fP (a path on the host system) to the list
+of apt sources for the duration of the package build. The file is expected
+to contain one or more apt sources in the Deb822 format (as used by files
+ending in \fI.sources\fP in
+.BR /etc/apt/sources.list.d ;
+see
+.BR sources.list(5)
+for details)
+and is copied into the chroot before the first apt update and removed again
+when the build finishes. The Deb822 format makes it possible to bind a
+repository key directly to the repository via the \fISigned-By\fP field,
+instead of installing the key into
+.B /etc/apt/trusted.gpg.d.
+This command line option appends to the \fBEXTRA_REPOSITORY_FILES\fP configuration variable. See
+.BR sbuild.conf (5)
+for more information.
+.TP
.BR \-\-extra\-repository\-key=\fIfile.asc\fP
Add \fIfile.asc\fP to the list of trusted keys inside the chroot. The key is
read from the filename given, and added to the trusted keys. For more
diff --git a/test/sbuild-options-parsing.t b/test/sbuild-options-parsing.t
index f103699f..cc132408 100755
--- a/test/sbuild-options-parsing.t
+++ b/test/sbuild-options-parsing.t
@@ -250,6 +250,10 @@ sub main {
'extra-repository=s' => sub {
check_option_value($_[0]->get_conf('EXTRA_REPOSITORIES'), $_[1]);
},
+ 'extra-repository-file=s' => sub {
+ check_option_value($_[0]->get_conf('EXTRA_REPOSITORY_FILES'),
+ $_[1]);
+ },
'extra-repository-key=s' => sub {
check_option_value($_[0]->get_conf('EXTRA_REPOSITORY_KEYS'),
$_[1]);
--
2.47.3