;; This is an operating system configuration template
;; for a "desktop" setup without full-blown desktop
;; environments.

(use-modules (gnu)
	     (gnu system nss)
	     (gnu services)
	     (gnu system shadow)	;for user-group
	     (guix download)		;for url-fetch
	     (guix gexp)		;for file-append
	     (guix packages)		;for origin
	     (guix store)		;for %default-substitute-urls
	     (srfi srfi-1))		;for the remove function

(use-service-modules base		;for nscd-service-type
		     desktop
		     networking		;for wicd-service-type
		     ssh)		;for lsh-service

(use-package-modules admin		;for wpa-supplicant
		     android  		;for android-udev-rules
		     ratpoison
		     certs)

(define 51-android-udev.rules
  (let ((version "20170910"))
   (origin
     (method url-fetch)
     (uri (string-append "https://raw.githubusercontent.com/M0Rf30/"
			 "android-udev-rules/" version "/51-android.rules"))
     (sha256
      (base32 "0lmmagpyb6xsq6zcr2w1cyx9qmjqmajkvrdbhjx32gqf1d9is003")))))

(operating-system
  (host-name "apteryx")
  (timezone "America/Montreal")	      ;America/Los_Angeles, Asia/Tokyo
  (locale "en_US.UTF-8")

  ;; Assuming /dev/sdX is the target hard disk, and "my-root"
  ;; is the label of the target root file system.
  (bootloader (bootloader-configuration
	       (bootloader grub-bootloader)
	       (target "/dev/sda")))

  (file-systems (cons (file-system
                        (device "my-root")
                        (title 'label)
                        (mount-point "/")
                        (type "ext4"))
                      %base-file-systems))

  (users (cons (user-account
                (name "maxim")
                (comment "Maxim Cournoyer")
                (group "users")
                (supplementary-groups
		 '("lp"			;for bluetooth
		   "adbusers"		;for adb
		   "wheel" "netdev" "audio" "video"))
                (home-directory "/home/maxim"))
               %base-user-accounts))

  ;; Add plugdev to %base-groups
  (groups (cons (user-group (system? #t) (name "adbusers")) %base-groups))
  
  ;; Add a bunch of window managers; we can choose one at
  ;; the log-in screen with F1.
  (packages (cons* ratpoison
                   nss-certs		;for HTTPS access
                   %base-packages))

  ;; Use the "desktop" services, which include the X11
  ;; log-in service and more.
  (services
   (cons*
    (bluetooth-service #:auto-enable? #t)
    (modify-services %desktop-services
      ;; Add a couple extra substitute servers.
      (guix-service-type config =>
                         (guix-configuration
                          (inherit config)
                          (substitute-urls
                           (cons* "https://bayfront.guixsd.org"
				  "https://berlin.guixsd.org"
                                  %default-substitute-urls))))
      ;; Enable using adb as a simple user with a multitude of devices.
      (udev-service-type
       config =>
       (udev-configuration
      	(inherit config)
      	(rules (cons* android-udev-rules
		      (udev-configuration-rules config))))))))

  ;; Allow resolution of '.local' host names with mDNS.
  (name-service-switch %mdns-host-lookup-nss))