diff --git a/configuration/options.nix b/configuration/options.nix
index ec4bc85b9c48..ffcd0b61f9e0 100644
--- a/configuration/options.nix
+++ b/configuration/options.nix
@@ -14,7 +14,7 @@
description = "
Whether to find the root device automatically by searching for a
device with the right label. If this option is off, then a root
- file system must be specified using .
+ file system must be specified using .
";
}
@@ -141,7 +141,8 @@
{
- name = ["filesystems"];
+ name = ["fileSystems"];
+ default = [];
example = [
{ mountPoint = "/";
device = "/dev/hda1";
@@ -155,11 +156,12 @@
];
description = "
The file systems to be mounted. It must include an entry for
- the root directory (mountPoint = \"/\").
- Each entry in the list is an attribute set with the following
- fields: mountPoint,
- device, filesystem (a file
- system type recognised by mount; defaults to
+ the root directory (mountPoint = \"/\") if
+ boot.autoDetectRootDevice is not set. Each
+ entry in the list is an attribute set with the following fields:
+ mountPoint, device,
+ filesystem (a file system type recognised by
+ mount; defaults to
\"auto\"), autoMount (a
boolean indicating whether the file system is mounted
automatically; defaults to true) and
@@ -170,6 +172,17 @@
}
+ {
+ name = ["swapDevices"];
+ default = [];
+ example = ["/dev/hda7" "/dev/hdb3" "/var/swapfile"];
+ description = "
+ The swap devices and swap files. These must have been
+ initialised using mkswap.
+ ";
+ }
+
+
{
name = ["services" "extraJobs"];
default = [];
diff --git a/configuration/system.nix b/configuration/system.nix
index 090ecc9b3a54..e4b102d8f0cb 100644
--- a/configuration/system.nix
+++ b/configuration/system.nix
@@ -76,7 +76,7 @@ rec {
rootDevice =
(pkgs.library.findSingle (fs: fs.mountPoint == "/")
(abort "No root mount point declared.")
- (config.get ["filesystems"])).device;
+ (config.get ["fileSystems"])).device;
rootLabel = config.get ["boot" "rootLabel"];
inherit stage2Init;
modulesDir = modulesClosure;
diff --git a/configuration/upstart.nix b/configuration/upstart.nix
index d6249fc0294d..5de0164b062a 100644
--- a/configuration/upstart.nix
+++ b/configuration/upstart.nix
@@ -31,6 +31,12 @@ import ../upstart-jobs/gather.nix {
inherit (pkgs) kernel module_init_tools;
})
+ # Swapping.
+ (import ../upstart-jobs/swap.nix {
+ inherit (pkgs) utillinux;
+ swapDevices = config.get ["swapDevices"];
+ })
+
# Network interfaces.
(import ../upstart-jobs/network-interfaces.nix {
inherit (pkgs) nettools kernel module_init_tools;
diff --git a/instances/examples/basic.nix b/instances/examples/basic.nix
index f77b8101bb70..b72f3f64d485 100644
--- a/instances/examples/basic.nix
+++ b/instances/examples/basic.nix
@@ -5,11 +5,13 @@
grubDevice = "/dev/hda";
};
- filesystems = [
+ fileSystems = [
{ mountPoint = "/";
device = "/dev/hda1";
}
];
+
+ swapDevices = ["/dev/hdb1"];
services = {
sshd = {
diff --git a/upstart-jobs/swap.nix b/upstart-jobs/swap.nix
new file mode 100644
index 000000000000..b7487da77846
--- /dev/null
+++ b/upstart-jobs/swap.nix
@@ -0,0 +1,29 @@
+{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
+ ";
+
+}