* Add a ‘size’ option to ‘swapDevices’ to create swapfiles on the fly.
svn path=/nixos/trunk/; revision=34478
This commit is contained in:
parent
03653d43eb
commit
15d44498f9
@ -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>.
|
||||
'';
|
||||
|
@ -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";
|
||||
|
Loading…
Reference in New Issue
Block a user