Building the development container
A reproducible GNU Guix Linux container can be created with a channels file listing the source repository and commit ID as well as a manifest file listing the set of packages to be installed.
The container can be packaged using one of several formats. To build a Docker image:
guix time-machine \
--channels=channels.scm \
-- pack \
--format=docker \
--compression=xz \
--save-provenance \
--symlink=/bin=bin \
--symlink=/sbin=sbin \
--system=x86_64-linux \
--manifest=manifest/manifest.scmWhen building and installing a simple tarball, relocatable packages can be
installed anywhere in the filesystem. The double --relocatable creates
"really relocatable" binaries with fallback methods when user namespaces are
not available in the kernel.
To instantiate the user environment source gnu/store/*-profile/etc/profile.
guix time-machine \
--channels=channels.scm \
-- pack \
--compression=xz \
--save-provenance \
--symlink=/bin=bin \
--symlink=/sbin=sbin \
--system=x86_64-linux \
--relocatable --relocatable \
--manifest=manifest/manifest.scmThe provided channels and manifest file were originally exported from a profile on a running GNU Guix system but can be updated in place.
guix package \
--export-channelsguix package \
--export-manifestThe last output lines from the pack command list the derivation and output files. The derivation file (with a '.drv' suffix) is a text file describing the build configuration.
building /gnu/store/...-cmake-make-ninja-pkg-config-gdb-lldb-docker-pack.tar.xz.drv...
/gnu/store/...-cmake-make-ninja-pkg-config-gdb-lldb-docker-pack.tar.xzThe container file can be loaded as a Docker image.
docker load < /gnu/store/...-cmake-make-ninja-pkg-config-gdb-lldb-docker-pack.tar.xzCopying packages to a remote system
Setting up the environment ...
ARCH=aarch64
REMOTE=172.31.X.YA single, pre-built package can be copied.
guix copy --to=$REMOTE $(guix build --dry-run /gnu/store/<hash>-<package name>.drv)All packages in a profile, in all profiles, can be copied. This assumes that the profiles are stored, as below, in this user-created directory.
guix copy --to=$REMOTE $(readlink -f /var/guix/profiles/per-user/${ARCH}/*)All installed builds can be copied, filtered by architecture. The regex filters out non-built packages. This can be slow.
OUTPUT=()
for DRV in /gnu/store/*.drv ; do
if [[ $(<$DRV) =~ ${ARCH}-linux ]] ; then
BUILD=$(guix build --dry-run $DRV 2>&1)
if [[ $BUILD =~ ^/gnu/store/.*$ ]]; then
OUTPUT+=($BUILD)
fi
fi
done
guix copy --to=$REMOTE ${OUTPUT[@]}Another attempt at copying all installed builds. This is faster since the derivation files are searched (quite inefficiently) using bash regular expressions. This errors when attempting to copy non-built packages.
TO_COPY=()
REGEX='\("[^"]*","(/gnu/store/[^"]*)"'
for DRV in /gnu/store/*.drv ; do
echo $DRV
if [[ $(<$DRV) =~ ${ARCH}-linux ]] ; then
CONTENTS=$(<$DRV)
while [[ $CONTENTS =~ $REGEX ]] ; do
TO_COPY+=(${BASH_REMATCH[1]})
# trim off the portion already matched
CONTENTS="${CONTENTS#*${BASH_REMATCH[1]}}"
done
fi
done
guix copy --to=$REMOTE ${TO_COPY[@]}Copying the profile from a remote system
The "--system" flag to guix build and guix pack permit building and
compiling Guix packages remotely using offload builds. Unfortunately,
guix package has no such flag and therefore cannot be used to create profiles
for preventing package deletion during guix gc garbage collection. The profile
must be created on and copied from the offload host. This includes the guix
build for each channel and inferior.
ARCH=aarch64
COMMIT=ΑΒΓΔΕΖΗΘ
REMOTE=172.31.X.Y
# copy 'current guix'
ssh $REMOTE -- guix pull --commit=$COMMIT
CURRENT_GUIX=$(ssh $REMOTE readlink -f /var/guix/profiles/per-user/${USER}/current-guix)
guix copy --from=$REMOTE $CURRENT_GUIX
sudo ln --force --no-dereference --symbolic $CURRENT_GUIX /var/guix/profiles/per-user/${ARCH}/current-guix-$COMMIT
# copy 'guix profile'
ssh $REMOTE -- /path/to/update_profile.sh
GUIX_PROFILE=$(ssh $REMOTE readlink -f .guix-profile)
guix copy --from=$REMOTE $GUIX_PROFILE
sudo ln --force --no-dereference --symbolic $GUIX_PROFILE /var/guix/profiles/per-user/${ARCH}/guix-profile