nixpkgs/upstart-jobs/swap.nix
Eelco Dolstra c78a1d9781 * Upstart job to start swapping to the devices or files listed in the
swapDevices option.

svn path=/nixos/trunk/; revision=7448
2006-12-21 01:07:23 +00:00

30 lines
653 B
Nix

{utillinux, swapDevices}:
{
name = "swap";
job = "
start on startup
script
for device in ${toString swapDevices}; do
# !!! Check whether we are already swapping to $device.
${utillinux}/sbin/swapon \"$device\" || true
done
# Remove swap devices not listed in swapDevices.
for used in $(cat /proc/swaps | grep '^/' | sed 's/ .*//'); do
found=
for device in ${toString swapDevices}; do
if test \"$used\" = \"$device\"; then found=1; fi
done
if test -z \"$found\"; then
${utillinux}/sbin/swapoff \"$used\" || true
fi
done
end script
";
}