{ config, pkgs, ... }:

{
  # Bootloader.
  boot.loader.grub.enable = true;
  boot.loader.grub.device = "/dev/sda";
  boot.loader.grub.useOSProber = false;

  # Setup keyfile
  boot.initrd.secrets = {
    "/crypto_keyfile.bin" = null;
  };

  # Enable grub cryptodisk
  boot.loader.grub.enableCryptodisk = true;

  boot.initrd.luks.devices."luks-efc0285c-812e-4946-936b-37e737fb72eb".keyFile = "/crypto_keyfile.bin";

  networking.hostName = "lift";

  networking.networkmanager.enable = true;
  systemd.network.wait-online.enable = false;
  boot.initrd.systemd.network.wait-online.enable = false;

  sops.defaultSopsFile = ./secrets.yaml;
  sops.age.sshKeyPaths = [];
  sops.age.keyFile = "/home/rothe/.config/sops/age/keys.txt";
  sops.secrets."samba/user" = { };
  sops.secrets."samba/password" = { };
  sops.templates.sambacreds.content = ''
    username=${config.sops.placeholder."samba/user"}
    password=${config.sops.placeholder."samba/password"}
  '';

  fileSystems."/mnt/media" = {
    device = "//dalinar.home.johannes-rothe.de/media";
    fsType = "cifs";
    options = let
      # this line prevents hanging on network split
      automount_opts = "x-systemd.automount,noauto,x-systemd.idle-timeout=60,x-systemd.device-timeout=5s,x-systemd.mount-timeout=5s";

    in ["${automount_opts},credentials=${config.sops.templates.sambacreds.path},uid=1000,gid=100"];
  };

  # bluetooth
  hardware.bluetooth.enable = true;

  environment.systemPackages = with pkgs; [
    avrdude
    cryptsetup
    cifs-utils
    ffmpeg
    fzf
    gammastep
    glib
    gnupg
    ispell
    keychain
    hugo
    mosquitto
    mypy
    sqlite
  ];

  services.pcscd.enable = true;
  services.passSecretService.enable = true;

  services.blueman.enable = true;

  networking.nftables = {
    enable = true;
  };
  networking.firewall.trustedInterfaces = [ "incusbr0" ];
  # 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 = "23.05"; # Did you read the comment?

  virtualisation = {
    incus.enable = true;
    podman.enable = true;
  };
}