Loading nixos/modules/config/swap.nix +15 −7 Original line number Diff line number Diff line Loading @@ -268,6 +268,7 @@ in sw: let realDevice' = utils.escapeSystemdPath sw.realDevice; btrfsInSystem = config.boot.supportedFilesystems.btrfs or false; in lib.nameValuePair "mkswap-${sw.deviceName}" { description = "Initialisation of swap device ${sw.device}"; Loading @@ -287,6 +288,7 @@ in pkgs.util-linux pkgs.e2fsprogs ] ++ lib.optional btrfsInSystem pkgs.btrfs-progs ++ lib.optional sw.randomEncryption.enable pkgs.cryptsetup; environment.DEVICE = sw.device; Loading @@ -295,7 +297,12 @@ in ${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 # Disable CoW for CoW based filesystems like BTRFS. if [[ $(stat -f -c %T $(dirname "$DEVICE")) == "btrfs" ]]; then # Use btrfs mkswapfile to speed up the creation of swapfile. rm -f "$DEVICE" btrfs filesystem mkswapfile --size "${toString sw.size}M" --uuid clear "$DEVICE" else # Disable CoW for CoW based filesystems. truncate --size 0 "$DEVICE" chattr +C "$DEVICE" 2>/dev/null || true Loading @@ -303,6 +310,7 @@ in dd if=/dev/zero of="$DEVICE" bs=1M count=${toString sw.size} status=progress ${lib.optionalString (!sw.randomEncryption.enable) "mkswap ${sw.realDevice}"} fi fi ''} ${lib.optionalString sw.randomEncryption.enable '' cryptsetup plainOpen -c ${sw.randomEncryption.cipher} -d ${sw.randomEncryption.source} \ Loading Loading
nixos/modules/config/swap.nix +15 −7 Original line number Diff line number Diff line Loading @@ -268,6 +268,7 @@ in sw: let realDevice' = utils.escapeSystemdPath sw.realDevice; btrfsInSystem = config.boot.supportedFilesystems.btrfs or false; in lib.nameValuePair "mkswap-${sw.deviceName}" { description = "Initialisation of swap device ${sw.device}"; Loading @@ -287,6 +288,7 @@ in pkgs.util-linux pkgs.e2fsprogs ] ++ lib.optional btrfsInSystem pkgs.btrfs-progs ++ lib.optional sw.randomEncryption.enable pkgs.cryptsetup; environment.DEVICE = sw.device; Loading @@ -295,7 +297,12 @@ in ${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 # Disable CoW for CoW based filesystems like BTRFS. if [[ $(stat -f -c %T $(dirname "$DEVICE")) == "btrfs" ]]; then # Use btrfs mkswapfile to speed up the creation of swapfile. rm -f "$DEVICE" btrfs filesystem mkswapfile --size "${toString sw.size}M" --uuid clear "$DEVICE" else # Disable CoW for CoW based filesystems. truncate --size 0 "$DEVICE" chattr +C "$DEVICE" 2>/dev/null || true Loading @@ -303,6 +310,7 @@ in dd if=/dev/zero of="$DEVICE" bs=1M count=${toString sw.size} status=progress ${lib.optionalString (!sw.randomEncryption.enable) "mkswap ${sw.realDevice}"} fi fi ''} ${lib.optionalString sw.randomEncryption.enable '' cryptsetup plainOpen -c ${sw.randomEncryption.cipher} -d ${sw.randomEncryption.source} \ Loading