Add parameter for swapfile offset

This commit is contained in:
Benjamin Bädorf 2022-08-14 19:59:01 +02:00
parent ba6dfdcf53
commit 46992c46d6
No known key found for this signature in database
GPG key ID: 4406E80E13CD656C
2 changed files with 36 additions and 17 deletions

View file

@ -22,6 +22,18 @@ in
default = false; default = false;
description = "Whether the device can hibernate. This creates a swapfile at /swapfile."; description = "Whether the device can hibernate. This creates a swapfile at /swapfile.";
}; };
resumeDevice = mkOption {
type = types.str;
default = "/swapfile";
description = "The location of the hibernation resume swap file.";
};
resumeOffset = mkOption {
type = types.nullOr types.number;
default = null;
description = "The swap file offset. Can be found by running `filefrag -v $swap_file_location`. See https://wiki.archlinux.org/title/Power_management/Suspend_and_hibernate#Hibernation_into_swap_file";
};
}; };
config = { config = {
@ -38,7 +50,14 @@ in
}; };
}; };
resumeDevice = mkIf cfg.hibernation.enable "/swapfile";
resumeDevice = mkIf cfg.hibernation.enable cfg.hibernation.resumeDevice;
kernelParams = mkIf cfg.hibernation.enable [
"resume=${cfg.hibernation.resumeDevice}"
] ++ (
if (cfg.hibernation.resumeOffset == null) then builtins.abort "config.pub-solar.hibernation.resumeOffset has to be set if config.pub-solar.hibernation.enable is true."
else [ "resume_offset=${cfg.hibernation.resumeOffset}" ]
);
loader.systemd-boot.enable = true; loader.systemd-boot.enable = true;

View file

@ -1,21 +1,21 @@
{ psCfg, ... }: '' { psCfg, ... }: ''
# Set shut down, restart and locking features # Set shut down, restart and locking features
set $mode_system (e)xit, (h)ibernate, (r)eboot, (Shift+s)hutdown set $mode_system (e)xit, (h)ibernate, (r)eboot, (Shift+s)hutdown
bindsym $mod+0 mode "$mode_system" bindsym $mod+0 mode "$mode_system"
mode "$mode_system" { mode "$mode_system" {
bindsym e exec swaymsg exit, mode "default" bindsym e exec swaymsg exit, mode "default"
'' + (if !psCfg.core.allow-hibernation then '' '' + (if !psCfg.core.hibernation.enable then ''
bindsym h exec systemctl hibernate, mode "default" bindsym h exec systemctl hibernate, mode "default"
'' else "") '' else "")
+ (if !psCfg.paranoia.enable then '' + (if !psCfg.paranoia.enable then ''
bindsym l exec swaylock-bg, mode "default" bindsym l exec swaylock-bg, mode "default"
bindsym s exec systemctl suspend, mode "default" bindsym s exec systemctl suspend, mode "default"
'' else "") + '' '' else "") + ''
bindsym r exec systemctl reboot, mode "default" bindsym r exec systemctl reboot, mode "default"
bindsym Shift+s exec systemctl poweroff, mode "default" bindsym Shift+s exec systemctl poweroff, mode "default"
# exit system mode: "Enter" or "Escape" # exit system mode: "Enter" or "Escape"
bindsym Return mode "default" bindsym Return mode "default"
bindsym Escape mode "default" bindsym Escape mode "default"
} }
'' ''