nixos/swap: remove fallocate and use dd as the main swap creation method
https://github.com/NixOS/nixpkgs/issues/144572 https://github.com/NixOS/nixpkgs/issues/91986 nixos/swap: remove expansion if else because the file is already recreated if file size is not the same as the configured size nixos/swap: remove old fixme
This commit is contained in:
parent
96c11eb49a
commit
17c61e9772
|
@ -203,7 +203,6 @@ in
|
||||||
];
|
];
|
||||||
|
|
||||||
# Create missing swapfiles.
|
# Create missing swapfiles.
|
||||||
# FIXME: support changing the size of existing swapfiles.
|
|
||||||
systemd.services =
|
systemd.services =
|
||||||
let
|
let
|
||||||
|
|
||||||
|
@ -223,11 +222,7 @@ in
|
||||||
${optionalString (sw.size != null) ''
|
${optionalString (sw.size != null) ''
|
||||||
currentSize=$(( $(stat -c "%s" "${sw.device}" 2>/dev/null || echo 0) / 1024 / 1024 ))
|
currentSize=$(( $(stat -c "%s" "${sw.device}" 2>/dev/null || echo 0) / 1024 / 1024 ))
|
||||||
if [ "${toString sw.size}" != "$currentSize" ]; then
|
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}
|
||||||
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}
|
chmod 0600 ${sw.device}
|
||||||
${optionalString (!sw.randomEncryption.enable) "mkswap ${sw.realDevice}"}
|
${optionalString (!sw.randomEncryption.enable) "mkswap ${sw.realDevice}"}
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in a new issue