From 46992c46d6521dd74c81a937ad1c1465578cbe30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20B=C3=A4dorf?= Date: Sun, 14 Aug 2022 19:59:01 +0200 Subject: [PATCH] Add parameter for swapfile offset --- modules/core/boot.nix | 21 +++++++++++- .../sway/config/config.d/mode_system.conf.nix | 32 +++++++++---------- 2 files changed, 36 insertions(+), 17 deletions(-) diff --git a/modules/core/boot.nix b/modules/core/boot.nix index 1512289c..9df859e2 100644 --- a/modules/core/boot.nix +++ b/modules/core/boot.nix @@ -22,6 +22,18 @@ in default = false; 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 = { @@ -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; diff --git a/modules/sway/config/config.d/mode_system.conf.nix b/modules/sway/config/config.d/mode_system.conf.nix index ef11a461..c505a9f5 100644 --- a/modules/sway/config/config.d/mode_system.conf.nix +++ b/modules/sway/config/config.d/mode_system.conf.nix @@ -1,21 +1,21 @@ { psCfg, ... }: '' -# Set shut down, restart and locking features -set $mode_system (e)xit, (h)ibernate, (r)eboot, (Shift+s)hutdown -bindsym $mod+0 mode "$mode_system" -mode "$mode_system" { - bindsym e exec swaymsg exit, mode "default" -'' + (if !psCfg.core.allow-hibernation then '' - bindsym h exec systemctl hibernate, mode "default" + # Set shut down, restart and locking features + set $mode_system (e)xit, (h)ibernate, (r)eboot, (Shift+s)hutdown + bindsym $mod+0 mode "$mode_system" + mode "$mode_system" { + bindsym e exec swaymsg exit, mode "default" +'' + (if !psCfg.core.hibernation.enable then '' + bindsym h exec systemctl hibernate, mode "default" '' else "") - + (if !psCfg.paranoia.enable then '' - bindsym l exec swaylock-bg, mode "default" - bindsym s exec systemctl suspend, mode "default" ++ (if !psCfg.paranoia.enable then '' + bindsym l exec swaylock-bg, mode "default" + bindsym s exec systemctl suspend, mode "default" '' else "") + '' - bindsym r exec systemctl reboot, mode "default" - bindsym Shift+s exec systemctl poweroff, mode "default" + bindsym r exec systemctl reboot, mode "default" + bindsym Shift+s exec systemctl poweroff, mode "default" - # exit system mode: "Enter" or "Escape" - bindsym Return mode "default" - bindsym Escape mode "default" -} + # exit system mode: "Enter" or "Escape" + bindsym Return mode "default" + bindsym Escape mode "default" + } ''