user.scm 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2018 Mathieu Othacehe <m.othacehe@gmail.com>
  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 installer user)
  19. #:use-module (guix records)
  20. #:use-module (srfi srfi-1)
  21. #:use-module (srfi srfi-9)
  22. #:use-module (srfi srfi-9 gnu)
  23. #:export (<secret>
  24. secret?
  25. make-secret
  26. secret-content
  27. <user>
  28. user
  29. make-user
  30. user-name
  31. user-real-name
  32. user-group
  33. user-home-directory
  34. user-password
  35. users->configuration))
  36. (define-record-type <secret>
  37. (make-secret content)
  38. secret?
  39. (content secret-content))
  40. (set-record-type-printer!
  41. <secret>
  42. (lambda (secret port)
  43. (format port "<secret>")))
  44. (define-record-type* <user>
  45. user make-user
  46. user?
  47. (name user-name)
  48. (real-name user-real-name
  49. (default ""))
  50. (group user-group
  51. (default "users"))
  52. (password user-password)
  53. (home-directory user-home-directory))
  54. (define (users->configuration users)
  55. "Return the configuration field for USERS."
  56. (define (user->sexp user)
  57. `(user-account
  58. (name ,(user-name user))
  59. (comment ,(user-real-name user))
  60. (group ,(user-group user))
  61. (home-directory ,(user-home-directory user))
  62. (supplementary-groups '("wheel" "netdev"
  63. "audio" "video"))))
  64. `((users (cons*
  65. ,@(filter-map (lambda (user)
  66. ;; Do not emit a 'user-account' form for "root".
  67. (and (not (string=? (user-name user) "root"))
  68. (user->sexp user)))
  69. users)
  70. %base-user-accounts))))