;; This is my home environment
;; 
;; 
;; 
;; 

(define-module (home)
  #:use-module (pkgs emacs-xyz)
  #:use-module (pkgs tridactyl-native)
  #:use-module (home-services pipewire)
  #:use-module (gnu home)
  #:use-module (gnu home services)
  #:use-module (gnu home services desktop)
  #:use-module (gnu home services shells)
  #:use-module (gnu home services xdg)
  #:use-module (gnu home services gnupg)
  #:use-module (gnu packages)
  #:use-module (gnu packages vim)
  #:use-module (gnu packages rust-apps)
  #:use-module (gnu packages video)
  #:use-module (gnu packages gnupg)
  #:use-module (gnu services)
  #:use-module (guix gexp)
  #:use-module (guix packages)
  #:use-module (guix git-download)
  #:use-module (guix build-system emacs)
  #:use-module ((guix licenses) #:prefix license:))

(define home-packages
  (list "vim"
        "exa"
        "unzip"
        "rsync"
        "openssh"
        "gcc-toolchain"
        "make"
        "git"
        "curl"
	"mpv"
	"mpv-mpris"
	"yt-dlp"
        "python"
        "playerctl"
        "gstreamer"
        "gst-plugins-base"
        "gst-plugins-good"
        "gst-plugins-bad"
        "gst-plugins-ugly"
        "gst-libav"
        "alsa-utils"
        "pavucontrol"
        "v4l-utils"
        "tmux"
        "direnv"
        "dutree"
        "btop"
        "htop"
        "ripgrep"
        "bat"
        "alacritty"
        "libnotify"
        "nextcloud-client"
        "rofi-wayland"
        "waybar"
        "qt5ct"
        "fd"
        "bc"
        "sysstat"
        "ffmpeg"
        "pandoc"
        "grim"
        "slurp"
        "imv"
        "firefox"
        "openjdk"
        "kwallet"
        "kwallet-pam"
        "breeze"
        "breeze-icons"
        "kdeconnect"
        ;; "tridactyl-native"
        "qtwayland@5.15.8"
        ;; "qtwayland"
        "egl-wayland"
        "pinentry"
        "pinentry-qt"
        "pinentry-gnome3"
        "pinentry-rofi"
        "pulsemixer"
        "pamixer"
        "python-pulsectl"
        "dunst"
        "rbw"
        "aspell"
        "aspell-dict-en"
        "alsa-utils"
        "lightly"
        "swaylock-effects"
        "swayidle"
        "wtype"
        "brightnessctl"
        "flatpak"
        "flatpak-xdg-utils"
        "sound-theme-freedesktop"
        "xdg-utils"
        "xdg-desktop-portal"
        "xdg-desktop-portal-kde"
        "papirus-icon-theme"
        "font-google-noto"
        "font-google-noto-emoji"
        "enchant"
        "blesh"
        "ncurses"
        "transmission"

        ;; Emacs and packages
        "emacs-next-pgtk"
        "emacs-dired-rsync"
        "emacs-all-the-icons"
        "emacs-org-roam"
        "emacs-paredit"
        "emacs-evil-paredit"
        "emacs-doom-modeline"
        "emacs-doom-themes"
        "emacs-org"
        "emacs-elfeed"
        "emacs-elfeed-org"
        "emacs-esh-autosuggest"
        "emacs-use-package"
        "emacs-exec-path-from-shell"
        "emacs-langtool"
        "emacs-avy"
        "emacs-general"
        "emacs-evil"
        "emacs-evil-collection"
        "emacs-no-littering"
        "emacs-evil-escape"
        "emacs-smartparens"
        "emacs-evil-org"
        "emacs-evil-smartparens"
        "emacs-aggressive-indent"
        "emacs-adaptive-wrap"
        "emacs-which-key"
        "emacs-evil-surround"
        "emacs-websocket"
        "emacs-org-modern"
        "emacs-org-web-tools"
        "emacs-org-re-reveal"
        "emacs-org-ql"
        "emacs-org-msg"
        "emacs-calfw"
        "emacs-transmission"
        "emacs-emojify"
        "emacs-pulsar"
        "emacs-vertico"
        "emacs-consult"
        "emacs-consult-eglot"
        "emacs-consult-org-roam"
        "emacs-tempel"
        "emacs-tempel-collection"
        "emacs-marginalia"
        "emacs-embark"
        "emacs-wgrep"
        "emacs-corfu"
        "emacs-cape"
        "emacs-rainbow-delimiters"
        "emacs-orderless"
        "emacs-kind-icon"
        "emacs-projectile"
        "emacs-simple-httpd"
        "emacs-direnv"
        "emacs-diredfl"
        "emacs-pdf-tools"
        "emacs-vterm"
        "emacs-plz"
        "emacs-ement"
        "emacs-bongo"
        "emacs-emms"
        "emacs-gcmh"
        "emacs-visual-fill-column"
        "emacs-eat"
        "emacs-mpv"
        "emacs-all-the-icons-dired"
        "emacs-all-the-icons-completion"
        "emacs-org-super-agenda"
        "emacs-toc-org"
        "emacs-ox-reveal"
        "emacs-ox-pandoc"
        "emacs-ox-hugo"
        "emacs-dired-sidebar"
        "emacs-dired-du"
        "emacs-ledger-mode"
        "emacs-rustic"
        "emacs-lua-mode"
        "emacs-fennel-mode"
        "emacs-web-mode"
        "emacs-yaml-mode"
        "emacs-cmake-mode"
        "emacs-typescript-mode"
        "emacs-fish-mode"
        "emacs-markdown-mode"
        "emacs-restclient"
        "emacs-ob-restclient"
        "emacs-guix"
        "emacs-nix-mode"
        "emacs-helpful"
        ;; "emacs-mu4e"
        "isync"
        "mu"))

(home-environment
  (packages (specifications->packages home-packages))

  (services
   (list (service home-bash-service-type
                  (home-bash-configuration
                   (guix-defaults? #t)
                   (aliases '(("grep" . "grep --color=auto")
                              ("gh" . "guix home -L ~/dotfiles/guix reconfigure ~/dotfiles/guix/home.scm")
                              ("gs" . "sudo guix system -L /home/chris/dotfiles/guix reconfigure /home/chris/dotfiles/guix/$(hostname).scm")))
                   (environment-variables
                    '(("QT_QPA_PLATFORM" . "wayland-egl")
                      ("QT_QPA_PLATFORMTHEME" . "qt5ct")
                      ("XDG_DATA_DIRS" . "$XDG_DATA_DIRS:$HOME/.local/share/flatpak/exports/share")
                      ("RTC_USE_PIPEWIRE" . "true")
                      ("GDK_BACKEND" . "wayland")
                      ("WLR_DRM_NO_ATOMIC" . "1")
                      ("MOZ_ENABLE_WAYLAND" . "1")
                      ("WLR_BACKEND" . "vulkan")
                      ("WLR_RENDERER" . "vulkan")
                      ("SDL_VIDEODRIVER" . "wayland")
                      ("WLR_NO_HARDWARE_CURSORS" . "1")
                      ("GTK_USE_PORTAL" . "1")
                      ("EDITOR" . "emacsclient -t -a")
                      ("VISUAL" . "emacsclient -c -a")))
                   (bashrc (list (plain-file "blesh" "source $HOME/.guix-home/profile/share/blesh/ble.sh")
                                 (plain-file "home-manager" "source $HOME/.nix-profile/etc/profile.d/hm-session-vars.sh")
                                 ;;These need to be here so they are at the bottom and therefore after guix-defaults
                                 (plain-file "exal" "alias ls=\"exa -l\"")
                                 (plain-file "exala" "alias la=\"exa -la\"")
                                 (plain-file "less-color" "export LESS=\"--RAW-CONTROL-CHARS\"")
                                 (plain-file "man-colors" "[[ -f ~/.LESS_TERMCAP ]] && . ~/.LESS_TERMCAP")
                                 (plain-file "starship" "source $HOME/.config/starship/init.sh")))))
         (simple-service 'extra-env-vars
          		 home-environment-variables-service-type
          		 `(("PATH" . "$PATH:/home/chris/bin:/home/chris/.nix-profile/bin")
                           ("QT_QPA_PLATFORM" . "wayland-egl")
                           ("SDL_VIDEODRIVER" . "wayland")
                           ("MOZ_ENABLE_WAYLAND" . "1")
                           ("CLUTTER_BACKEND" . "wayland")
                           ("ELM_ENGINE" . "wayland_egl")
                           ("ECORE_EVAS_ENGINE" . "wayland-egl")
                           ("QT_QPA_PLATFORMTHEME" . "qt5ct")
                           ("LITERAL_VALUE" . ,(literal-string "${abc}"))))
         (service home-fish-service-type
                  (home-fish-configuration
                   (aliases '(("ls" . "exa -l")
                              ("gh" . "guix home -L ~/dotfiles/guix reconfigure ~/dotfiles/guix/home.scm")
                              ("gs" . "sudo guix system -L /home/chris/dotfiles/guix reconfigure /home/chris/dotfiles/guix/$(hostname).scm")))))
         (simple-service 'config
                         home-xdg-configuration-files-service-type
                         `(("hypr" ,(local-file "../.config/hypr" #:recursive? #t))
                           ("tridactyl" ,(local-file "../.config/tridactyl" #:recursive? #t))
                           ("eww" ,(local-file "../.config/eww" #:recursive? #t))
                           ("waybar" ,(local-file "../.config/waybar" #:recursive? #t))
                           ("rofi" ,(local-file "../.config/rofi" #:recursive? #t))
                           ("dunst" ,(local-file "../.config/dunst" #:recursive? #t))
                           ("btop" ,(local-file "../.config/bpytop" #:recursive? #t))
                           ("mpv" ,(local-file "../.config/mpv" #:recursive? #t))
                           ("blesh" ,(local-file "../.config/blesh" #:recursive? #t))
                           ("starship" ,(local-file "../.config/starship" #:recursive? #t))
                           ("starship.toml" ,(local-file "../.config/starship.toml"))
                           ("guix/channels.scm" ,(local-file "channels.scm"))
                           ("home-manager/home.nix" ,(local-file "home.nix"))
                           ("qt5ct/colors/snazzy.conf" ,(local-file "../.config/qt5ct/snazzy.conf"))
                           ("alacritty/alacritty.yml" ,(local-file "../.config/alacritty/alacritty.yml"))))
         (simple-service 'scripts
                         home-files-service-type
                         `(("bin" ,(local-file "../scripts" #:recursive? #t))
                           (".mozilla/firefox/chris.default/chrome" ,(local-file "../.config/firefox/chrome" #:recursive? #t))))

         (service home-gpg-agent-service-type
                  (home-gpg-agent-configuration
                   (pinentry-program
                    (file-append pinentry-rofi "/bin/pinentry-rofi"))
                   (ssh-support? #t)
                   (default-cache-ttl 28800)
                   (max-cache-ttl 28800)
                   (default-cache-ttl-ssh 28800)
                   (max-cache-ttl-ssh 28800)))

         (service home-xdg-user-directories-service-type
                  (home-xdg-user-directories-configuration
                   (videos "$HOME/vids")
                   (pictures "$HOME/pics")
                   (download "$HOME/dls")
                   (documents "$HOME/docs")
                   (music "$HOME/music")
                   (templates "$HOME")
                   (desktop "$HOME")
                   (publicshare "$HOME")))
         (service home-xdg-mime-applications-service-type
                  (home-xdg-mime-applications-configuration
                   (default '(("video/mp4" . "mpv.desktop")
                              ("video/webm" . "mpv.desktop")
                              ("video/x-matroska" . "mpv.destop")
                              ("video/mkv" . "mpv.destop")
                              ("video/quicktime" . "mpv.destop")
                              ("video/mpeg" . "mpv.desktop")
                              ("video/ogg" . "mpv.desktop")
                              ("video/VP9" . "mpv.desktop")
                              ("video/VP8" . "mpv.desktop")
                              ("video/AV1" . "mpv.desktop")
                              ("video/H264" . "mpv.desktop")
                              ("video/H265" . "mpv.desktop")
                              ("video/H266" . "mpv.desktop")
                              ("video/vnd.youtube.yt" . "mpv.desktop")
                              ("application/x-extension-htm" . "firefox.desktop")
                              ("application/x-extension-html" . "firefox.desktop")
                              ("application/x-extension-shtml" . "firefox.desktop")
                              ("application/x-extension-xht" . "firefox.desktop")
                              ("application/x-extension-xhtml" . "firefox.desktop")
                              ("application/xhtml+xml" . "firefox.desktop")
                              ("inode/directory" . "dolphin.desktop")
                              ("image/gif" . "imv.desktop")
                              ("image/jpeg" . "imv.desktop")
                              ("image/heif" . "imv.desktop")
                              ("image/png" . "imv.desktop")
                              ("audio/vorbis" . "mpv-slow.desktop")
                              ("audio/mp3" . "mpv-slow.desktop")
                              ("audio/flac" . "mpv-slow.desktop")
                              ("audio/wav" . "mpv-slow.desktop")
                              ("audio/opus" . "mpv-slow.desktop")))
                   (added '(("video/mp4" . "mpv.desktop")
                            ("video/webm" . "mpv.desktop")
                            ("video/mpeg" . "mpv.desktop")
                            ("video/ogg" . "mpv.desktop")
                            ("video/VP9" . "mpv.desktop")
                            ("video/VP8" . "mpv.desktop")
                            ("video/AV1" . "mpv.desktop")
                            ("video/H264" . "mpv.desktop")
                            ("video/H265" . "mpv.desktop")
                            ("video/H266" . "mpv.desktop")
                            ("video/vnd.youtube.yt" . "mpv.desktop")
                            ("video/x-matroska" . "mpv.destop")
                            ("video/mkv" . "mpv.destop")
                            ("video/quicktime" . "mpv.destop")
                            ("application/x-extension-htm" . "firefox.desktop")
                            ("application/x-extension-html" . "firefox.desktop")
                            ("application/x-extension-shtml" . "firefox.desktop")
                            ("application/x-extension-xht" . "firefox.desktop")
                            ("application/x-extension-xhtml" . "firefox.desktop")
                            ("application/xhtml+xml" . "firefox.desktop")
                            ("image/gif" . "imv.desktop")
                            ("image/jpeg" . "imv.desktop")
                            ("image/heif" . "imv.desktop")
                            ("image/png" . "imv.desktop")
                            ("audio/vorbis" . "mpv-slow.desktop")
                            ("audio/mp3" . "mpv-slow.desktop")
                            ("audio/flac" . "mpv-slow.desktop")
                            ("audio/wav" . "mpv-slow.desktop")
                            ("audio/opus" . "mpv-slow.desktop")))
                   (desktop-entries
                    (list (xdg-desktop-entry
                           (file "mpv-slow")
                           (name "MPV for Audio and Streams")
                           (type 'application)
                           (config
                            '((exec . "mpv --profile=slow %U"))))))))
         (service home-pipewire-service-type)
         (service home-dbus-service-type))))