87 lines
2.2 KiB
Nix
Raw Normal View History

2024-09-19 23:57:25 +03:00
{ config, pkgs, lib, ... }:
2023-03-25 19:31:05 +03:00
let
zfs_arc_max = toString (6 * 1024 * 1024 * 1024);
in {
boot = {
2024-12-28 11:35:20 +03:00
zfs.package = pkgs.zfs_unstable;
kernelPackages = pkgs.linuxPackages_xanmod_latest;
2023-09-16 00:49:54 +03:00
2023-03-25 19:31:05 +03:00
initrd = {
2023-03-26 19:24:28 +03:00
supportedFilesystems = [ "zfs" ];
2023-03-25 19:31:05 +03:00
luks.devices = {
"cryptroot" = {
keyFile = "/keyfile0.bin";
allowDiscards = true;
2023-03-26 19:24:28 +03:00
bypassWorkqueues = true;
2023-03-25 19:31:05 +03:00
};
};
secrets = {
"keyfile0.bin" = "/etc/secrets/keyfile0.bin";
};
};
loader = {
2023-03-26 19:24:28 +03:00
grub = {
2023-03-25 19:31:05 +03:00
enable = true;
2023-03-27 15:50:40 +03:00
device = "nodev";
copyKernels = true;
2023-03-26 19:24:28 +03:00
efiSupport = true;
enableCryptodisk = true;
2023-03-27 15:50:40 +03:00
useOSProber = false;
2023-03-26 19:24:28 +03:00
zfsSupport = true;
2024-07-16 15:11:12 +03:00
gfxmodeEfi = "2560x1440";
# efiInstallAsRemovable = true;
2023-03-25 19:31:05 +03:00
};
2023-03-27 15:50:40 +03:00
systemd-boot.enable = lib.mkForce false;
2023-03-26 19:24:28 +03:00
efi.canTouchEfiVariables = true;
efi.efiSysMountPoint = "/efi";
2023-03-25 19:31:05 +03:00
generationsDir.copyKernels = true;
};
2023-03-27 15:50:40 +03:00
binfmt.emulatedSystems = [ "aarch64-linux" ];
2023-03-25 19:31:05 +03:00
kernelParams = [
"zfs.metaslab_lba_weighting_enabled=0"
"zfs.zfs_arc_max=${zfs_arc_max}"
2023-10-01 23:39:11 +03:00
"amd_pstate=active"
2023-11-11 03:11:02 +03:00
"retbleed=off" # big performance impact
2024-03-23 18:01:09 +03:00
"amdgpu.ignore_min_pcap=1"
2023-03-25 19:31:05 +03:00
];
2023-11-11 03:11:15 +03:00
kernel.sysctl = {
"kernel.split_lock_mitigate" = 0;
};
2023-05-13 01:01:57 +03:00
tmp.useTmpfs = true;
tmp.tmpfsSize = "32G";
2023-03-27 20:57:06 +03:00
supportedFilesystems = [ "ntfs" ];
2023-03-25 19:31:05 +03:00
};
2023-03-26 19:24:28 +03:00
persist = {
enable = true;
2023-04-08 17:57:02 +03:00
cache.clean.enable = true;
2023-03-26 19:24:28 +03:00
};
2023-04-08 17:57:02 +03:00
fileSystems."/" = lib.mkForce {
device = "none";
options = [ "defaults" "size=4G" "mode=755" ];
fsType = "tmpfs";
};
2023-03-26 19:24:28 +03:00
fileSystems."/home".neededForBoot = true;
fileSystems."/persist".neededForBoot = true;
2024-09-19 23:57:25 +03:00
boot.initrd.systemd.enable = true;
boot.initrd.systemd.services.rollback = {
description = "Rollback zfs to a pristine state on boot";
wantedBy = [ "initrd.target" ];
after = [ "zfs-import-rpool.service" ];
before = [ "sysroot.mount" ];
path = [ config.boot.zfs.package ];
unitConfig.DefaultDependencies = "no";
serviceConfig.Type = "oneshot";
script = ''
zfs rollback -r rpool/nixos/root@empty && echo " >>> rollback root <<<"
zfs rollback -r rpool/user/home@empty && echo " >>> rollback home <<<"
'';
};
2023-03-25 19:31:05 +03:00
}