nix-config/devices/tunyon/default.nix
2024-07-21 01:47:39 +02:00

101 lines
2.6 KiB
Nix

{ lib, config, pkgs, ... }: {
imports = [
./options.nix
];
nixpkgs = {
hostPlatform = "x86_64-linux";
};
networking = {
hostName = "tunyon";
};
boot = {
initrd = {
availableKernelModules = [ "nvme" "xhci_pci" "thunderbolt" ];
luks.devices.root.device = "/dev/disk/by-uuid/${config.disks.crypt}";
postDeviceCommands = lib.mkAfter ''
mkdir /btrfs_tmp
mount /dev/disk/by-uuid/${config.disks.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
'';
};
kernelModules = [ "kvm-amd" ];
kernelPackages = pkgs.linuxPackages_zen;
loader = {
systemd-boot = {
enable = true;
};
efi.canTouchEfiVariables = true;
};
};
fileSystems = {
"/boot" = {
device = "/dev/disk/by-uuid/${config.disks.boot}";
fsType = "vfat";
};
"/" = {
device = "/dev/disk/by-uuid/${config.disks.root}";
fsType = "btrfs";
options = [ "subvol=root" "compress=zstd" "noatime" ];
};
"/nix" = {
device = "/dev/disk/by-uuid/${config.disks.root}";
fsType = "btrfs";
options = [ "subvol=nix" "compress=zstd" "noatime" ];
neededForBoot = true;
};
"/persist" = {
device = "/dev/disk/by-uuid/${config.disks.root}";
fsType = "btrfs";
options = [ "subvol=persist" "compress=zstd" "noatime" ];
neededForBoot = true;
};
"/swap" = {
device = "/dev/disk/by-uuid/${config.disks.root}";
fsType = "btrfs";
options = [ "subvol=swap" "noatime" ];
};
};
swapDevices = [ { device = "/swap/swapfile"; } ];
services = {
upower.enable = true;
fwupd.enable = true;
power-profiles-daemon.enable = true;
};
hardware = {
enableRedistributableFirmware = true;
enableAllFirmware = true;
cpu.amd.updateMicrocode = true;
graphics = {
enable = true;
enable32Bit = true;
};
};
}