Featured image of post Debian APT DEB822-Style Sources List

Debian APT DEB822-Style Sources List

緣由

因為 debian:11 套件太舊,就改用 debian:bookworm (Debian 12) 當 base image,我在 Dockerfile 都會寫以下指令替換成交大的 mirror

sed -i -e 's/deb.debian.org/debian.cs.nycu.edu.tw/g' /etc/apt/sources.list

建置 image 時發現 No such file or directory,沒有 sources.list 那要怎麼下載套件?
跑了一個容器進去一看,還真的沒有 /etc/apt/sources.list,取而代之的是 /etc/apt/sources.list.d/debian.sources,網路上一查才知道 APT 1.1 後支援 DEB822-Style 格式,而 Debian 12 成為 sources list 預設格式。
會改變預設格式一定是有他們的考量,所以來看看 DEB822-Style 格式的差異吧。

One-Line-Style Format

傳統熟悉的格式,一列一個來源,多個值用逗號分隔,Options 放在 Type 後並用中括號包起來。然而這種格式只能放入一個 URI,有多個 mirror 時只能分成多列,也容易造成單列太長,還需要記參數順序,不利於人類理解與修改。

DEB822-Style Format

遵循 RFC822 格式,副檔名為 .sources,每個段落為一組來源,段落之間用空白列區隔,段落每個欄位都自成一列,多個值用空白分隔,欄位的順序並不影響,閱讀起來一瞭目然。

Options 欄位對照表

One-Line DEB822
arch Architectures
lang Languages
target Targets
pdiffs PDiffs
by-hash By-Hash
allow-insecure Allow-Insecure
trusted Trusted
signed-by Signed-By
check-valid-until Check-Valid-Until
valid-until-min Valid-Until-Min
check-date Check-Date
date-max-future Date-Max-Future
inrelease-path InRelease-Path

總結

DEB822-Style 對於電腦沒有比較好處理,但對於人類來說可讀性大幅提升,的確是一個提升 UX 的好想法。而 Debian 12 將於 2023/06/10 正式發佈,下游的 Ubuntu 預計於 23.10 引入這項改動,希望這篇文章有幫助到各位 Debian 系使用者提早適應 APT sources list 的改動。

參考資料

使用 Hugo 建立
主題 StackJimmy 設計