{ config, pkgs, lib, ... }:

{

  imports = [
    ./device-conf.nix
    private/private.nix
  ];

  home.username = "vi";
  home.homeDirectory = "/home/vi";
  home.stateVersion = "23.11"; # Please read the comment before changing.

  home.packages = with pkgs; [
    gimp
    yt-dlp
    openssl
    killall
    sshfs
    hledger
    extremetuxracer
    superTux
    superTuxKart
    pinentry
    evolution
    w3m
    nmap
    nb
    asciidoctor-with-extensions
    simple-scan
    paperwork
    xsane
    dnsutils
#    inetutils
    shotwell
    lua54Packages.lua
    lua54Packages.fennel
    entr
    zathura
    swayimg
    texliveSmall
    vlc
    quodlibet
    ffmpeg
    mosh
    openscad
    openscad-lsp
    pandoc
    lynx
    neofetch
    telegram-desktop
    git-annex
    python3
    eza
    bat
    fzf
    ripgrep
    wl-clipboard
    foot
    git
    waybar
    wofi
#    signal-desktop
    element-desktop
#    thunderbird
    keepassxc
    glib
    gsettings-desktop-schemas
    themechanger
    gnome.seahorse
    pavucontrol
    dunst
    libreoffice
    borgbackup
    gnupg
    firefox
    thunderbird
    rofi
    go
    gopls
  ];
  services.kdeconnect.enable = true;
  services.kdeconnect.indicator = true;
  programs.taskwarrior = {
    enable = true;
    config = {
      weekstart = "Monday";
      dateformat = "d.m.y";
      report.X.dateformat = "a, D. b Y";
    };
  };
  programs.alacritty = {
    enable = true;
    settings = {
      env.TERM = "xterm";
      window.opacity = 0.9;
      font.normal = {
        family = "Hack Nerd Font Mono";
        style = "Regular";
      };
      colors.primary = {
        foreground = "#fc28c3";
        background = "#230038";
      };
      font.size = 9;
    };
  };
  programs.starship = {
    enable = true;
    enableZshIntegration = true;
    enableFishIntegration = true;
    settings = {
      add_newline = false;
      format = "$username$hostname $directory$all";
      directory.style = "bold bright-blue";
      username.show_always = true;
      username.format = "[$user]($style)";
      username.style_user = "bold bright-purple";
      hostname.ssh_only = false;
      hostname.format = "[@$hostname$ssh_symbol]($style)";
      hostname.style = "bold bright-purple";
      character = {
        success_symbol = "[>>](bold light-green)";
        error_symbol = "[>>](bold red)";
      };
      line_break.disabled = true;
      cmd_duration.disabled = true;
    };
  };
  home.file = {
    ".config/sway/xenia.png".source = ./xenia.png;
    ".config/gtk-3.0/settings.ini".text = ''
      [Settings]
      gtk-application-prefer-dark-theme=1
    '';
    ".config/wofi/config".text = ''
      show=drun
      drun-print_command=true
    '';
    ".borg" = {
      source = ./borg;
      recursive = true;
    };
    "scripts" = {
      source = ./scripts;
      recursive = true;
    };
  };
  home.sessionVariables = {
    EDITOR = "nvim";
    VISUAL = "nvim";
    LEDGER_FILE = "$HOME/hledger/hledger.journal";
    PATH = "$PATH:$HOME/go/bin";
  };

  # Let Home Manager install and manage itself.
#  xsession.windowManager.i3.package = ;

  programs.home-manager.enable = true;
  programs.fish.enable = true;
  home.shellAliases = {
    ls = "exa --git";
    ll = "exa --git -l";
    la = "exa --git -al";
    tt = "exa --git -Tl";
    g = "git";
    cat = "bat";
    backup = "$HOME/.borg/backup.sh";
    grep = "rg";
    fox = "cat";
    t = "task";
    hl = "hledger";
    mountNas = "systemctl start home-vi-nas.mount";
    budget = "hledger print income:krankengeld | grep -Po \'^\\d\\d\\d\\d-\\d\\d-\\d\\d\' | tail -1 | xargs -I{} hledger balance budgets date:{}-today";
  };
  programs.neovim = {
    enable = true;
    defaultEditor = true;
    extraConfig = ''
    set number

    set listchars=tab:>-,trail:~,extends:>,precedes:<
    set list

    set expandtab
    set tabstop=2
    set shiftwidth=2

    set autoindent

    set colorcolumn=80

    set cursorline
    set mouse=a

    set clipboard=unnamedplus

    set nocompatible
    filetype plugin on
    syntax on

    call plug#begin('~/.vim/plugged')
    Plug 'mattn/calendar-vim'
    call plug#end()

    nnoremap <C-n> :Neotree<CR>

    nnoremap <tab> <C-w>

    nnoremap <C-h> :tabprevious<CR>
    nnoremap <C-l> :tabnext<CR>
    nnoremap <C-CR> :tabnew<CR>
    let g:airline_theme='violet'
    set modeline
    autocmd FileType markdown set textwidth=80
    autocmd FileType asciidoc set textwidth=80
    set scrolloff=5 

    let g:org_agenda_files = ['~/org/*.org']

    tnoremap <Esc> <C-\><C-n>
    '';
    plugins = with pkgs.vimPlugins; [
      vim-speeddating
      indentLine
      nightfox-nvim
      vim-airline
      vim-airline-themes
      neo-tree-nvim
      syntastic
      ale
      surround-nvim
      fennel-vim
      vim-orgmode
    ];
    extraLuaConfig = ''
      require("nightfox").setup({
        palettes = {
          duskfox = {
            bg1 = "#230038",
            fg1 = "#fc28c3",
          }
        }
      })
      vim.cmd("colorscheme duskfox")
    '';
    viAlias = true;
    vimAlias = true;
    vimdiffAlias = true;
  };

 services.gpg-agent.enable = true;
 services.syncthing.enable = true;
}
