summary refs log tree commit diff
path: root/nixos
diff options
context:
space:
mode:
authorArtturin <Artturin@artturin.com>2021-11-13 17:04:42 +0200
committerArtturin <Artturin@artturin.com>2021-11-13 17:49:42 +0200
commit17c61e97723ef2b10b60fd497b0e4eebe3b8655c (patch)
tree4c80fc3743b92148a80cc507f645ded9851a260c /nixos
parent96c11eb49a2427aacf7995e24417eef10a0f1f66 (diff)
downloadnixpkgs-17c61e97723ef2b10b60fd497b0e4eebe3b8655c.tar
nixpkgs-17c61e97723ef2b10b60fd497b0e4eebe3b8655c.tar.gz
nixpkgs-17c61e97723ef2b10b60fd497b0e4eebe3b8655c.tar.bz2
nixpkgs-17c61e97723ef2b10b60fd497b0e4eebe3b8655c.tar.lz
nixpkgs-17c61e97723ef2b10b60fd497b0e4eebe3b8655c.tar.xz
nixpkgs-17c61e97723ef2b10b60fd497b0e4eebe3b8655c.tar.zst
nixpkgs-17c61e97723ef2b10b60fd497b0e4eebe3b8655c.zip
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
Diffstat (limited to 'nixos')
-rw-r--r--nixos/modules/config/swap.nix7
1 files changed, 1 insertions, 6 deletions
diff --git a/nixos/modules/config/swap.nix b/nixos/modules/config/swap.nix
index 9b005021086..2b94b954cb8 100644
--- a/nixos/modules/config/swap.nix
+++ b/nixos/modules/config/swap.nix
@@ -203,7 +203,6 @@ in
     ];
 
     # Create missing swapfiles.
-    # FIXME: support changing the size of existing swapfiles.
     systemd.services =
       let
 
@@ -223,11 +222,7 @@ in
                 ${optionalString (sw.size != null) ''
                   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
+                    dd if=/dev/zero of="${sw.device}" bs=1M count=${toString sw.size}
                     chmod 0600 ${sw.device}
                     ${optionalString (!sw.randomEncryption.enable) "mkswap ${sw.realDevice}"}
                   fi