diff --git a/disko/ext4-swap.nix b/disko/ext4-swap.nix deleted file mode 100644 index f5ae368..0000000 --- a/disko/ext4-swap.nix +++ /dev/null @@ -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" - ]; - }; - }; - }; - }; - }; - }; -} diff --git a/disko/ext4.nix b/disko/ext4.nix deleted file mode 100644 index 9e41ee1..0000000 --- a/disko/ext4.nix +++ /dev/null @@ -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; - }; - }; - }; - }; - }; - }; - }; -} diff --git a/disko/impermanence-btrfs-luks.nix b/disko/impermanence-btrfs-luks.nix deleted file mode 100644 index d688346..0000000 --- a/disko/impermanence-btrfs-luks.nix +++ /dev/null @@ -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; -} diff --git a/disko/impermanence-btrfs.nix b/disko/impermanence-btrfs.nix deleted file mode 100644 index a4a6883..0000000 --- a/disko/impermanence-btrfs.nix +++ /dev/null @@ -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 - ''; -} diff --git a/disko/impermanence-tmpfs-luks.nix b/disko/impermanence-tmpfs-luks.nix deleted file mode 100644 index a411f8c..0000000 --- a/disko/impermanence-tmpfs-luks.nix +++ /dev/null @@ -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"; -} diff --git a/disko/impermanence-tmpfs.nix b/disko/impermanence-tmpfs.nix deleted file mode 100644 index ff11f03..0000000 --- a/disko/impermanence-tmpfs.nix +++ /dev/null @@ -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"; - }; - }; - }; -} diff --git a/modules/nixos/hardware/hibernation/default.nix b/modules/nixos/hardware/hibernation/default.nix index 1fc246d..e73afde 100644 --- a/modules/nixos/hardware/hibernation/default.nix +++ b/modules/nixos/hardware/hibernation/default.nix @@ -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"; diff --git a/modules/nixos/hardware/tablet/default.nix b/modules/nixos/hardware/tablet/default.nix index f2daa9c..ee9114e 100644 --- a/modules/nixos/hardware/tablet/default.nix +++ b/modules/nixos/hardware/tablet/default.nix @@ -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"; };