* Add a ‘size’ option to ‘swapDevices’ to create swapfiles on the fly.

svn path=/nixos/trunk/; revision=34478
This commit is contained in:
Eelco Dolstra 2012-06-12 13:41:51 +00:00
parent 03653d43eb
commit 15d44498f9
2 changed files with 23 additions and 3 deletions

View file

@ -33,13 +33,22 @@ with pkgs.lib;
device = mkOption {
example = "/dev/sda3";
type = types.string;
type = types.uniq types.string;
description = "Path of the device.";
};
label = mkOption {
example = "swap";
type = types.string;
type = types.uniq types.string;
description = ''
Label of the device. Can be used instead of <varname>device</varname>.
'';
};
size = mkOption {
default = null;
example = "swap";
type = types.nullOr types.int;
description = ''
Label of the device. Can be used instead of <varname>device</varname>.
'';

View file

@ -22,7 +22,7 @@ let
# Swap devices.
${flip concatMapStrings config.swapDevices (sw:
"${sw.device} none swap\n"
"${sw.device} none swap\n"
)}
'';
@ -213,6 +213,17 @@ in
${flip concatMapStrings config.fileSystems (fs: optionalString fs.autocreate ''
mkdir -p -m 0755 '${fs.mountPoint}'
'')}
# Create missing swapfiles.
# FIXME: support changing the size of existing swapfiles.
${flip concatMapStrings config.swapDevices (sw: optionalString (sw.size != null) ''
if [ ! -e "${sw.device}" -a -e "$(dirname "${sw.device}")" ]; then
# FIXME: use fallocate on filesystems that support it.
dd if=/dev/zero of="${sw.device}" bs=1M count=${toString sw.size}
mkswap ${sw.device}
fi
'')}
'';
daemonType = "daemon";