diff options
Diffstat (limited to '')
| -rw-r--r-- | hosts/by-name/tiamat/hardware.nix | 4 | ||||
| -rw-r--r-- | hosts/by-name/tiamat/legacy-disk-module/fstrim.nix | 51 | ||||
| -rw-r--r-- | hosts/by-name/tiamat/legacy-disk-module/hibernate.nix | 55 | ||||
| -rw-r--r-- | hosts/by-name/tiamat/legacy-disk-module/module.nix | 159 |
4 files changed, 268 insertions, 1 deletions
diff --git a/hosts/by-name/tiamat/hardware.nix b/hosts/by-name/tiamat/hardware.nix index 2b18a662..f2a5cec6 100644 --- a/hosts/by-name/tiamat/hardware.nix +++ b/hosts/by-name/tiamat/hardware.nix @@ -10,6 +10,7 @@ {modulesPath, ...}: { imports = [ (modulesPath + "/installer/scan/not-detected.nix") # TODO: is this necessary? + ./legacy-disk-module/module.nix ]; soispha = { @@ -20,7 +21,8 @@ enableFlashing = true; }; }; - + }; + legacy.soispha = { disks = { enable = true; disk = "/dev/disk/by-id/nvme-CT1000P5SSD8_21032C857568"; diff --git a/hosts/by-name/tiamat/legacy-disk-module/fstrim.nix b/hosts/by-name/tiamat/legacy-disk-module/fstrim.nix new file mode 100644 index 00000000..0fbb6c83 --- /dev/null +++ b/hosts/by-name/tiamat/legacy-disk-module/fstrim.nix @@ -0,0 +1,51 @@ +# nixos-config - My current NixOS configuration +# +# Copyright (C) 2025 Benedikt Peetz <benedikt.peetz@b-peetz.de> +# SPDX-License-Identifier: GPL-3.0-or-later +# +# This file is part of my nixos-config. +# +# You should have received a copy of the License along with this program. +# If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>. +{ + pkgs, + lib, + cfg, +}: { + timers.fstrim = lib.mkIf cfg.ssd { + wantedBy = ["timers.target"]; + wants = ["fstrim.service"]; + unitConfig = { + Description = "Discard unused blocks once a week"; + Documentation = "man:fstrim"; + ConditionVirtualization = "!container"; + ConditionPathExists = "!/etc/initrd-release"; + }; + timerConfig = { + OnCalendar = "weekly"; + AccuracySec = "1h"; + Persistent = "true"; + RandomizedDelaySec = "6000"; + }; + }; + services.fstrim = lib.mkIf cfg.ssd { + wantedBy = lib.mkForce []; + unitConfig = { + Description = "Discard unused blocks on filesystems from /etc/fstab"; + Documentation = "man:fstrim(8)"; + ConditionVirtualization = "!container"; + }; + serviceConfig = { + Type = "oneshot"; + ExecStart = "${pkgs.util-linux}/bin/fstrim --listed-in /etc/fstab:/proc/self/mountinfo --verbose --quiet-unsupported"; + PrivateDevices = "no"; + PrivateNetwork = "yes"; + PrivateUsers = "no"; + ProtectKernelTunables = "yes"; + ProtectKernelModules = "yes"; + ProtectControlGroups = "yes"; + MemoryDenyWriteExecute = "yes"; + SystemCallFilter = "@default @file-system @basic-io @system-service"; + }; + }; +} diff --git a/hosts/by-name/tiamat/legacy-disk-module/hibernate.nix b/hosts/by-name/tiamat/legacy-disk-module/hibernate.nix new file mode 100644 index 00000000..d3f8fe8b --- /dev/null +++ b/hosts/by-name/tiamat/legacy-disk-module/hibernate.nix @@ -0,0 +1,55 @@ +# nixos-config - My current NixOS configuration +# +# Copyright (C) 2025 Benedikt Peetz <benedikt.peetz@b-peetz.de> +# SPDX-License-Identifier: GPL-3.0-or-later +# +# This file is part of my nixos-config. +# +# You should have received a copy of the License along with this program. +# If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>. +{pkgs}: { + services = { + hibernate-preparation = { + wantedBy = ["systemd-hibernate.service"]; + unitConfig = { + Description = "Enable swap file and disable zram before hibernate"; + Before = "systemd-hibernate.service"; + }; + serviceConfig = { + Type = "oneshot"; + User = "root"; + ExecStart = "${pkgs.bash}/bin/bash -c \"${pkgs.util-linux}/bin/swapon /swap/swapfile && ${pkgs.util-linux}/bin/swapoff /dev/zram0\""; + }; + }; + + hibernate-resume = { + wantedBy = ["systemd-hibernate.service"]; + unitConfig = { + Description = "Disable swap after resuming from hibernation"; + After = "hibernate.target"; + }; + serviceConfig = { + Type = "oneshot"; + User = "root"; + ExecStart = "${pkgs.util-linux}/bin/swapoff /swap/swapfile"; + }; + }; + # swapoff-start = { + # wantedBy = ["multi-user.target"]; + # unitConfig = { + # Description = "Disable hardware swap after booting"; + # }; + # serviceConfig = { + # Type = "oneshot"; + # User = "root"; + # ExecStart = "${pkgs.util-linux}/bin/swapoff /swap/swapfile"; + # }; + # }; + systemd-hibernate.serviceConfig.Environment = "SYSTEMD_BYPASS_HIBERNATION_MEMORY_CHECK=1"; + systemd-logind.serviceConfig.Environment = "SYSTEMD_BYPASS_HIBERNATION_MEMORY_CHECK=1"; + }; + + sleep.settings.Sleep = { + HibernateDelaySec = "10m"; + }; +} diff --git a/hosts/by-name/tiamat/legacy-disk-module/module.nix b/hosts/by-name/tiamat/legacy-disk-module/module.nix new file mode 100644 index 00000000..955d2026 --- /dev/null +++ b/hosts/by-name/tiamat/legacy-disk-module/module.nix @@ -0,0 +1,159 @@ +# nixos-config - My current NixOS configuration +# +# Copyright (C) 2025 Benedikt Peetz <benedikt.peetz@b-peetz.de> +# SPDX-License-Identifier: GPL-3.0-or-later +# +# This file is part of my nixos-config. +# +# You should have received a copy of the License along with this program. +# If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>. +{ + config, + lib, + pkgs, + modules, + ... +}: let + # FIXME: The iso redeploy requires a bigger efi partition <2024-05-12> + cfg = config.legacy.soispha.disks; + defaultMountOptions = [ + "compress=zstd:3" # This saves disk space, at a performance cost + "noatime" # should have some performance upsides, and I don't use it anyways + "lazytime" # make time changes in memory + ]; +in { + options.legacy.soispha.disks = { + enable = lib.mkEnableOption "disk setup with disko"; + + disk = lib.mkOption { + type = lib.types.path; + example = lib.literalExpression "/dev/disk/by-uuid/0442cb6d-f13a-4635-b487-fa76189774c5"; + description = "The disk used for installing the OS."; + }; + + ssd = lib.mkEnableOption "ssd specific improvements, like trim"; + + swap = { + uuid = lib.mkOption { + type = lib.types.str; + example = lib.literalExpression "d1d20ae7-3d8a-44da-86da-677dbbb10c89"; + description = "The uuid of the swapfile"; + }; + resumeOffset = lib.mkOption { + type = lib.types.str; + example = lib.literalExpression "134324224"; + description = "The resume offset of the swapfile"; + }; + }; + }; + + imports = [ + modules.disko.nixosModules.default + ]; + + config = lib.mkIf cfg.enable { + systemd = lib.recursiveUpdate (import ./hibernate.nix {inherit pkgs;}) (import ./fstrim.nix {inherit pkgs lib cfg;}); + + disko.devices = { + disk = { + main = { + device = cfg.disk; + content = { + type = "gpt"; + partitions = { + root = { + size = "100%"; + name = "root"; + content = { + type = "luks"; + name = "nixos"; + extraOpenArgs = ["--allow-discards"]; + content = { + type = "btrfs"; + extraArgs = ["-f" "--label nixos"]; # Override existing partitions + subvolumes = { + "nix" = { + mountpoint = "/nix"; + mountOptions = defaultMountOptions; + }; + "persistent-storage" = { + mountpoint = "/srv"; + mountOptions = defaultMountOptions; + }; + "persistent-storage@snapshots" = { + mountpoint = "/srv/.snapshots"; + mountOptions = defaultMountOptions; + }; + "swap" = { + mountpoint = "/swap"; + mountOptions = [ + "noatime" # should have some performance upsides, and I don't use it anyways + "lazytime" # make time changes in memory + ]; + }; + }; + }; + }; + }; + boot = { + type = "EF00"; + size = "512M"; + name = "boot"; + content = { + type = "filesystem"; + format = "vfat"; + mountpoint = "/boot"; + }; + }; + }; + }; + }; + }; + nodev = { + "/" = { + fsType = "tmpfs"; + mountOptions = ["defaults" "size=25%" "mode=0755"]; + }; + "/tmp" = { + fsType = "tmpfs"; + mountOptions = ["defaults" "size=50%" "mode=0755"]; + }; + "/nix/var/nix/b" = { + fsType = "tmpfs"; + mountOptions = [ + "defaults" + "noswap" # Otherwise, we might run into io-based slowdowns + "size=80%" + "mode=0755" + ]; + }; + }; + }; + fileSystems = { + "/srv" = { + neededForBoot = true; + }; + "/swap" = { + neededForBoot = true; + }; + }; + swapDevices = [ + #{ + # device = "/swap/swapfile"; + # priority = 1; # lower than zramSwap, just in case + # # size = 2048; # TODO: can nixos create a btrfs swapfile correctly? + #} + ]; + zramSwap = { + enable = true; + priority = 10; # needs to be higher than hardware-swap + }; + boot = { + kernelParams = [ + "resume_offset=${cfg.swap.resumeOffset}" + "zswap.enabled=0" # zswap and zram are not really compatible + ]; + resumeDevice = "/dev/disk/by-uuid/${cfg.swap.uuid}"; + }; + }; +} |
