Convert "swap"

svn path=/nixos/branches/fix-style/; revision=14402
This commit is contained in:
Marc Weber 2009-03-06 12:27:35 +00:00
parent d964466c1a
commit ed8bfc1c78
3 changed files with 43 additions and 37 deletions

View File

@ -422,6 +422,8 @@ in
(import ../upstart-jobs/filesystems.nix) # Mount file systems. (import ../upstart-jobs/filesystems.nix) # Mount file systems.
(import ../upstart-jobs/swap.nix)
# security # security
(import ../system/sudo.nix) (import ../system/sudo.nix)

View File

@ -71,12 +71,6 @@ let
jobs = map makeJob jobs = map makeJob
([ ([
# Swapping.
(import ../upstart-jobs/swap.nix {
inherit (pkgs) utillinux lib;
swapDevices = config.swapDevices;
})
# Network interfaces. # Network interfaces.
(import ../upstart-jobs/network-interfaces.nix { (import ../upstart-jobs/network-interfaces.nix {
inherit modprobe config; inherit modprobe config;

View File

@ -1,7 +1,13 @@
{lib, utillinux, swapDevices}: {pkgs, config, ...}:
###### implementation
let let
inherit (pkgs) utillinux lib;
swapDevices = config.swapDevices;
devicesByPath = devicesByPath =
map (x: x.device) (lib.filter (x: x ? device) swapDevices); map (x: x.device) (lib.filter (x: x ? device) swapDevices);
@ -10,35 +16,39 @@ let
in in
{ {
name = "swap"; services = {
extraJobs = [{
name = "swap";
job = " job = "
start on startup start on startup
start on new-devices start on new-devices
script script
for device in ${toString devicesByPath}; do for device in ${toString devicesByPath}; do
${utillinux}/sbin/swapon \"$device\" || true ${utillinux}/sbin/swapon \"$device\" || true
done done
for label in ${toString devicesByLabel}; do for label in ${toString devicesByLabel}; do
${utillinux}/sbin/swapon -L \"$label\" || true ${utillinux}/sbin/swapon -L \"$label\" || true
done done
# Remove swap devices not listed in swapDevices. # Remove swap devices not listed in swapDevices.
# !!! disabled because it doesn't work with labels # !!! disabled because it doesn't work with labels
#for used in $(cat /proc/swaps | grep '^/' | sed 's/ .*//'); do #for used in $(cat /proc/swaps | grep '^/' | sed 's/ .*//'); do
# found= # found=
# for device in $ {toString swapDevices}; do # for device in $ {toString swapDevices}; do
# if test \"$used\" = \"$device\"; then found=1; fi # if test \"$used\" = \"$device\"; then found=1; fi
# done # done
# if test -z \"$found\"; then # if test -z \"$found\"; then
# ${utillinux}/sbin/swapoff \"$used\" || true # ${utillinux}/sbin/swapoff \"$used\" || true
# fi # fi
#done #done
end script
";
end script
";
}];
};
} }