A nix flake to help you build systemd portable services.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
portable-svc/build-rootfs.sh

38 lines
997 B

source $stdenv/setup
set -o pipefail
# basic file system layout
mkdir -p $out/etc $out/proc $out/sys $out/dev $out/run $out/tmp $out/var/tmp $out/var/lib/private/$serviceName $out/var/log $out/var/cache/private/$serviceName
ln -sf /var/cache/private/$serviceName $out/var/cache/$serviceName
ln -sf /var/lib/private/$serviceName $out/var/lib/$serviceName
# empty files to mount over with host's version
touch $out/etc/resolv.conf $out/etc/machine-id
# required for portable services
cp ${osRelease} $out/etc/os-release
# units must be copied to /etc/…
mkdir -p $out/etc/systemd/system
units=($units)
unitNames=($unitNames)
for ((n = 0; n < ${#units[*]}; n++)); do
unit=${units[$n]}
unitName=${unitNames[$n]}
cp $unit $out/etc/systemd/system/$unitName
done
# symlinks
objects=($objects)
targets=($targets)
for ((n = 0; n < ${#objects[*]}; n++)); do
object=${objects[$n]}
target=${targets[$n]}
mkdir -p $(dirname $out/$target)
ln -s $object $out/$target
done