{ config, lib, pkgs, ... }:
let
  pkgsVersion = pkgs; #.unstable;
in 
{
  services = {
    # Enable Flatpak
    flatpak.enable = lib.mkDefault false;

    # enable auto discovery of printers
    avahi = {
      enable = lib.mkDefault true;
      nssmdns4 = lib.mkDefault true;
      openFirewall = lib.mkDefault true;
    };

    restic.backups = {
      jallen-nas = {
        initialize = true;
        createWrapper = true;
        inhibitsSleep = true;
        environmentFile = config.sops.templates."restic.env".path;
        passwordFile = config.sops.secrets."desktop/restic/password".path;
        repositoryFile = config.sops.secrets."desktop/restic/repo".path;
        paths = [
          "/home/matt"
        ];
        exclude = [
          "/home/matt/Steam"
          "/home/matt/Heroic"
          "/home/matt/1TB"
          "/home/matt/Downloads"
          "/home/matt/Nextcloud"
          "/home/matt/.cache"
          "/home/matt/.local/share/Steam"
          "/home/matt/.var/app/com.valvesoftware.Steam"
          "/home/matt/.tmp"
          "/home/matt/.thumbnails"
          "/home/matt/.compose-cache"
        ];
      };
      proton-drive = {
        initialize = true;
        createWrapper = true;
        inhibitsSleep = true;
        passwordFile = config.sops.secrets."desktop/restic/password".path;
        rcloneConfigFile = "/home/matt/.config/rclone/rclone.conf";
        repository = "rclone:proton-drive:backup-nix";
        paths = [
          "/home/matt"
        ];
        exclude = [
          "/home/matt/Steam"
          "/home/matt/Heroic"
          "/home/matt/1TB"
          "/home/matt/Downloads"
          "/home/matt/Nextcloud"
          "/home/matt/.cache"
          "/home/matt/.local/share/Steam"
          "/home/matt/.var/app/com.valvesoftware.Steam"
          "/home/matt/.tmp"
          "/home/matt/.thumbnails"
          "/home/matt/.compose-cache"
        ];
      };
    };

    btrfs = {
      autoScrub.enable = lib.mkDefault true;
      autoScrub.fileSystems = lib.mkDefault [
        "/nix"
        "/root"
        "/etc"
        "/var/log"
        "/home"
      ];
    };

    ratbagd.enable = lib.mkDefault true;
  };

  systemd = {
    user.services = {
      rclone-home-proton = {
        enable = lib.mkDefault false;
        path = with pkgsVersion; [
          bash
          pkgs.rclone
        ];
        script = ''
          rclone sync /home/matt proton-drive:backup-nix --exclude '/home/matt/Games/**' --exclude '/home/matt/1TB/**' --exclude '/home/matt/Downloads/**'
        '';
      };

      rsync-home = {
        enable = lib.mkDefault false;
        path = with pkgsVersion; [
          bash
          rsync
          openssh
        ];
        script = ''
          rsync -rtpogvPlHzs --ignore-existing --exclude={'/home/matt/Games', '/home/matt/1TB', '/home/matt/Downloads/*', '/home/matt/.cache'} -e ssh /home/matt admin@10.0.1.3:/media/nas/main/backup/desktop-nix/home 
        '';
      };
    };
  };
}
