{ config, pkgs, ... }:

{
  imports =
    [ # Include the results of the hardware scan.
      ./hardware-configuration.nix
    ];

  nix = {
   extraOptions = "experimental-features = nix-command flakes";
   package = pkgs.nixFlakes; 
  };

  nixpkgs.config.allowUnFree = true;

  # Use the systemd-boot EFI boot loader.
  boot.loader.systemd-boot.enable = true;
  boot.loader.efi.canTouchEfiVariables = true;

  networking.hostName = "dalinar"; # Define your hostname.
  # Pick only one of the below networking options.
  # networking.wireless.enable = true;  # Enables wireless support via wpa_supplicant.
  networking.networkmanager.enable = true;  # Easiest to use and most distros use this by default.

  # Set your time zone.
  time.timeZone = "America/Chicago";

  # Configure network proxy if necessary
  # networking.proxy.default = "http://user:password@proxy:port/";
  # networking.proxy.noProxy = "127.0.0.1,localhost,internal.domain";

  # Select internationalisation properties.
  i18n.defaultLocale = "en_US.UTF-8";

  # Enable the X11 windowing system.
  # services.xserver.enable = true;

  # Configure keymap in X11
  # services.xserver.layout = "us";
  # services.xserver.xkbOptions = {
  #   "eurosign:e";
  #   "caps:escape" # map caps to escape.
  # };

  # Enable CUPS to print documents.
  # services.printing.enable = true;

  # Enable sound.
  # sound.enable = true;
  # hardware.pulseaudio.enable = true;

  hardware.opengl = {
   enable = true;
   extraPackages = with pkgs; [
    intel-media-driver
    vaapiIntel
    vaapiVdpau
    libvdpau-va-gl    
   ];
  };

  environment.homeBinInPath = true;
  programs.fish.enable = true;

  # Enable touchpad support (enabled default in most desktopManager).
  # services.xserver.libinput.enable = true;

  # Define a user account. Don't forget to set a password with ‘passwd’.
  users.users.chris = {
    isNormalUser = true;
    extraGroups = [ "wheel" ]; # Enable ‘sudo’ for the user.
  };

  # List packages installed in system profile. To search, run:
  # $ nix search wget
  environment.systemPackages = with pkgs; [
    vim  
    wget
    yt-dlp
    bat
    ripgrep
    ffmpeg-full
    rsync
    dutree
    tmux
    git
    samba
    exa
    jq
    fd
    bc
    sysstat
    procs
    btop
    htop
    unzip
    #blesh
  ];

  virtualisation.docker.enable = true;

  # Some programs need SUID wrappers, can be configured further or are
  # started in user sessions.
  # programs.mtr.enable = true;
  # programs.gnupg.agent = {
  #   enable = true;
  #   enableSSHSupport = true;
  # };

  nix-bitcoin = {
    generateSecrets = true;
    operator = {
      enable = true;
      name = "chris";
    };
  };

  # List services that you want to enable:

  services.locate = {
    enable = true;
    locate = pkgs.plocate;
    localuser = null;
  };

  # Enable the OpenSSH daemon.
  services.openssh.enable = true;
  services.fstrim.enable = true;
  services.logind = {
    lidSwitch = "ignore";
    lidSwitchExternalPower = "ignore";
  };

  services.monero = {
    enable = true;
    dataDir = "/storage/monero";
  };

  services.bitcoind = {
    enable = true;
    listen = true;
    dataDir = "/storage/bitcoind";
  };

  services.clightning = {
    enable = true;
    dataDir = "/storage/clightning";
  };

  services.rtl = {
    enable = true;
    dataDir = "/storage/rtl";
    nightTheme = true;
    extraCurrency = "USD";
    nodes.clightning.enable = true;
  };

  # DDCLIENT
  services.ddclient = {
    enable = true;
    configFile = /home/chris/ddclient.conf;
   #domains = [
   #  "nc.cochrun.xyz"
   #  "home.cochrun.xyz"
   #  "mail.cochrun.xyz"
   #  "jelly.cochrun.xyz"
   #];
   #passwordFile = "/etc/nixos/ddclientp";
   #protocol = "namecheap";
   #use = "web, web=dynamicdns.park-your-domain.com/getip";
   #server = "dynamicdns.park-your-domain.com";
   #username = "cochrun.xyz";
   #extraConfig = ''
   #use=web, web=dynamicdns.park-your-domain.com/getip
   #protocol=namecheap
   #server=dynamicdns.park-your-domain.com
   #login=livingseedco.shop
   #password=e157e42337fc4ccd850d0a3904733f46
   #@

   #use=web, web=dynamicdns.park-your-domain.com/getip
   #protocol=namecheap
   #server=dynamicdns.park-your-domain.com
   #login=cochrun.xyz
   #password=94602c373f9f4743838bf567def2eb72
   #@,nc.cochrun.xyz,home.cochrun.xyz,mail.cochrun.xyz,jelly.cochrun.xyz


   #'';
  };

  # CADDY
  services.caddy = {
    enable = true;
    virtualHosts = {
      "home.cochrun.xyz".extraConfig = ''
        reverse_proxy localhost:8123
      '';
    };
    virtualHosts = {
      "jelly.cochrun.xyz".extraConfig = ''
        reverse_proxy localhost:8096
      '';
    };
    virtualHosts = {
      "livingseedco.shop".extraConfig = ''
        reverse_proxy localhost:8282
      '';
    };
    virtualHosts = {
      "sonarr.cochrun.xyz".extraConfig = ''
        reverse_proxy localhost:7879
      '';
    };
    virtualHosts = {
      "radarr.cochrun.xyz".extraConfig = ''
        reverse_proxy localhost:7878
      '';
    };
    virtualHosts = {
      "192.168.1.2".extraConfig = ''
        reverse_proxy localhost:9091
      '';
    };
    virtualHosts = {
      "rtl.cochrun.xyz".extraConfig = ''
        reverse_proxy localhost:3000
      '';
    };
    virtualHosts = {
      "nc.cochrun.xyz".extraConfig = ''
        reverse_proxy localhost:8080
        encode gzip
        redir /.well-known/carddav /remote.php/carddav 301
        redir /.well-known/caldav /remote.php/caldav 301
        header Strict-Transport-Security "max-age=15768000; includeSubDomains; reload;"
      '';
    };
  };

  systemd.servics = {
    # mail-cert-renew = {
    #   enable = true;
    #   serviceConfig = {
    #     Type = "oneshot";
    #     ExecStart = with pkgs.docker "sh -c /home/chris/bin/mail-cert-renew";
    #   };
    # };
  };

  # Open ports in the firewall.
  # networking.firewall.allowedTCPPorts = [ ... ];
  # networking.firewall.allowedUDPPorts = [ ... ];
  # Or disable the firewall altogether.
  networking.firewall.enable = false;

  # Copy the NixOS configuration file and link it from the resulting system
  # (/run/current-system/configuration.nix). This is useful in case you
  # accidentally delete configuration.nix.
  # system.copySystemConfiguration = true;

  # This value determines the NixOS release from which the default
  # settings for stateful data, like file locations and database versions
  # on your system were taken. It‘s perfectly fine and recommended to leave
  # this value at the release version of the first install of this system.
  # Before changing this value read the documentation for this option
  # (e.g. man configuration.nix or on https://nixos.org/nixos/options.html).
  system.stateVersion = "22.05"; # Did you read the comment?

  # The nix-bitcoin release version that your config is compatible with.
  # When upgrading to a backwards-incompatible release, nix-bitcoin will display an
  # an error and provide instructions for migrating your config to the new release.
  nix-bitcoin.configVersion = "0.0.77";
}
