From 8a3a429da6c149c743498b41e2bd6a36f6963d65 Mon Sep 17 00:00:00 2001 From: bb2020 Date: Fri, 23 Jul 2021 23:06:36 +0300 Subject: [PATCH] nixos/swap: add randomEncryption.allowDiscards option --- nixos/modules/config/swap.nix | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/nixos/modules/config/swap.nix b/nixos/modules/config/swap.nix index ff2ae1da31bd..9b005021086b 100644 --- a/nixos/modules/config/swap.nix +++ b/nixos/modules/config/swap.nix @@ -47,6 +47,15 @@ let ''; }; + allowDiscards = mkOption { + default = false; + type = types.bool; + description = '' + Whether to allow TRIM requests to the underlying device. This option + has security implications; please read the LUKS documentation before + activating it. + ''; + }; }; }; @@ -224,7 +233,8 @@ in fi ''} ${optionalString sw.randomEncryption.enable '' - cryptsetup plainOpen -c ${sw.randomEncryption.cipher} -d ${sw.randomEncryption.source} ${optionalString (sw.discardPolicy != null) "--allow-discards"} ${sw.device} ${sw.deviceName} + cryptsetup plainOpen -c ${sw.randomEncryption.cipher} -d ${sw.randomEncryption.source} \ + ${optionalString sw.randomEncryption.allowDiscards "--allow-discards"} ${sw.device} ${sw.deviceName} mkswap ${sw.realDevice} ''} '';