forked from mirrors/nixpkgs
* Allow swap devices to be specified by label.
svn path=/nixos/trunk/; revision=7609
This commit is contained in:
parent
cb10364838
commit
24e34612e3
|
@ -9,7 +9,9 @@
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
swapDevices = ["/dev/sdb1"];
|
swapDevices = [
|
||||||
|
{ device = "/dev/sdb1"; }
|
||||||
|
];
|
||||||
|
|
||||||
services = {
|
services = {
|
||||||
sshd = {
|
sshd = {
|
||||||
|
|
|
@ -212,10 +212,19 @@
|
||||||
{
|
{
|
||||||
name = ["swapDevices"];
|
name = ["swapDevices"];
|
||||||
default = [];
|
default = [];
|
||||||
example = ["/dev/hda7" "/dev/hdb3" "/var/swapfile"];
|
example = [
|
||||||
|
{device="/dev/hda7";}
|
||||||
|
{device="/var/swapfile";}
|
||||||
|
{label="bigswap";}
|
||||||
|
];
|
||||||
description = "
|
description = "
|
||||||
The swap devices and swap files. These must have been
|
The swap devices and swap files. These must have been
|
||||||
initialised using <command>mkswap</command>.
|
initialised using <command>mkswap</command>. Each element
|
||||||
|
should be an attribute set specifying either the path of the
|
||||||
|
swap device or file (<literal>device</literal>) or the label
|
||||||
|
of the swap device (<literal>label</literal>, see
|
||||||
|
<command>mkswap -L</command</command>). Using a label is
|
||||||
|
recommended.
|
||||||
";
|
";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,7 @@ import ../upstart-jobs/gather.nix {
|
||||||
|
|
||||||
# Swapping.
|
# Swapping.
|
||||||
(import ../upstart-jobs/swap.nix {
|
(import ../upstart-jobs/swap.nix {
|
||||||
inherit (pkgs) utillinux;
|
inherit (pkgs) utillinux library;
|
||||||
swapDevices = config.get ["swapDevices"];
|
swapDevices = config.get ["swapDevices"];
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,14 @@
|
||||||
{utillinux, swapDevices}:
|
{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";
|
name = "swap";
|
||||||
|
@ -8,21 +18,25 @@ start on startup
|
||||||
start on new-devices
|
start on new-devices
|
||||||
|
|
||||||
script
|
script
|
||||||
for device in ${toString swapDevices}; do
|
for device in ${toString devicesByPath}; do
|
||||||
# !!! Check whether we are already swapping to $device.
|
|
||||||
${utillinux}/sbin/swapon \"$device\" || true
|
${utillinux}/sbin/swapon \"$device\" || true
|
||||||
done
|
done
|
||||||
|
|
||||||
# Remove swap devices not listed in swapDevices.
|
for label in ${toString devicesByLabel}; do
|
||||||
for used in $(cat /proc/swaps | grep '^/' | sed 's/ .*//'); do
|
${utillinux}/sbin/swapon -L \"$label\" || true
|
||||||
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
|
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
|
end script
|
||||||
";
|
";
|
||||||
|
|
Loading…
Reference in a new issue