sddm.scm 13 KB

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