mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-12-27 08:04:14 +00:00
24e34612e3
svn path=/nixos/trunk/; revision=7609
45 lines
985 B
Nix
45 lines
985 B
Nix
{library, utillinux, swapDevices}:
|
|
|
|
let
|
|
|
|
devicesByPath =
|
|
map (x: x.device) (library.filter (x: x ? device) swapDevices);
|
|
|
|
devicesByLabel =
|
|
map (x: x.label) (library.filter (x: x ? label) swapDevices);
|
|
|
|
in
|
|
|
|
{
|
|
name = "swap";
|
|
|
|
job = "
|
|
start on startup
|
|
start on new-devices
|
|
|
|
script
|
|
for device in ${toString devicesByPath}; do
|
|
${utillinux}/sbin/swapon \"$device\" || true
|
|
done
|
|
|
|
for label in ${toString devicesByLabel}; do
|
|
${utillinux}/sbin/swapon -L \"$label\" || true
|
|
done
|
|
|
|
# Remove swap devices not listed in swapDevices.
|
|
# !!! disabled because it doesn't work with labels
|
|
#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
|
|
";
|
|
|
|
}
|