···
realDevice' = utils.escapeSystemdPath sw.realDevice;
271
+
btrfsInSystem = config.boot.supportedFilesystems.btrfs or false;
lib.nameValuePair "mkswap-${sw.deviceName}" {
description = "Initialisation of swap device ${sw.device}";
···
291
+
++ lib.optional btrfsInSystem pkgs.btrfs-progs
++ lib.optional sw.randomEncryption.enable pkgs.cryptsetup;
environment.DEVICE = sw.device;
···
${lib.optionalString (sw.size != null) ''
currentSize=$(( $(stat -c "%s" "$DEVICE" 2>/dev/null || echo 0) / 1024 / 1024 ))
if [[ ! -b "$DEVICE" && "${toString sw.size}" != "$currentSize" ]]; then
298
-
# Disable CoW for CoW based filesystems like BTRFS.
299
-
truncate --size 0 "$DEVICE"
300
-
chattr +C "$DEVICE" 2>/dev/null || true
300
+
if [[ $(stat -f -c %T $(dirname "$DEVICE")) == "btrfs" ]]; then
301
+
# Use btrfs mkswapfile to speed up the creation of swapfile.
303
+
btrfs filesystem mkswapfile --size "${toString sw.size}M" --uuid clear "$DEVICE"
305
+
# Disable CoW for CoW based filesystems.
306
+
truncate --size 0 "$DEVICE"
307
+
chattr +C "$DEVICE" 2>/dev/null || true
302
-
echo "Creating swap file using dd and mkswap."
303
-
dd if=/dev/zero of="$DEVICE" bs=1M count=${toString sw.size} status=progress
304
-
${lib.optionalString (!sw.randomEncryption.enable) "mkswap ${sw.realDevice}"}
309
+
echo "Creating swap file using dd and mkswap."
310
+
dd if=/dev/zero of="$DEVICE" bs=1M count=${toString sw.size} status=progress
311
+
${lib.optionalString (!sw.randomEncryption.enable) "mkswap ${sw.realDevice}"}
${lib.optionalString sw.randomEncryption.enable ''