about summary refs log tree commit diff
path: root/modules/system
diff options
context:
space:
mode:
authoraszlig <aszlig@nix.build>2018-07-16 02:22:21 +0200
committeraszlig <aszlig@nix.build>2018-07-16 02:22:21 +0200
commit5658505b8631d28a09fc1f75481397c192e6f0eb (patch)
treeb922536bf5ed3bd6315e70929a5b292b3f449223 /modules/system
parent2c430626afff03bec16071843f0e661a43cfe2c9 (diff)
Add module for zswap
Even though these options are rather opinionated rather than generally
useful, it makes sense to have an option for that because I'm going to
use it for my managed machines as well.

Signed-off-by: aszlig <aszlig@nix.build>
Diffstat (limited to 'modules/system')
-rw-r--r--modules/system/kernel/zswap.nix38
1 files changed, 38 insertions, 0 deletions
diff --git a/modules/system/kernel/zswap.nix b/modules/system/kernel/zswap.nix
new file mode 100644
index 00000000..43b89ca6
--- /dev/null
+++ b/modules/system/kernel/zswap.nix
@@ -0,0 +1,38 @@
+{ config, lib, ... }:
+
+let
+  kernelVersion = config.boot.kernelPackages.kernel.version;
+  hasZstd = lib.versionAtLeast kernelVersion "4.18";
+in {
+  options.vuizvui.system.kernel.zswap.enable = lib.mkOption {
+    type = lib.types.bool;
+    default = false;
+    description = ''
+      Whether to enable support for zswap with the use of the
+      <literal>z3fold</literal> for pooling and <literal>zstd</literal> for
+      compression, if available (otherwise it falls back to
+      <literal>lzo</literal>).
+
+      Zswap is a compressed cache for swap pages, which is especially useful
+      for machines with limited RAM.
+    '';
+  };
+
+  config = lib.mkIf config.vuizvui.system.kernel.zswap.enable {
+    boot.kernelPatches = lib.singleton {
+      name = "zswap-config";
+      patch = null;
+      extraConfig = ''
+        CRYPTO_${if hasZstd then "ZSTD" else "LZO"} y
+        ZSWAP y
+        Z3FOLD y
+      '';
+    };
+
+    boot.kernelParams = [
+      "zswap.enabled=1"
+      "zswap.zpool=z3fold"
+      "zswap.compressor=${if hasZstd then "zstd" else "lzo"}"
+    ];
+  };
+}