(add-to-load-path "/etc/guix-config")

(use-modules
  (gnu)
  (gnu system nss)
  (gnu packages certs)
  (gnu packages linux)
  (gnu packages wm)
  (gnu packages wordnet)
  (gnu packages dictionaries)
  (gnu services desktop)
  (gnu services networking)
  (gnu services xorg)
  (gnu services cups)
  (gnu services ssh)
  (gnu services dbus)
  (gnu services virtualization)
  (gnu services authentication)
  (gnu services dict)
  (gnu services linux))

;; DICT
(define wordnet-handler
  (dicod-handler
    (name "wordnet")
    (module "dictorg")
    (options
      (list #~(string-append "dbdir=" #$wordnet)))))
(define vera-handler
  (dicod-handler
    (name "vera")
    (module "dictorg")
    (options
      (list #~(string-append "dbdir=" #$vera)))))

(define wordnet-db
  (dicod-database
    (name "wordnet")
    (complex? #t)
    (handler "wordnet")
    (options '("database=wn"))))
(define vera-db
  (dicod-database
    (name "vera")
    (complex? #t)
    (handler "vera")
    (options '("database=vera"))))

;; Kernel
(define v4l2loopback-config
  (plain-file "v4l2loopback.conf"
              "options v4l2loopback video_nr=6,7,8,9 card_label=loopback0,loopback1,loopback2,loopback3 exclusive_caps=1"))

;; System
(define sudoers
  (plain-file "sudoers" "\
root ALL=(ALL) ALL
%wheel ALL=(ALL) ALL
Cmnd_Alias WITHOUTPW = /home/cobra/.local/bin/__suspend, /home/cobra/.local/bin/beep, /run/current-system/profile/sbin/halt, /run/current-system/profile/sbin/reboot
Defaults!WITHOUTPW !authenticate
"))


(operating-system
  (kernel linux-libre)
  (kernel-loadable-modules (list v4l2loopback-linux-module))
  (kernel-arguments '("intel_iommu=on"
                      "kvm.ignore_msrs=1"
                      "log_buf_len=1M"))
  (keyboard-layout (keyboard-layout "us" "altgr-intl"))
  (bootloader
    (bootloader-configuration
      (bootloader (bootloader
                    (inherit grub-bootloader)
                    (installer #~(const #t))))
      (keyboard-layout keyboard-layout)))
  (host-name "Xenon")
  (mapped-devices (list
                    (mapped-device
                      (source (uuid "e836ef6e-97a8-442b-a025-e81ab58bbc04"))
                      (target "fde")
                      (type luks-device-mapping))
                    (mapped-device
                      (source "matrix")
                      (targets (list "matrix-rootvol"))
                      (type lvm-device-mapping))))
  (file-systems (append (list
                          (file-system
                            (type "btrfs")
                            (mount-point "/")
                            (device (file-system-label "root"))
                            (flags '(no-atime))
                            (options "space_cache=v2")
                            (needed-for-boot? #t)
                            (dependencies mapped-devices)))
                        %base-file-systems))
  (users (append (list
                   (user-account
                     (name "cobra")
                     (comment "Skylar \"The Cobra\" Widulski")
                     (group "users")
                     (supplementary-groups '("audio"
                                             "cdrom"
                                             "dialout"
                                             "input"
                                             "kvm"
                                             "libvirt"
                                             "lp"
                                             "netdev"
                                             "tape"
                                             "video"
                                             "wheel"))))
                 %base-user-accounts))
  (packages (append
              (map specification->package+output
                   (list ;; Bluetooth
                         "bluez"

			 ;; DVD
                         "libdvdcss"
                         "libdvdread"

                         ;; Fonts
                         "font-awesome"
                         "font-fira-code"
                         "font-fira-mono"
                         "font-fira-sans"
                         "font-google-noto"
                         "font-google-noto-sans-cjk"
                         "font-google-noto-serif-cjk"
                         "font-liberation"

                         ;; Graphics
                         "intel-vaapi-driver"
                         "mesa"
                         "mesa-utils"

                         ;; Kernel
                         "v4l2loopback-linux-module"

                         ;; Network
                         "nss-certs"
                         "torsocks"
                         "tor"

                         ;; System
                         "acpi"
                         "cryptsetup"
                         "curl"
                         "dconf"
                         "gnunet"
                         "lvm2"
                         "openssh"
                         "openssl"

                         ;; Utilities
                         "vim"

                         ;; Virtualization
                         "libvirt"
                         "virt-manager"
                         "qemu"))
              (cons*
                %base-packages)))
  (timezone "America/New_York")
  (locale "en_US.utf8")
  (name-service-switch %mdns-host-lookup-nss)
  (services
    (cons*
      ;; Bluetooth
      (service bluetooth-service-type
               (bluetooth-configuration
                 (auto-enable? #t)))

      ;; Desktop
      (service screen-locker-service-type
               (screen-locker-configuration
                 "swaylock" (file-append swaylock "/bin/swaylock") #f))

      ;; DICT
      (service dicod-service-type
               (dicod-configuration
                 (handlers (list wordnet-handler vera-handler))
                 (databases (list wordnet-db vera-db %dicod-database:gcide))))

      ;; Kernel
      (service kernel-module-loader-service-type
               '("v4l2loopback"))
      (simple-service 'v4l2loopback etc-service-type
                      (list `("modprobe.d/v4l2loopback.conf"
                              ,v4l2loopback-config)))

      ;; Network
      (service cups-service-type)
      (service network-manager-service-type)
      (service ntp-service-type)
      (service tor-service-type
               (tor-configuration
                 (config-file (plain-file "tor-config"
                                          "HTTPTunnelPort 127.0.0.1:9250"))))
      (service wpa-supplicant-service-type)

      ;; System
      (service dbus-root-service-type)
      (service elogind-service-type)
      (service openssh-service-type
               (openssh-configuration
                 (permit-root-login 'prohibit-password)
                 (password-authentication? #f)))
      (service gpm-service-type)

      ;; Virtualization
      (service libvirt-service-type
               (libvirt-configuration
                 (unix-sock-group "libvirt")))
      (service virtlog-service-type)

      (modify-services %base-services
        (guix-service-type
          config => (guix-configuration
                      (inherit config)
                      (http-proxy "http://localhost:9250"))))))
  (sudoers-file sudoers))
