# nixos-config - My current NixOS configuration # # Copyright (C) 2025 Benedikt Peetz # 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 . { config, lib, pkgs, modules, ... }: let cfg = config.soispha.disks; defaultMountOptions = [ "compress-force=zstd:15" # 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.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 = { ram_size = lib.mkOption { type = lib.types.str; example = lib.literalExpression "16G"; description = "The size of the ram (translates to the swapfile size)"; }; }; }; 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;}); services.btrfs.autoScrub = { enable = true; fileSystems = ["/srv" "/nix"]; interval = "monthly"; }; disko.devices = { disk = { main = { device = cfg.disk; content = { type = "gpt"; partitions = { ESP = { # 2GiB plus 512MiB for tails ISO and normal boot stuff size = "2600M"; type = "EF00"; content = { type = "filesystem"; format = "vfat"; mountpoint = "/boot"; mountOptions = ["umask=0077"]; }; }; nix = { size = "30G"; content = { type = "luks"; name = "nixos-store"; extraOpenArgs = ["--allow-discards"]; content = { type = "btrfs"; extraArgs = ["-f" "--label nixos-store"]; # Override existing partitions mountpoint = "/nix"; mountOptions = defaultMountOptions; }; }; }; root = { size = "100%"; content = { type = "luks"; name = "nixos-root"; extraOpenArgs = ["--allow-discards"]; content = { type = "btrfs"; extraArgs = ["-f" "--label nixos-root"]; # Override existing partitions subvolumes = { "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 ]; swap = { swapfile = { priority = -1; # lower than zramSwap, just in case size = cfg.swap.ram_size; }; }; }; }; }; }; }; }; }; }; }; 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 = { "/nix" = { neededForBoot = true; }; "/srv" = { neededForBoot = true; }; "/swap" = { neededForBoot = true; }; }; zramSwap = { enable = true; priority = 10; # needs to be higher than hardware-swap }; boot = { kernelParams = [ "zswap.enabled=0" # zswap and zram are not really compatible ]; }; }; }