diff options
author | Nikolay Amiantov <ab@fmap.me> | 2016-07-08 20:36:44 +0300 |
---|---|---|
committer | Nikolay Amiantov <ab@fmap.me> | 2016-07-08 20:36:44 +0300 |
commit | 8b92103ae8de028374b13203f1c9c3e87810246c (patch) | |
tree | 35909fb0493fe14b4951511e85c77144d1baabf0 /nixos/modules/config | |
parent | 4ae98c20644c414ccbf8720696b4dddf54ea0cc3 (diff) | |
parent | 7921e6873480070cc42696091884361d2ebb647b (diff) | |
download | nixlib-8b92103ae8de028374b13203f1c9c3e87810246c.tar nixlib-8b92103ae8de028374b13203f1c9c3e87810246c.tar.gz nixlib-8b92103ae8de028374b13203f1c9c3e87810246c.tar.bz2 nixlib-8b92103ae8de028374b13203f1c9c3e87810246c.tar.lz nixlib-8b92103ae8de028374b13203f1c9c3e87810246c.tar.xz nixlib-8b92103ae8de028374b13203f1c9c3e87810246c.tar.zst nixlib-8b92103ae8de028374b13203f1c9c3e87810246c.zip |
Merge branch 'master' into staging
Diffstat (limited to 'nixos/modules/config')
-rw-r--r-- | nixos/modules/config/swap.nix | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/nixos/modules/config/swap.nix b/nixos/modules/config/swap.nix index f0353c5a35ec..62b6e011713e 100644 --- a/nixos/modules/config/swap.nix +++ b/nixos/modules/config/swap.nix @@ -30,8 +30,7 @@ let description = '' If this option is set, ‘device’ is interpreted as the path of a swapfile that will be created automatically - with the indicated size (in megabytes) if it doesn't - exist. + with the indicated size (in megabytes). ''; }; @@ -132,9 +131,13 @@ in script = '' ${optionalString (sw.size != null) '' - if [ ! -e "${sw.device}" ]; then + currentSize=$(( $(stat -c "%s" "${sw.device}" 2>/dev/null || echo 0) / 1024 / 1024 )) + if [ "${toString sw.size}" != "$currentSize" ]; then fallocate -l ${toString sw.size}M "${sw.device}" || dd if=/dev/zero of="${sw.device}" bs=1M count=${toString sw.size} + if [ "${toString sw.size}" -lt "$currentSize" ]; then + truncate --size "${toString sw.size}M" "${sw.device}" + fi chmod 0600 ${sw.device} ${optionalString (!sw.randomEncryption) "mkswap ${sw.realDevice}"} fi |