# Edit this configuration file to define what should be installed on
# your system.  Help is available in the configuration.nix(5) man page
# and in the NixOS manual (accessible by running ‘nixos-help’).
{
  config,
  pkgs,
  ...
}: {
  imports = [
    # Include the results of the hardware scan.
    ./hardware-configuration.nix
  ];

  # Secret management
  sops.age.keyFile = "/var/lib/sops-nix/key.txt";
  sops.secrets.wg-priv = {
    sopsFile = ../../secrets/comfy-station/wg.yaml;
    key = "privateKey";
  };

  # Users
  users.users.jonas = {
    isNormalUser = true;
    description = "Jonas";
    extraGroups = ["networkmanager" "wheel" "docker" "dialout"];
  };
  users.defaultUserShell = pkgs.zsh;
  programs.zsh.enable = true;

  # hive modules
  hive.nix-scripts.enable = true;
  hive.displayManager.name = "sddm";
  hive.hyprland.enable = true;
  hive.kwallet.enable = true;
  hive.kwallet.forUsers = ["jonas"];
  hive.virt-manager.enable = true;
  hive.virt-manager.forUsers = ["jonas"];
  hive.bluetooth.enable = true;
  hive.sound.enable = true;
  hive.yubikey.enable = true;
  hive.wg.client.enable = true;
  hive.wg.client.privateKeyFile = config.sops.secrets.wg-priv.path;
  hive.wg.client.peer = "comfy-station";
  hive.programs.games.enable = true;
  hive.programs.games.steam = true;
  hive.programs.creative = {
    enable = true;
    image-management = true;
    image-raw-processing = true;
    video-editing-light = true;
  };

  # system packages
  environment.systemPackages = with pkgs; [
    age
    alejandra
    arduino
    borgbackup
    borgmatic
    chromium
    digikam
    discord
    docker
    docker-compose
    drawio
    feh
    ffmpeg
    firefox
    gimp
    git
    (gnome-network-displays.overrideAttrs (final: prev: {buildInputs = prev.buildInputs ++ [glib-networking];}))
    insomnia
    krita
    libreoffice
    mosquitto
    mpv
    mupdf
    nh
    nix-index
    nix-output-monitor
    obsidian
    openhantek6022
    qalculate-qt
    qtpass
    ranger
    sops
    spotify
    vim
    vlc
    vscode
    wget
    zoom
    zotero
  ];
  nixpkgs.config.permittedInsecurePackages = [
    "electron-25.9.0" # required by obsidian
  ];
  services.avahi.enable = true;
  services.udev.packages = [pkgs.openhantek6022];
  virtualisation.docker.enable = 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 = "24.11"; # Did you read the comment?

  # gc settings
  nix = {
    settings = {
      experimental-features = ["nix-command" "flakes"];
      auto-optimise-store = true;
    };
    gc = {
      automatic = true;
      dates = "weekly";
      options = "--delete-older-than 30d";
    };
  };

  # boot
  boot.loader.systemd-boot.enable = true;
  boot.loader.efi.canTouchEfiVariables = true;
  boot.plymouth.enable = true;
  boot.initrd.systemd.enable = true;
  boot.supportedFilesystems = ["ntfs"];

  # Configure console keymap
  console.keyMap = "de";

  # Set your time zone.
  time.timeZone = "Europe/Berlin";

  # Select internationalisation properties.
  i18n.defaultLocale = "en_US.UTF-8";
  i18n.extraLocaleSettings = {
    LC_ADDRESS = "de_DE.UTF-8";
    LC_IDENTIFICATION = "de_DE.UTF-8";
    LC_MEASUREMENT = "de_DE.UTF-8";
    LC_MONETARY = "de_DE.UTF-8";
    LC_NAME = "de_DE.UTF-8";
    LC_NUMERIC = "de_DE.UTF-8";
    LC_PAPER = "de_DE.UTF-8";
    LC_TELEPHONE = "de_DE.UTF-8";
    LC_TIME = "de_DE.UTF-8";
  };

  networking.hostName = "comfy-station"; # Define your hostname.

  # Enable networking
  networking.networkmanager.enable = true;

  # printing
  services.printing.enable = true;

  # touchpad
  services.libinput.touchpad.naturalScrolling = true;

  # ld-fix
  programs.nix-ld.enable = true;
  programs.nix-ld.libraries = [
    # Add any missing dynamic libraries for unpackaged programs
    # here, NOT in environment.systemPackages
  ];
}
