From f236f6df36e7e8077ff33304a1bf5dbc5c6b7122 Mon Sep 17 00:00:00 2001 From: Giel van Schijndel Date: Mon, 13 May 2024 10:42:41 +0200 Subject: [PATCH] swap: forward discardPolicy option to randomEncryption.allowDiscards I.e. instead of effectively ignoring `discardPolicy` when combined with `randomEncryption`, or adding a second option requiring the user to repeat themselves (DRY violation), just enable both when requested via `discardPolicy`. Without this `discardPolicy` is a NOP when `randomEncryption` is enabled. --- lib/types/swap.nix | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/types/swap.nix b/lib/types/swap.nix index d56871a..0cb4270 100644 --- a/lib/types/swap.nix +++ b/lib/types/swap.nix @@ -92,7 +92,12 @@ default = [{ swapDevices = [{ device = config.device; - inherit (config) discardPolicy priority randomEncryption; + inherit (config) discardPolicy priority; + randomEncryption = { + enable = config.randomEncryption; + # forward discard/TRIM attempts through dm-crypt + allowDiscards = config.discardPolicy != null; + }; }]; boot.resumeDevice = lib.mkIf config.resumeDevice config.device; }];