(use-modules (gnu)
	     (guix gexp)
	     (guix modules))
(use-service-modules networking ssh)
(use-package-modules tmux ssh)

(operating-system
  (host-name "guixvm")
  (timezone "xxxx/xxxx")
  (locale "en_US.utf8")

  (mapped-devices
   (list (mapped-device
          (source (uuid "ba778b24-4025-40ab-b5f3-57acf1eb8ac4")) ;; luks1
          (target "boot")
          (type luks-device-mapping))
         (mapped-device
          (source (uuid "38659c87-82d9-4bb8-97e1-405dc3dfc40e")) ;; luks2
          (target "root")
          (type luks-device-mapping))
         (mapped-device
          (source (uuid "c987052c-76fd-44b9-8a60-986845ad2584")) ;; luks2
          (target "swap")
          (type luks-device-mapping))
         (mapped-device
          (source (uuid "2fca8372-a1b6-46b4-808a-0de9be4f2d76")) ;; luks2
          (target "root-raid")
          (type luks-device-mapping))))
  
  (bootloader (bootloader-configuration
               (bootloader grub-efi-bootloader)
               (targets '("/efi"))))

  (file-systems (append
                 (list (file-system
                         (device "none")
                         (mount-point "/")
                         (type "tmpfs")
			 (options "size=500M,mode=755")
			 (check? #f))
		       (file-system
                         (device (uuid "1111-1111" 'fat)) ;; TODO use label?
                         (mount-point "/efi")
                         (type "vfat")
			 (create-mount-point? #t)) ;; TODO needed-for-boot?
		       (file-system
                         (device (file-system-label "boot"))
                         (mount-point "/boot")
                         (type "btrfs")
			 (flags '(no-atime))
			 (options "compress=zstd:1,space_cache=v2,ssd")
			 (check? #f)
			 (create-mount-point? #t)
                         (dependencies mapped-devices)) ;; TODO filter
		       (file-system
                         (device (file-system-label "root"))
                         (mount-point "/gnu")
                         (type "btrfs")
			 (flags '(no-atime))
			 (options "compress=zstd:1,space_cache=v2,ssd,subvol=@gnu")
			 (needed-for-boot? #t)
			 (check? #f)
			 (create-mount-point? #t)
                         (dependencies mapped-devices)) ;; TODO filter
		       (file-system
                         (device (file-system-label "root"))
                         (mount-point "/var")
                         (type "btrfs")
			 (flags '(no-atime))
			 (options "compress=zstd:1,space_cache=v2,ssd,subvol=@var")
			 (needed-for-boot? #t)
			 (check? #f)
			 (create-mount-point? #t)
                         (dependencies mapped-devices)) ;; TODO filter
		       (file-system ;; TODO bind mount state files
                         (device (file-system-label "root"))
                         (mount-point "/state")
                         (type "btrfs")
			 (flags '(no-atime))
			 (options "compress=zstd:1,space_cache=v2,ssd,subvol=@state")
			 (needed-for-boot? #t)
			 (check? #f)
			 (create-mount-point? #t)
                         (dependencies mapped-devices)) ;; TODO filter
		       (file-system
                         (device (file-system-label "root"))
                         (mount-point "/home")
                         (type "btrfs")
			 (flags '(no-atime))
			 (options "compress=zstd:1,space_cache=v2,ssd,subvol=@home")
			 (needed-for-boot? #t)
			 (check? #f)
			 (create-mount-point? #t)
                         (dependencies mapped-devices)) ;; TODO filter
		       )
                 %base-file-systems))

  (swap-devices (list (swap-space
                       (target (file-system-label "swap"))
		       (dependencies mapped-devices) ;; TODO filter
		       (discard? #t))))
  
  ;; This is where user accounts are specified.  The "root"
  ;; account is implicit, and is initially created with the
  ;; empty password.
  (users (cons (user-account
                (name "me")
                (comment "xxxx")
                (group "users")

                ;; Adding the account to the "wheel" group
                ;; makes it a sudoer.  Adding it to "audio"
                ;; and "video" allows the user to play sound
                ;; and access the webcam.
                (supplementary-groups '("wheel"
                                        "audio" "video")))
               %base-user-accounts))

  ;; Globally-installed packages.
  (packages (cons tmux %base-packages))

  ;; Add services to the baseline: a DHCP client and
  ;; an SSH server.
  (services (append (list (service dhcp-client-service-type)
                          (service openssh-service-type
                                   (openssh-configuration
                                    (openssh openssh-sans-x)
                                    (port-number 22))))
                    %base-services)))
;;