From ed8bfc1c78133d9e9438271bd34bf3325f21f2f8 Mon Sep 17 00:00:00 2001 From: Marc Weber Date: Fri, 6 Mar 2009 12:27:35 +0000 Subject: [PATCH] Convert "swap" svn path=/nixos/branches/fix-style/; revision=14402 --- system/options.nix | 2 ++ upstart-jobs/default.nix | 6 ---- upstart-jobs/swap.nix | 72 +++++++++++++++++++++++----------------- 3 files changed, 43 insertions(+), 37 deletions(-) diff --git a/system/options.nix b/system/options.nix index 039f8b72403..9a502d9502e 100644 --- a/system/options.nix +++ b/system/options.nix @@ -422,6 +422,8 @@ in (import ../upstart-jobs/filesystems.nix) # Mount file systems. + (import ../upstart-jobs/swap.nix) + # security (import ../system/sudo.nix) diff --git a/upstart-jobs/default.nix b/upstart-jobs/default.nix index ca90d8bb8d3..2de4ba70760 100644 --- a/upstart-jobs/default.nix +++ b/upstart-jobs/default.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; diff --git a/upstart-jobs/swap.nix b/upstart-jobs/swap.nix index cd640b5060e..5b6b70e362f 100644 --- a/upstart-jobs/swap.nix +++ b/upstart-jobs/swap.nix @@ -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 + "; + }]; + }; }