{ self, pkgs, config, inputs, ... }:

{
  imports = [
    ./sketchybar
    # ./yabai # Now using aerospace
    # ./casks
    # ../../modules/darwin/home-manager.nix
    # ../../modules/shared
    # ../../modules/shared/cachix
  ];

  environment.systemPackages = [ 
    pkgs.go
    pkgs.python3
    pkgs.cargo
    pkgs.k9s
    pkgs.kubernetes-helm
    pkgs.shellcheck
  ];

  age.identityPaths = [ "/Users/anishlakhwara/.ssh/id_ed25519" ];
  age.secrets.work-wg.file = "${self}/secrets/work-wg.age";
  age.secrets.work-wg.owner = "anishlakhwara";
  age.secrets.github-token.file = "${self}/secrets/github-token.age";
  age.secrets.github-token.owner = "anishlakhwara";
  age.secrets.anthropicToken.file = "${self}/secrets/anthropicToken.age";
  age.secrets.anthropicToken.owner = "anishlakhwara";
  networking.wg-quick.interfaces = {
    wg0 = {
      address = [ "10.0.69.7/24" ];
      listenPort = 60990; # to match firewall allowedUDPPorts (without this wg uses random port numbers)
      privateKeyFile = config.age.secrets.work-wg.path;
      dns = [ "10.0.69.4" ];
      postDown = ''
        sudo /usr/sbin/networksetup -setdnsservers Wi-Fi "Empty"
      '';
      peers = [
        # For a client configuration, one peer entry for the server will suffice.
        {
          publicKey = "c1J4p63rD3IlszugMZiki7UBV3YmDdqa3DU4UejXzAI=";
          allowedIPs = [ "10.0.69.0/24" ];
          # Set this to the server IP and port.
          endpoint = "sealight.xyz:60990"; # ToDo: route to endpoint not automatically configured https://wiki.archlinux.org/index.php/WireGuard#Loop_routing https://discourse.nixos.org/t/solved-minimal-firewall-setup-for-wireguard-client/7577
          persistentKeepalive = 25;
        }
      ];
    };
  };

  # Auto upgrade nix package and the daemon service.
  # services.nix-daemon.enable = true; # removed in newer nix-darwin
  nixpkgs.hostPlatform = "aarch64-darwin";
  programs.zsh.enable = true;

  # Setup user, packages, programs
  nix = {
    # package = pkgs.nixUnstable;
    settings.trusted-users = [ "@admin" "anishlakhwara" ];

    gc = {
      # user = "root"; # removed in newer nix-darwin
      automatic = true;
      interval = { Weekday = 0; Hour = 2; Minute = 0; };
      options = "--delete-older-than 30d";
    };

    # Turn this on to make command line easier
    extraOptions = ''
      experimental-features = nix-command flakes
    '';
  };

  # Turn off NIX_PATH warnings now that we're using flakes
  system.checks.verifyNixPath = false;

  # Load configuration that is shared across systems
  # environment.systemPackages = with pkgs; [
  # 
  # ] ++ (import ../../modules/shared/packages.nix { inherit pkgs; });

  # Enable fonts dir
  # fonts.fontDir.enable = true;
  fonts.packages = with pkgs; [
    fira-code
    fira-code-symbols
    hermit
    #hack
    siji
    font-awesome
    proggyfonts
    nerd-fonts.fira-code
    nerd-fonts.droid-sans-mono
    nerd-fonts.iosevka
  ];

  system = {
    stateVersion = 4;
    primaryUser = "anishlakhwara";  # required for newer nix-darwin

    keyboard = {
      enableKeyMapping = true;
    };

    defaults = {
      LaunchServices = {
        LSQuarantine = false;
      };

      NSGlobalDomain = {
        AppleShowAllExtensions = true;
        ApplePressAndHoldEnabled = false;

        # 120, 90, 60, 30, 12, 6, 2
        KeyRepeat = 2;

        # 120, 94, 68, 35, 25, 15
        InitialKeyRepeat = 15;

        "com.apple.mouse.tapBehavior" = 1;
        "com.apple.sound.beep.volume" = 0.0;
        "com.apple.sound.beep.feedback" = 0;
      };

      loginwindow = {
        # disable guest account
        GuestEnabled = false;
        # show name instead of username
        SHOWFULLNAME = false;
      };

      dock = {
        autohide = true;
        autohide-delay = 0.0;
        autohide-time-modifier = 1.0;
        static-only = false;
        showhidden = false;
        show-recents = false;
        launchanim = true;
        mouse-over-hilite-stack = true;
        orientation = "bottom";
        tilesize = 48;
        mru-spaces = false;
      };

      finder = {
        _FXShowPosixPathInTitle = false;
      };

      trackpad = {
        Clicking = false;
        TrackpadThreeFingerDrag = true;
      };
    };

    # keyboard = {
    #   enableKeyMapping = true;
    #   remapCapsLockToControl = true;
    # };
  };
}
