sddm.scm 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2016 David Craven <david@craven.ch>
  3. ;;;
  4. ;;; This file is part of GNU Guix.
  5. ;;;
  6. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  7. ;;; under the terms of the GNU General Public License as published by
  8. ;;; the Free Software Foundation; either version 3 of the License, or (at
  9. ;;; your option) any later version.
  10. ;;;
  11. ;;; GNU Guix is distributed in the hope that it will be useful, but
  12. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ;;; GNU General Public License for more details.
  15. ;;;
  16. ;;; You should have received a copy of the GNU General Public License
  17. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  18. (define-module (gnu services sddm)
  19. #:use-module (gnu packages admin)
  20. #:use-module (gnu packages display-managers)
  21. #:use-module (gnu packages freedesktop)
  22. #:use-module (gnu packages xorg)
  23. #:use-module (gnu services)
  24. #:use-module (gnu services shepherd)
  25. #:use-module (gnu services xorg)
  26. #:use-module (gnu system pam)
  27. #:use-module (gnu system shadow)
  28. #:use-module (guix gexp)
  29. #:use-module (guix records)
  30. #:export (sddm-configuration
  31. sddm-configuration?
  32. sddm-service-type
  33. sddm-service))
  34. (define-record-type* <sddm-configuration>
  35. sddm-configuration make-sddm-configuration
  36. sddm-configuration?
  37. (sddm sddm-configuration-sddm
  38. (default sddm))
  39. ;; [General]
  40. ;; valid values are x11 and wayland
  41. ;; currently doesn't do anything is enabled by wayland greeter PR
  42. (display-server sddm-configuration-display-server
  43. (default "x11"))
  44. ;; valid values are on, off or none
  45. (numlock sddm-configuration-numlock
  46. (default "on"))
  47. (halt-command sddm-configuration-halt-command
  48. (default (file-append shepherd "/sbin/halt")))
  49. (reboot-command sddm-configuration-reboot-command
  50. (default (file-append shepherd "/sbin/reboot")))
  51. ;; [Theme]
  52. ;; valid values are elarun or maldives
  53. (theme sddm-configuration-theme
  54. (default "maldives"))
  55. (themes-directory sddm-configuration-themes-directory
  56. (default "/run/current-system/profile/share/sddm/themes"))
  57. (faces-directory sddm-configuration-faces-directory
  58. (default "/run/current-system/profile/share/sddm/faces"))
  59. ;; [Users]
  60. (default-path sddm-configuration-default-path
  61. (default "/run/current-system/profile/bin"))
  62. (minimum-uid sddm-configuration-minimum-uid
  63. (default 1000))
  64. (maximum-uid sddm-configuration-maximum-uid
  65. (default 2000))
  66. (remember-last-user? sddm-configuration-remember-last-user?
  67. (default #t))
  68. (remember-last-session? sddm-configuration-remember-last-session?
  69. (default #t))
  70. (hide-users sddm-configuration-hide-users
  71. (default ""))
  72. (hide-shells sddm-configuration-hide-shells
  73. (default (file-append shadow "/sbin/nologin")))
  74. ;; [Wayland]
  75. (session-command sddm-configuration-session-command
  76. (default (file-append sddm "/share/sddm/scripts/wayland-session")))
  77. (sessions-directory sddm-configuration-sessions-directory
  78. (default "/run/current-system/profile/share/wayland-sessions"))
  79. ;; [X11]
  80. (xorg-server-path sddm-configuration-xorg-server-path
  81. (default (xorg-start-command)))
  82. (xauth-path sddm-configuration-xauth-path
  83. (default (file-append xauth "/bin/xauth")))
  84. (xephyr-path sddm-configuration-xephyr-path
  85. (default (file-append xorg-server "/bin/Xephyr")))
  86. (xdisplay-start sddm-configuration-xdisplay-start
  87. (default (file-append sddm "/share/sddm/scripts/Xsetup")))
  88. (xdisplay-stop sddm-configuration-xdisplay-stop
  89. (default (file-append sddm "/share/sddm/scripts/Xstop")))
  90. (xsession-command sddm-configuration-xsession-command
  91. (default (xinitrc)))
  92. (xsessions-directory sddm-configuration-xsessions-directory
  93. (default "/run/current-system/profile/share/xsessions"))
  94. (minimum-vt sddm-configuration-minimum-vt
  95. (default 7))
  96. (xserver-arguments sddm-configuration-xserver-arguments
  97. (default "-nolisten tcp"))
  98. ;; [Autologin]
  99. (auto-login-user sddm-configuration-auto-login-user
  100. (default ""))
  101. ;; valid values are xfce.desktop gnome.desktop weston.desktop hawaii.desktop
  102. (auto-login-session sddm-configuration-auto-login-session
  103. (default ""))
  104. (relogin? sddm-configuration-relogin?
  105. (default #f)))
  106. (define (sddm-configuration-file config)
  107. (mixed-text-file "sddm.conf" "
  108. [General]
  109. DisplayServer=" (sddm-configuration-display-server config) "
  110. Numlock=" (sddm-configuration-numlock config) "
  111. HaltCommand=" (sddm-configuration-halt-command config) "
  112. RebootCommand=" (sddm-configuration-reboot-command config) "
  113. [Users]
  114. DefaultPath=" (sddm-configuration-default-path config) "
  115. MinimumUid=" (number->string (sddm-configuration-minimum-uid config))"
  116. MaximumUid=" (number->string (sddm-configuration-maximum-uid config))"
  117. RememberLastUser=" (if (sddm-configuration-remember-last-user? config)
  118. "true" "false") "
  119. RememberLastSession=" (if (sddm-configuration-remember-last-session? config)
  120. "true" "false") "
  121. HideUsers=" (sddm-configuration-hide-users config) "
  122. Hideshells=" (sddm-configuration-hide-shells config) "
  123. [Theme]
  124. Current=" (sddm-configuration-theme config) "
  125. ThemeDir=" (sddm-configuration-themes-directory config) "
  126. FacesDir=" (sddm-configuration-faces-directory config) "
  127. [Wayland]
  128. SessionCommand=" (sddm-configuration-session-command config) "
  129. SessionDir=" (sddm-configuration-sessions-directory config) "
  130. [X11]
  131. ServerPath=" (sddm-configuration-xorg-server-path config) "
  132. XauthPath=" (sddm-configuration-xauth-path config) "
  133. XephyrPath=" (sddm-configuration-xephyr-path config) "
  134. DisplayCommand=" (sddm-configuration-xdisplay-start config) "
  135. DisplayStopCommand=" (sddm-configuration-xdisplay-stop config) "
  136. SessionCommand=" (sddm-configuration-xsession-command config) "
  137. SessionDir=" (sddm-configuration-xsessions-directory config) "
  138. MinimumVT=" (number->string (sddm-configuration-minimum-vt config)) "
  139. ServerArguments=" (sddm-configuration-xserver-arguments config) "
  140. [Autologin]
  141. User=" (sddm-configuration-auto-login-user config) "
  142. Session=" (sddm-configuration-auto-login-session config) "
  143. Relogin=" (if (sddm-configuration-relogin? config)
  144. "true" "false") "
  145. "))
  146. (define (sddm-shepherd-service config)
  147. "Return a <shepherd-service> for sddm with CONFIG."
  148. (define sddm-command
  149. #~(list (string-append #$(sddm-configuration-sddm config) "/bin/sddm")))
  150. (list (shepherd-service
  151. (documentation "SDDM display manager.")
  152. (requirement '(user-processes))
  153. (provision '(display-manager))
  154. (start #~(make-forkexec-constructor #$sddm-command))
  155. (stop #~(make-kill-destructor)))))
  156. (define (sddm-etc-service config)
  157. (list `("sddm.conf" ,(sddm-configuration-file config))))
  158. (define (sddm-pam-service)
  159. "Return a PAM service for @command{sddm}."
  160. (pam-service
  161. (name "sddm")
  162. (auth
  163. (list
  164. (pam-entry
  165. (control "requisite")
  166. (module "pam_nologin.so"))
  167. (pam-entry
  168. (control "required")
  169. (module "pam_env.so"))
  170. (pam-entry
  171. (control "required")
  172. (module "pam_succeed_if.so")
  173. (arguments (list "uid >= 1000" "quiet")))
  174. ;; should be factored out into system-auth
  175. (pam-entry
  176. (control "required")
  177. (module "pam_unix.so"))))
  178. (account
  179. (list
  180. ;; should be factored out into system-account
  181. (pam-entry
  182. (control "required")
  183. (module "pam_unix.so"))))
  184. (password
  185. (list
  186. ;; should be factored out into system-password
  187. (pam-entry
  188. (control "required")
  189. (module "pam_unix.so")
  190. (arguments (list "sha512" "shadow" "try_first_pass")))))
  191. (session
  192. (list
  193. ;; lfs has a required pam_limits.so
  194. ;; should be factored out into system-session
  195. (pam-entry
  196. (control "required")
  197. (module "pam_unix.so"))))))
  198. (define (sddm-greeter-pam-service)
  199. "Return a PAM service for @command{sddm-greeter}."
  200. (pam-service
  201. (name "sddm-greeter")
  202. (auth
  203. (list
  204. ;; Load environment from /etc/environment and ~/.pam_environment
  205. (pam-entry
  206. (control "required")
  207. (module "pam_env.so"))
  208. ;; Always let the greeter start without authentication
  209. (pam-entry
  210. (control "required")
  211. (module "pam_permit.so"))))
  212. (account
  213. (list
  214. ;; No action required for account management
  215. (pam-entry
  216. (control "required")
  217. (module "pam_permit.so"))))
  218. (password
  219. (list
  220. ;; Can't change password
  221. (pam-entry
  222. (control "required")
  223. (module "pam_deny.so"))))
  224. (session
  225. (list
  226. ;; Setup session
  227. (pam-entry
  228. (control "required")
  229. (module "pam_unix.so"))))))
  230. (define (sddm-autologin-pam-service)
  231. "Return a PAM service for @command{sddm-autologin}"
  232. (pam-service
  233. (name "sddm-autologin")
  234. (auth
  235. (list
  236. (pam-entry
  237. (control "requisite")
  238. (module "pam_nologin.so"))
  239. (pam-entry
  240. (control "required")
  241. (module "pam_succeed_if.so")
  242. (arguments (list "uid >= 1000" "quiet")))
  243. (pam-entry
  244. (control "required")
  245. (module "pam_permit.so"))))
  246. (account
  247. (list
  248. (pam-entry
  249. (control "include")
  250. (module "sddm"))))
  251. (password
  252. (list
  253. (pam-entry
  254. (control "required")
  255. (module "pam_deny.so"))))
  256. (session
  257. (list
  258. (pam-entry
  259. (control "include")
  260. (module "sddm"))))))
  261. (define (sddm-pam-services config)
  262. (list (sddm-pam-service)
  263. (sddm-greeter-pam-service)
  264. (sddm-autologin-pam-service)))
  265. (define %sddm-accounts
  266. (list (user-group (name "sddm") (system? #t))
  267. (user-account
  268. (name "sddm")
  269. (group "sddm")
  270. (system? #t)
  271. (comment "SDDM user")
  272. (home-directory "/var/lib/sddm")
  273. (shell (file-append shadow "/sbin/nologin")))))
  274. ;; Add default themes to profile
  275. (define sddm-profile-service
  276. (compose list sddm-configuration-sddm))
  277. (define sddm-service-type
  278. (service-type (name 'sddm)
  279. (extensions
  280. (list (service-extension shepherd-root-service-type
  281. sddm-shepherd-service)
  282. (service-extension etc-service-type
  283. sddm-etc-service)
  284. (service-extension pam-root-service-type
  285. sddm-pam-services)
  286. (service-extension account-service-type
  287. (const %sddm-accounts))
  288. (service-extension profile-service-type
  289. sddm-profile-service)))))
  290. (define* (sddm-service #:optional (config (sddm-configuration)))
  291. "Run the @uref{https://github.com/sddm/sddm,SSDM display manager}
  292. with the given @var{config}, a @code{<sddm-configuration>} object."
  293. (service sddm-service-type config))