From 61dd3938aa9c9e5f24409e44d0e12adc974efd40 Mon Sep 17 00:00:00 2001 From: "Else, Someone" Date: Thu, 9 Oct 2025 04:14:16 +0300 Subject: [PATCH] zswap in uvms: optional/configurable --- profiles/uvms-guest.nix | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/profiles/uvms-guest.nix b/profiles/uvms-guest.nix index fb9bc1c..afcaa16 100644 --- a/profiles/uvms-guest.nix +++ b/profiles/uvms-guest.nix @@ -7,12 +7,32 @@ }: let mkIfGuest = import ../lib/mkIfMicrovmGuest.nix { inherit options config lib; }; + inherit (lib) types; in { imports = [ ./vsock-connect-guest.nix ./uvms-users.nix ]; + options = { + uvms.zswap.enable = lib.mkEnableOption "Pass zswap.enabled=1 to kernelParams (and disable zramSwap)"; + uvms.zswap.settings = lib.mkOption { + description = "Zswap kernel module configuration"; + type = types.submodule { + freeformType = types.attrsOf types.str; + options.max_pool_percent = lib.mkOption { + type = types.int; + default = 25; + description = "..."; + }; + options.compressor = lib.mkOption { + type = types.str; + default = "zstd"; + description = "..."; + }; + }; + }; + }; config = lib.mkMerge [ (mkIfGuest { microvm = { @@ -31,10 +51,21 @@ in size = 768; } ]; + systemd.services."microvm@".serviceConfig.ExecStartPost = [ + (pkgs.writeShellScript "microvm-fix-umask" '' + if [[ -e CONNECT.sock ]] ; then + chmod g+rw CONNECT.sock + fi + '') + ]; }) - { - boot.kernelParams = [ "zswap.enabled=1" ]; + (lib.mkIf config.uvms.zswap.enable { zramSwap.enable = false; - } + boot.kernelParams = + builtins.attrValues ((lib.mapAttrs ( + name: value: "zswap.${name}=${toString value}" + )) config.uvms.zswap.settings) + ++ [ "zswap.enabled=1" ]; + }) ]; }