[arch-projects] [devtools] [PATCH 1/2] arch-nspawn, mkarchroot: Allow not sharing the cache directories.

Maarten de Vries maarten at de-vri.es
Tue Jan 15 13:34:51 UTC 2019


These patches make it possible to build withouth a shared pacman cache
using makechrootpkg. I need this myself because I'm building packages
for different repositories where some of them contain packages with the
same name, but different compile time configuration.

It also allows building packages for different Arch based distros on the
same host more easily.

The first patch changes arch-nspawn and mkarchroot to accept `-c -` to
disable bind mounting the host pacman cache in the container.
The container will simply use whatever is configured in the container
instead.

The second patch allows the user set the pacman cache for makechrootpkg.
Sadly -c was already taken, so here it's -C.

The end result is that a user can run the following to build without
a shared pacman cache:

`makechrootpkg -C - -r $chroot`

I considered a more generic -N ... to pass arguments to arch-nspawn,
but arch-nspawn doesn't have that many options and it would get quite
ugly:

makechrootpkg -N -c -N - -r $chroot

Signed-off-by: Maarten de Vries <maarten at de-vri.es>
---
 arch-nspawn.in | 12 +++++++++---
 mkarchroot.in  |  4 +++-
 2 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/arch-nspawn.in b/arch-nspawn.in
index b9c846e..c6cc3a4 100644
--- a/arch-nspawn.in
+++ b/arch-nspawn.in
@@ -52,7 +52,9 @@ shift 1
 
 [[ -z $working_dir ]] && die 'Please specify a working directory.'
 
-if [[ -z $cache_dir ]]; then
+if [[ $cache_dir = '-' ]]; then
+	cache_dirs=()
+elif [[ -z $cache_dir ]]; then
 	cache_dirs=($(pacman -v 2>&1 | grep '^Cache Dirs:' | sed 's/Cache Dirs:\s*//g'))
 else
 	cache_dirs=("$cache_dir")
@@ -72,7 +74,9 @@ build_mount_args() {
 		mount_args+=("--bind-ro=$host_mirror_path")
 	fi
 
-	mount_args+=("--bind=${cache_dirs[0]}")
+	if [[ ${#cache_dirs[@]} -ge 1 ]]; then
+		mount_args+=("--bind=${cache_dirs[0]}")
+	fi
 
 	for cache_dir in "${cache_dirs[@]:1}"; do
 		mount_args+=("--bind-ro=$cache_dir")
@@ -92,7 +96,9 @@ copy_hostconf () {
 		cp -T "$file" "$working_dir$file"
 	done
 
-	sed -r "s|^#?\\s*CacheDir.+|CacheDir = ${cache_dirs[*]}|g" -i "$working_dir/etc/pacman.conf"
+	if [[ ${#cache_dirs[@]} -ge 1 ]]; then
+		sed -r "s|^#?\\s*CacheDir.+|CacheDir = ${cache_dirs[*]}|g" -i "$working_dir/etc/pacman.conf"
+	fi
 }
 # }}}
 
diff --git a/mkarchroot.in b/mkarchroot.in
index 52e363f..81bc58a 100644
--- a/mkarchroot.in
+++ b/mkarchroot.in
@@ -51,7 +51,9 @@ shift 1
 
 [[ -z $working_dir ]] && die 'Please specify a working directory.'
 
-if [[ -z $cache_dir ]]; then
+if [[ $cache_dir = '-' ]]; then
+	cache_dirs=()
+elif [[ -z $cache_dir ]]; then
 	cache_dirs=($(pacman -v "$cache_conf" 2>&1 | grep '^Cache Dirs:' | sed 's/Cache Dirs:\s*//g'))
 else
 	cache_dirs=(${cache_dir})
-- 
2.20.1


More information about the arch-projects mailing list