Finally fixed hibernation
This commit is contained in:
parent
86eafdc904
commit
466cdb10b3
8 changed files with 20 additions and 418 deletions
|
|
@ -1,63 +0,0 @@
|
|||
{
|
||||
device,
|
||||
swapSize ? "16G",
|
||||
}: {
|
||||
disko.devices = {
|
||||
disk.${device} = {
|
||||
type = "disk";
|
||||
inherit device;
|
||||
content = {
|
||||
type = "gpt"; # Initialize the disk with a GPT partition table
|
||||
partitions = {
|
||||
ESP = {
|
||||
# Setup the EFI System Partition
|
||||
type = "EF00"; # Set the partition type
|
||||
size = "1000M"; # Make the partition a gig
|
||||
content = {
|
||||
type = "filesystem";
|
||||
format = "vfat"; # Format it as a FAT32 filesystem
|
||||
mountpoint = "/boot"; # Mount it to /boot
|
||||
};
|
||||
};
|
||||
primary = {
|
||||
# Setup the LVM partition
|
||||
size = "100%"; # Fill up the rest of the drive with it
|
||||
content = {
|
||||
type = "lvm_pv"; # pvcreate
|
||||
vg = "vg1";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
lvm_vg = {
|
||||
# vgcreate
|
||||
vg1 = {
|
||||
# /dev/vg1
|
||||
type = "lvm_vg";
|
||||
lvs = {
|
||||
# lvcreate
|
||||
swap = {
|
||||
# Logical Volume = "swap", /dev/vg1/swap
|
||||
size = swapSize;
|
||||
content = {
|
||||
type = "swap";
|
||||
};
|
||||
};
|
||||
root = {
|
||||
# Logical Volume = "root", /dev/vg1/root
|
||||
size = "100%FREE"; # Use the remaining space in the Volume Group
|
||||
content = {
|
||||
type = "filesystem";
|
||||
format = "ext4";
|
||||
mountpoint = "/";
|
||||
mountOptions = [
|
||||
"defaults"
|
||||
];
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
{
|
||||
device,
|
||||
mountpoint ? "/run/extraDrive",
|
||||
}: {
|
||||
disko.devices = {
|
||||
disk = {
|
||||
"${device}" = {
|
||||
inherit device;
|
||||
type = "disk";
|
||||
content = {
|
||||
type = "gpt";
|
||||
partitions = {
|
||||
root = {
|
||||
size = "100%";
|
||||
content = {
|
||||
type = "filesystem";
|
||||
format = "ext4";
|
||||
inherit mountpoint;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
@ -1,84 +0,0 @@
|
|||
{
|
||||
device ? throw "Set this to your disk device, e.g. /dev/sda",
|
||||
lib,
|
||||
...
|
||||
}:
|
||||
# IMPORTANT
|
||||
# Calculate offset using https://wiki.archlinux.org/title/Power_management/Suspend_and_hibernate#Acquire_swap_file_offset
|
||||
# AND create this config
|
||||
# {
|
||||
# boot = {
|
||||
# kernelParams = [
|
||||
# "resume_offset=YOUR_OFFSET"
|
||||
# ];
|
||||
# resumeDevice = "/dev/disk/by-label/nixos";
|
||||
# };
|
||||
#}
|
||||
{
|
||||
disko.devices = {
|
||||
disk = {
|
||||
nvme0n1 = {
|
||||
type = "disk";
|
||||
inherit device;
|
||||
content = {
|
||||
type = "gpt";
|
||||
partitions = {
|
||||
ESP = {
|
||||
label = "boot";
|
||||
name = "ESP";
|
||||
size = "512M";
|
||||
type = "EF00";
|
||||
content = {
|
||||
type = "filesystem";
|
||||
format = "vfat";
|
||||
mountpoint = "/boot";
|
||||
mountOptions = [
|
||||
"defaults"
|
||||
];
|
||||
};
|
||||
};
|
||||
luks = {
|
||||
size = "100%";
|
||||
label = "luks";
|
||||
content = {
|
||||
type = "luks";
|
||||
name = "root_vg";
|
||||
extraOpenArgs = [
|
||||
"--allow-discards"
|
||||
"--perf-no_read_workqueue"
|
||||
"--perf-no_write_workqueue"
|
||||
];
|
||||
# https://0pointer.net/blog/unlocking-luks2-volumes-with-tpm2-fido2-pkcs11-security-hardware-on-systemd-248.html
|
||||
settings = {crypttabExtraOpts = ["fido2-device=auto" "token-timeout=10"];};
|
||||
content = {
|
||||
type = "btrfs";
|
||||
extraArgs = ["-L" "nixos" "-f"];
|
||||
subvolumes = {
|
||||
"/root" = {
|
||||
mountpoint = "/";
|
||||
mountOptions = ["subvol=root" "compress=zstd" "noatime"];
|
||||
};
|
||||
"/nix" = {
|
||||
mountpoint = "/nix";
|
||||
mountOptions = ["subvol=nix" "compress=zstd" "noatime"];
|
||||
};
|
||||
"/persist" = {
|
||||
mountpoint = "/persist";
|
||||
mountOptions = ["subvol=persist" "compress=zstd" "noatime"];
|
||||
};
|
||||
"/swap" = {
|
||||
mountpoint = "/swap";
|
||||
swap.swapfile.size = "64G";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
fileSystems."/persist".neededForBoot = true;
|
||||
}
|
||||
|
|
@ -1,97 +0,0 @@
|
|||
{device ? throw "Set this to your disk device, e.g. /dev/sda", ...}: {
|
||||
disko.devices = {
|
||||
disk.main = {
|
||||
inherit device;
|
||||
type = "disk";
|
||||
content = {
|
||||
type = "gpt";
|
||||
partitions = {
|
||||
boot = {
|
||||
name = "boot";
|
||||
size = "1M";
|
||||
type = "EF02";
|
||||
};
|
||||
esp = {
|
||||
name = "ESP";
|
||||
size = "500M";
|
||||
type = "EF00";
|
||||
content = {
|
||||
type = "filesystem";
|
||||
format = "vfat";
|
||||
mountpoint = "/boot";
|
||||
};
|
||||
};
|
||||
swap = {
|
||||
size = "32G";
|
||||
content = {
|
||||
type = "swap";
|
||||
resumeDevice = true;
|
||||
};
|
||||
};
|
||||
root = {
|
||||
name = "root";
|
||||
size = "100%";
|
||||
content = {
|
||||
type = "lvm_pv";
|
||||
vg = "root_vg";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
lvm_vg = {
|
||||
root_vg = {
|
||||
type = "lvm_vg";
|
||||
lvs = {
|
||||
root = {
|
||||
size = "100%FREE";
|
||||
content = {
|
||||
type = "btrfs";
|
||||
extraArgs = ["-f"];
|
||||
|
||||
subvolumes = {
|
||||
"/root" = {
|
||||
mountpoint = "/";
|
||||
};
|
||||
|
||||
"/persist" = {
|
||||
mountOptions = ["subvol=persist" "noatime"];
|
||||
mountpoint = "/persist";
|
||||
};
|
||||
|
||||
"/nix" = {
|
||||
mountOptions = ["subvol=nix" "noatime"];
|
||||
mountpoint = "/nix";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
boot.initrd.postDeviceCommands = ''
|
||||
mkdir -p /btrfs_tmp
|
||||
mount /dev/root_vg/root /btrfs_tmp
|
||||
if [[ -e /btrfs_tmp/root ]]; then
|
||||
mkdir -p /btrfs_tmp/old_roots
|
||||
timestamp=$(date --date="@$(stat -c %Y /btrfs_tmp/root)" "+%Y-%m-%-d_%H:%M:%S")
|
||||
mv /btrfs_tmp/root "/btrfs_tmp/old_roots/$timestamp"
|
||||
fi
|
||||
|
||||
delete_subvolume_recursively() {
|
||||
IFS=$'\n'
|
||||
for i in $(btrfs subvolume list -o "$1" | cut -f 9- -d ' '); do
|
||||
delete_subvolume_recursively "/btrfs_tmp/$i"
|
||||
done
|
||||
btrfs subvolume delete "$1"
|
||||
}
|
||||
|
||||
for i in $(find /btrfs_tmp/old_roots/ -maxdepth 1 -mtime +30); do
|
||||
delete_subvolume_recursively "$i"
|
||||
done
|
||||
|
||||
btrfs subvolume create /btrfs_tmp/root
|
||||
umount /btrfs_tmp
|
||||
'';
|
||||
}
|
||||
|
|
@ -1,80 +0,0 @@
|
|||
{device ? throw "Set this to your disk device, e.g. /dev/sda", ...}: {
|
||||
disko.devices = {
|
||||
disk = {
|
||||
main = {
|
||||
type = "disk";
|
||||
device = device;
|
||||
content = {
|
||||
type = "gpt";
|
||||
partitions = {
|
||||
ESP = {
|
||||
label = "boot";
|
||||
name = "ESP";
|
||||
size = "512M";
|
||||
type = "EF00";
|
||||
content = {
|
||||
type = "filesystem";
|
||||
format = "vfat";
|
||||
mountpoint = "/boot";
|
||||
mountOptions = [
|
||||
"defaults"
|
||||
];
|
||||
};
|
||||
};
|
||||
luks = {
|
||||
size = "100%";
|
||||
label = "luks";
|
||||
content = {
|
||||
type = "luks";
|
||||
name = "cryptroot";
|
||||
extraOpenArgs = [
|
||||
"--allow-discards"
|
||||
"--perf-no_read_workqueue"
|
||||
"--perf-no_write_workqueue"
|
||||
];
|
||||
# https://0pointer.net/blog/unlocking-luks2-volumes-with-tpm2-fido2-pkcs11-security-hardware-on-systemd-248.html
|
||||
settings = {crypttabExtraOpts = ["fido2-device=auto" "token-timeout=10"];};
|
||||
content = {
|
||||
type = "filesystem";
|
||||
format = "ext4";
|
||||
mountpoint = "/persist";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
nodev = {
|
||||
"/" = {
|
||||
fsType = "tmpfs";
|
||||
mountOptions = ["defaults" "size=8G" "mode=755"];
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
fileSystems."/persist" = {
|
||||
depends = ["/"];
|
||||
neededForBoot = true;
|
||||
};
|
||||
fileSystems."/nix" = {
|
||||
device = "/persist/nix";
|
||||
options = ["bind"];
|
||||
depends = ["/persist"];
|
||||
neededForBoot = true;
|
||||
};
|
||||
fileSystems."/tmp" = {
|
||||
device = "/persist/tmp";
|
||||
options = ["bind"];
|
||||
depends = ["/persist"];
|
||||
neededForBoot = true;
|
||||
};
|
||||
swapDevices = [
|
||||
{
|
||||
device = "/persist/swapfile";
|
||||
size = 64 * 1024; # 64 GB
|
||||
}
|
||||
];
|
||||
|
||||
boot.resumeDevice = "/persist/swapfile";
|
||||
}
|
||||
|
|
@ -1,48 +0,0 @@
|
|||
{device ? throw "Set this to your disk device, e.g. /dev/sda", ...}: {
|
||||
disko.devices = {
|
||||
disk.main = {
|
||||
inherit device;
|
||||
type = "disk";
|
||||
content = {
|
||||
type = "gpt";
|
||||
partitions = {
|
||||
boot = {
|
||||
name = "boot";
|
||||
size = "1M";
|
||||
type = "EF02";
|
||||
};
|
||||
esp = {
|
||||
name = "ESP";
|
||||
size = "500M";
|
||||
type = "EF00";
|
||||
content = {
|
||||
type = "filesystem";
|
||||
format = "vfat";
|
||||
mountpoint = "/boot";
|
||||
};
|
||||
};
|
||||
root = {
|
||||
name = "root";
|
||||
size = "100%";
|
||||
content = {
|
||||
type = "filesystem";
|
||||
format = "ext4";
|
||||
mountpoint = "/persist";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
nodev = {
|
||||
"/" = {
|
||||
fsType = "tmpfs";
|
||||
};
|
||||
"/nix" = {
|
||||
device = "/persist/nix";
|
||||
};
|
||||
"/tmp" = {
|
||||
device = "/persist/tmp";
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
@ -28,8 +28,8 @@ in {
|
|||
"mem_sleep_default=deep"
|
||||
]
|
||||
#https://github.com/nix-community/disko/issues/651#issuecomment-2383741717
|
||||
++ optional (!config.boot.initrd.systemd.enable) "resume_offset=${builtins.toString cfg.swapFileOffset}";
|
||||
inherit (cfg) resumeDevice;
|
||||
++ optional (cfg.swapFileOffset != null) "resume_offset=${builtins.toString cfg.swapFileOffset}";
|
||||
resumeDevice = mkDefault cfg.resumeDevice;
|
||||
};
|
||||
services.logind = {
|
||||
lidSwitch = mkDefault "suspend-then-hibernate";
|
||||
|
|
|
|||
|
|
@ -31,25 +31,25 @@ in {
|
|||
description = "Watch for tablet mode changes";
|
||||
serviceConfig = {
|
||||
ExecStart = "${pkgs.writeShellScript "tablet-mode-eventd" ''
|
||||
in_tablet_mode=$(${pkgs.coreutils}/bin/cat "${cfg.path}" 2>/dev/null || $(echo 0 > "${cfg.path}" && echo 0))
|
||||
in_tablet_mode=$(${pkgs.coreutils}/bin/cat "${cfg.path}" 2>/dev/null || $(echo 0 > "${cfg.path}" && echo 0))
|
||||
|
||||
stdbuf -oL -eL ${lib.getExe pkgs.libinput} debug-events --device "${cfg.inputDevice}" | while read -r line; do
|
||||
if [[ "$line" =~ switch\ tablet-mode\ state\ ([01]) ]]; then
|
||||
d="''${BASH_REMATCH[1]}"
|
||||
if [ "$d" -ne "$in_tablet_mode" ]; then
|
||||
in_tablet_mode=$d
|
||||
if [ "$d" -eq 1 ]; then
|
||||
systemctl start tablet-on.target
|
||||
echo "Tablet mode ON"
|
||||
echo 1 > "${cfg.path}"
|
||||
else
|
||||
systemctl start tablet-off.target
|
||||
echo "Tablet mode OFF"
|
||||
echo 0 > "${cfg.path}"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
done
|
||||
stdbuf -oL -eL ${lib.getExe pkgs.libinput} debug-events --device "${cfg.inputDevice}" | while read -r line; do
|
||||
if [[ "$line" =~ switch\ tablet-mode\ state\ ([01]) ]]; then
|
||||
d="''${BASH_REMATCH[1]}"
|
||||
if [ "$d" -ne "$in_tablet_mode" ]; then
|
||||
in_tablet_mode=$d
|
||||
if [ "$d" -eq 1 ]; then
|
||||
systemctl start tablet-on.target
|
||||
echo "Tablet mode ON"
|
||||
echo 1 > "${cfg.path}"
|
||||
else
|
||||
systemctl start tablet-off.target
|
||||
echo "Tablet mode OFF"
|
||||
echo 0 > "${cfg.path}"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
done
|
||||
''}";
|
||||
Restart = "always";
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue