# 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,
  ...
}:
let
  defragmentServiceBin = pkgs.writeScriptBin "defragment" ''
    # Defragment directories
    btrfs filesystem defragment -r -czstd /mnt/data/lmstudio_models
    btrfs filesystem defragment -r -czstd /mnt/data/NextCloud
    btrfs filesystem defragment -r -czstd /mnt/data/repos
    btrfs filesystem defragment -r -czstd /mnt/data/Steam
    btrfs filesystem defragment -r -czstd /mnt/data/VMs
  '';
in
{
  imports = [
    (modulesPath + "/installer/scan/not-detected.nix")
  ];

  boot.initrd.availableKernelModules = [
    "nvme"
    "xhci_pci"
    "ahci"
    "usbhid"
    "sd_mod"
  ];
  boot.initrd.kernelModules = [ ];
  boot.kernelModules = [ "kvm-amd" ];
  boot.extraModulePackages = [ ];

  fileSystems."/" = {
    device = "/dev/disk/by-uuid/1987b9a1-1444-404c-9775-b9cbedda0204";
    fsType = "ext4";
  };

  fileSystems."/boot" = {
    device = "/dev/disk/by-uuid/1668-AA41";
    fsType = "vfat";
    options = [
      "fmask=0077"
      "dmask=0077"
    ];
  };

  fileSystems."/mnt/data" = {
    device = "/dev/disk/by-uuid/dc60967d-4625-4840-9e56-9a1d9049dc02";
    fsType = "btrfs";
    options = [ "compress=zstd" ];
  };

  fileSystems."/mnt/NextCloud" = {
    device = "/dev/disk/by-uuid/dc60967d-4625-4840-9e56-9a1d9049dc02";
    fsType = "btrfs";
    options = [
      "subvol=NextCloud"
      "compress=zstd"
    ];
  };

  fileSystems."/mnt/repos" = {
    device = "/dev/disk/by-uuid/dc60967d-4625-4840-9e56-9a1d9049dc02";
    fsType = "btrfs";
    options = [
      "subvol=repos"
      "compress=zstd"
    ];
  };

  fileSystems."/mnt/Steam" = {
    device = "/dev/disk/by-uuid/dc60967d-4625-4840-9e56-9a1d9049dc02";
    fsType = "btrfs";
    options = [
      "subvol=Steam"
      "compress=zstd"
    ];
  };

  fileSystems."/mnt/VMs" = {
    device = "/dev/disk/by-uuid/dc60967d-4625-4840-9e56-9a1d9049dc02";
    fsType = "btrfs";
    options = [
      "subvol=VMs"
      "compress=zstd"
    ];
  };

  fileSystems."/home/marvin/.lmstudio/models" = {
    device = "/dev/disk/by-uuid/dc60967d-4625-4840-9e56-9a1d9049dc02";
    fsType = "btrfs";
    options = [
      "subvol=lmstudio_models"
      "compress=zstd"
    ];
  };

  # store isn't available across subvolumes so removing
  # fileSystems."/mnt/pnpm" = {
  #   device = "/dev/disk/by-uuid/dc60967d-4625-4840-9e56-9a1d9049dc02";
  #   fsType = "btrfs";
  #   options = [
  #     "subvol=pnpm"
  #     "compress=zstd"
  #   ];
  # };

  services.snapper.configs = {
    # lmstudio_models = {
    #   SUBVOLUME = "/home/marvin/.lmstudio/models";
    #   ALLOW_USERS = [ "marvin" ];
    #   TIMELINE_CREATE = true;
    #   TIMELINE_CLEANUP = true;
    #   TIMELINE_LIMIT_DAILY = 3;
    #   TIMELINE_LIMIT_HOURLY = 4;
    #   TIMELINE_LIMIT_MONTHLY = 2;
    #   TIMELINE_LIMIT_QUARTERLY = 1;
    #   TIMELINE_LIMIT_WEEKLY = 1;
    #   TIMELINE_LIMIT_YEARLY = 1;
    #   SPACE_LIMIT = "0.5";
    #   SYNC_ACL = "yes";
    # };
    NextCloud = {
      SUBVOLUME = "/mnt/NextCloud";
      ALLOW_USERS = [ "marvin" ];
      TIMELINE_CREATE = true;
      TIMELINE_CLEANUP = true;
      TIMELINE_LIMIT_DAILY = 14;
      TIMELINE_LIMIT_HOURLY = 24;
      TIMELINE_LIMIT_MONTHLY = 12;
      TIMELINE_LIMIT_QUARTERLY = 1;
      TIMELINE_LIMIT_WEEKLY = 5;
      TIMELINE_LIMIT_YEARLY = 2;
      SPACE_LIMIT = "0.5";
      SYNC_ACL = "yes";
    };
    repos = {
      SUBVOLUME = "/mnt/repos";
      ALLOW_USERS = [ "marvin" ];
      TIMELINE_CREATE = true;
      TIMELINE_CLEANUP = true;
      TIMELINE_LIMIT_DAILY = 14;
      TIMELINE_LIMIT_HOURLY = 24;
      TIMELINE_LIMIT_MONTHLY = 12;
      TIMELINE_LIMIT_QUARTERLY = 1;
      TIMELINE_LIMIT_WEEKLY = 5;
      TIMELINE_LIMIT_YEARLY = 2;
      SPACE_LIMIT = "0.5";
      SYNC_ACL = "yes";
    };
    # Steam = {
    #   SUBVOLUME = "/mnt/Steam";
    #   ALLOW_USERS = [ "marvin" ];
    #   TIMELINE_CREATE = true;
    #   TIMELINE_CLEANUP = true;
    #   SPACE_LIMIT = "0.5";
    #   SYNC_ACL = "yes";
    # };
    # VMs = {
    #   SUBVOLUME = "/mnt/VMs";
    #   ALLOW_USERS = [ "marvin" ];
    #   TIMELINE_CREATE = true;
    #   TIMELINE_CLEANUP = true;
    #   TIMELINE_LIMIT_DAILY = 4;
    #   TIMELINE_LIMIT_HOURLY = 4;
    #   TIMELINE_LIMIT_MONTHLY = 2;
    #   TIMELINE_LIMIT_QUARTERLY = 1;
    #   TIMELINE_LIMIT_WEEKLY = 1;
    #   TIMELINE_LIMIT_YEARLY = 1;
    #   SPACE_LIMIT = "0.5";
    #   SYNC_ACL = "yes";
    # };
  };

  systemd = {
    timers = {
      "defragment" = {
        enable = true;
        name = "defragment.timer";
        timerConfig = {
          OnCalendar = "*-*-01 00:00:00";
          Persistent = "true";
          Unit = "defragment.service";
        };
      };
    };
    services = {
      "defragment" = {
        script = "${defragmentServiceBin}/bin/defragment";
        name = "defragment.service";
        path = [ pkgs.btrfs-progs ];
        restartIfChanged = false;
      };
    };
  };

  # services.beesd.filesystems.data.hashTableSizeMB = lib.mkForce 512;

  swapDevices = [
    { device = "/dev/disk/by-uuid/c7459b6e-e621-4041-a12c-52a8209a0a7a"; }
  ];

  # Enables DHCP on each ethernet and wireless interface. In case of scripted networking
  # (the default) this is the recommended approach. When using systemd-networkd it's
  # still possible to use this option, but it's recommended to use it in conjunction
  # with explicit per-interface declarations with `networking.interfaces.<interface>.useDHCP`.
  networking.useDHCP = lib.mkDefault true;
  # networking.interfaces.enp40s0.useDHCP = lib.mkDefault true;
  # networking.interfaces.enp42s0.useDHCP = lib.mkDefault true;
  # networking.interfaces.wlp39s0.useDHCP = lib.mkDefault true;

  nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux";
  hardware.cpu.amd.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware;
}