Convert "swap"
svn path=/nixos/branches/fix-style/; revision=14402
This commit is contained in:
parent
d964466c1a
commit
ed8bfc1c78
@ -422,6 +422,8 @@ in
|
||||
|
||||
(import ../upstart-jobs/filesystems.nix) # Mount file systems.
|
||||
|
||||
(import ../upstart-jobs/swap.nix)
|
||||
|
||||
|
||||
# security
|
||||
(import ../system/sudo.nix)
|
||||
|
@ -71,12 +71,6 @@ let
|
||||
jobs = map makeJob
|
||||
([
|
||||
|
||||
# Swapping.
|
||||
(import ../upstart-jobs/swap.nix {
|
||||
inherit (pkgs) utillinux lib;
|
||||
swapDevices = config.swapDevices;
|
||||
})
|
||||
|
||||
# Network interfaces.
|
||||
(import ../upstart-jobs/network-interfaces.nix {
|
||||
inherit modprobe config;
|
||||
|
@ -1,7 +1,13 @@
|
||||
{lib, utillinux, swapDevices}:
|
||||
{pkgs, config, ...}:
|
||||
|
||||
###### implementation
|
||||
|
||||
let
|
||||
|
||||
inherit (pkgs) utillinux lib;
|
||||
|
||||
swapDevices = config.swapDevices;
|
||||
|
||||
devicesByPath =
|
||||
map (x: x.device) (lib.filter (x: x ? device) swapDevices);
|
||||
|
||||
@ -10,35 +16,39 @@ let
|
||||
|
||||
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
|
||||
";
|
||||
|
||||
services = {
|
||||
extraJobs = [{
|
||||
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
|
||||
";
|
||||
}];
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user