forked from aylac.top/nixcfg
this repo has no description

swap and hibernation

aylac.top 883d3162 fed1412a

verified
Changed files
+90 -3
hosts
morgana
modules
hardware
profiles
nixos
profiles
+10
hosts/morgana/default.nix
···
snapshots = true;
};
tmpOnTmpfs.enable = true;
+
+
hibernation = {
+
enable = true;
+
swap = {
+
size = 24576;
+
location = "/data/.swapfile";
+
keyFile = "/.swapkey";
+
blkDev = "/dev/disk/by-uuid/e88969b5-98a0-4d46-a059-8e07ebf2689e";
+
};
+
};
};
desktop.gnome.enable = true;
services = {
+2 -2
modules/hardware/profiles/base/default.nix
···
fstrim.enable = true;
logind.settings.Login = {
-
HandlePowerKey = "suspend";
-
HandlePowerKeyLongPress = "poweroff";
+
HandlePowerKey = lib.mkDefault "suspend";
+
HandlePowerKeyLongPress = lib.mkDefault "poweroff";
};
xserver.xkb = {
+1
modules/nixos/profiles/default.nix
···
./backups
./base
./btrfs
+
./hibernation
./workstation
./server
./autoUpgrade
+53
modules/nixos/profiles/hibernation/default.nix
···
+
{
+
config,
+
lib,
+
...
+
}: {
+
options.myNixOS.profiles.hibernation = {
+
enable = lib.mkEnableOption "enable hibernation";
+
swap = {
+
size = lib.mkOption {
+
default = 0;
+
description = "Swap size in megabytes.";
+
type = lib.types.int;
+
};
+
+
location = lib.mkOption {
+
default = "/.swap";
+
description = "Swap file location.";
+
type = lib.types.path;
+
};
+
+
keyFile = lib.mkOption {
+
default = "/.swapkey";
+
description = "Location of the encryption key.";
+
type = lib.types.path;
+
};
+
+
blkDev = lib.mkOption {
+
default = "/dev/sda1";
+
description = "Block device for swap file.";
+
type = lib.types.path;
+
};
+
};
+
};
+
+
config = lib.mkIf (config.myNixOS.profiles.hibernation.enable && config.myNixOS.profiles.hibernation.swap.size > 0) {
+
myNixOS.profiles.swap = {
+
enable = true;
+
random = false;
+
inherit (config.myNixOS.profiles.hibernation.swap) size location keyFile blkDev;
+
};
+
+
services.logind.settings.Login = {
+
HandleLidSwitch = "suspend-then-hibernate";
+
HandlePowerKey = "suspend-then-hibernate";
+
};
+
+
systemd.sleep.extraConfig = ''
+
HibernateDelaySec=15m
+
AllowSuspendThenHibernate=yes
+
HibernateOnACPower=no
+
'';
+
};
+
}
+24 -1
modules/nixos/profiles/swap/default.nix
···
description = "Swap file location.";
type = lib.types.path;
};
+
+
random = lib.mkOption {
+
default = true;
+
description = "Enable random encryption for swap file.";
+
type = lib.types.bool;
+
};
+
+
keyFile = lib.mkOption {
+
default = "/.swapkey";
+
description = "Location of the encryption key.";
+
type = lib.types.path;
+
};
+
+
blkDev = lib.mkOption {
+
default = "/dev/sda1";
+
description = "Block device for swap file.";
+
type = lib.types.path;
+
};
};
config = lib.mkIf config.myNixOS.profiles.swap.enable {
···
{
device = config.myNixOS.profiles.swap.location;
priority = 0;
-
randomEncryption.enable = true;
+
randomEncryption.enable = config.myNixOS.profiles.swap.random;
+
encrypted = lib.mkIf (!config.myNixOS.profiles.swap.random) {
+
label = "swapfile";
+
enable = true;
+
inherit (config.myNixOS.profiles.swap) keyFile blkDev;
+
};
inherit (config.myNixOS.profiles.swap) size;
}
];