#
# Hardware settings for Teclast F5 10" Laptop
# NixOS @ sda2
#
# flake.nix
#  └─ ./hosts
#      └─ ./laptop
#          └─ hardware-configuration.nix *
#
# Do not modify this file!  It was generated by ‘nixos-generate-config’
# and may be overwritten by future invocations.  Please make changes
# to /etc/nixos/configuration.nix instead.
{ config, lib, pkgs, modulesPath, ... }:

{
  imports =
    [ (modulesPath + "/installer/scan/not-detected.nix")] ++
      [( import ../../modules/hardware/backup.nix )];

  boot.initrd.availableKernelModules = [ "xhci_pci" "ahci" "nvme" "usb_storage" "usbhid" "sd_mod" ];
  boot.initrd.kernelModules = [ "vfio_pci" "vfio" "vfio_iommu_type1" ];
  boot.kernelModules = [ "kvm-intel" ];
  boot.extraModulePackages = [ ];
  boot.tmp.useTmpfs = false;
  boot.tmp.cleanOnBoot = true;
  zramSwap.enable = true;

  services.btrfs.autoScrub = {
    enable = true;
    interval = "monthly";
    fileSystems = [
      "/"
    ];
  };

  services.btrbk = {
      instances = {
          hf = {
              onCalendar = "hourly";
              settings = {
                  incremental = "yes";
                  snapshot_create = "ondemand";
                  snapshot_dir = "@snapshots";
                  timestamp_format = "long";

                  snapshot_preserve = "2m 2w 5d 5h";
                  snapshot_preserve_min = "latest";
                
                  volume =  {
                      "/mnt/snapshots/root" = {
                          snapshot_create = "always";
                          subvolume = {
                              "@home" = {};
                          };
                      };
                  };
              };
          };
      };
  };

  fileSystems."/" =
    { device = "/dev/disk/by-id/nvme-ADATA_SX8200PNP_2J3320119186-part2";
      fsType = "btrfs";
      options = [ "compress=zstd,space_cache=v2,ssd,noatime,subvol=@,discard=async" ];
    };

  fileSystems."/home" =
    { device = "/dev/disk/by-id/nvme-ADATA_SX8200PNP_2J3320119186-part2";
      fsType = "btrfs";
      options = [ "compress=zstd,space_cache=v2,ssd,noatime,subvol=@home,discard=async" ];
    };

  fileSystems."/srv" =
    { device = "/dev/disk/by-id/nvme-ADATA_SX8200PNP_2J3320119186-part2";
      fsType = "btrfs";
      options = [ "compress=zstd,space_cache=v2,ssd,noatime,subvol=@srv,discard=async" ];
    };

  fileSystems."/nix" =
    { device = "/dev/disk/by-id/nvme-ADATA_SX8200PNP_2J3320119186-part2";
      fsType = "btrfs";
      options = [ "compress=zstd,space_cache=v2,ssd,noatime,subvol=@nix,discard=async" ];
    };

  fileSystems."/swap" =
    { device = "/dev/disk/by-id/nvme-ADATA_SX8200PNP_2J3320119186-part2";
      fsType = "btrfs";
      options = [ "compress=zstd,space_cache=v2,ssd,noatime,subvol=@swap,discard=async" ];
    };

  fileSystems."/mnt/snapshots/root" =
    { device = "/dev/disk/by-id/nvme-ADATA_SX8200PNP_2J3320119186-part2";
      fsType = "btrfs";
      options = [ "compress=zstd,space_cache=v2,ssd,noatime,subvolid=5,discard=async" ];
    };

  fileSystems."/boot" =
    { device = "/dev/disk/by-id/nvme-ADATA_SX8200PNP_2J3320119186-part1";
      fsType = "vfat";
    };


  swapDevices = [ { device = "/swap/swapfile"; } ];
  
  networking = {
    useDHCP = false;                        # Deprecated
    hostName = "fuji";
    networkmanager = {
      enable = false;
    };
    firewall = {
      enable = true;
      #allowedUDPPorts = [ 24727 ];
      #allowedTCPPorts = [ 24727 ];
    };
  };

  systemd.network = {
      enable = true;
      networks = {
          "10-lan" = {
              matchConfig.Name = "eno1";
              ntp = [ "192.168.2.1" ];
              networkConfig = {
                DHCP = "yes";
                IPv6AcceptRA = true;
              };
          };
      };
  };

  hardware.cpu.intel.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware;
  #powerManagement.powertop.enable = true;
  powerManagement = {
    scsiLinkPolicy = "med_power_with_dipm";
  };
}