home.scm 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2021 Andrew Tropin <andrew@trop.in>
  3. ;;; Copyright © 2022 Ludovic Courtès <ludo@gnu.org>
  4. ;;;
  5. ;;; This file is part of GNU Guix.
  6. ;;;
  7. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  8. ;;; under the terms of the GNU General Public License as published by
  9. ;;; the Free Software Foundation; either version 3 of the License, or (at
  10. ;;; your option) any later version.
  11. ;;;
  12. ;;; GNU Guix is distributed in the hope that it will be useful, but
  13. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  14. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. ;;; GNU General Public License for more details.
  16. ;;;
  17. ;;; You should have received a copy of the GNU General Public License
  18. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  19. (define-module (gnu home)
  20. #:use-module (gnu home services)
  21. #:use-module (gnu home services symlink-manager)
  22. #:use-module (gnu home services shells)
  23. #:use-module (gnu home services xdg)
  24. #:use-module (gnu home services fontutils)
  25. #:use-module (gnu services)
  26. #:use-module (guix records)
  27. #:use-module (guix diagnostics)
  28. #:use-module (guix gexp)
  29. #:use-module (guix store)
  30. #:use-module (ice-9 match)
  31. #:use-module (ice-9 regex)
  32. #:export (home-environment
  33. home-environment?
  34. this-home-environment
  35. home-environment-derivation
  36. home-environment-user-services
  37. home-environment-essential-services
  38. home-environment-services
  39. home-environment-location
  40. home-environment-with-provenance
  41. home-generation-base))
  42. ;;; Comment:
  43. ;;;
  44. ;;; This module provides a <home-environment> record for managing
  45. ;;; per-user packages and configuration files in the similar way as
  46. ;;; <operating-system> do for system packages and configuration files.
  47. ;;;
  48. ;;; Code:
  49. (define-record-type* <home-environment> home-environment
  50. make-home-environment
  51. home-environment?
  52. this-home-environment
  53. (packages home-environment-packages ; list of (PACKAGE OUTPUT...)
  54. (default '()))
  55. (essential-services home-environment-essential-services ; list of services
  56. (thunked)
  57. (default (home-environment-default-essential-services
  58. this-home-environment)))
  59. (services home-environment-user-services
  60. (default '()))
  61. (location home-environment-location ; <location>
  62. (default (and=> (current-source-location)
  63. source-properties->location))
  64. (innate)))
  65. (define (home-environment-default-essential-services he)
  66. "Return the list of essential services for home environment."
  67. (list
  68. (service home-run-on-first-login-service-type)
  69. (service home-activation-service-type)
  70. (service home-environment-variables-service-type)
  71. (service home-symlink-manager-service-type)
  72. (service home-fontconfig-service-type)
  73. (service home-xdg-base-directories-service-type)
  74. (service home-shell-profile-service-type)
  75. (service home-service-type)
  76. (service home-profile-service-type (home-environment-packages he))))
  77. (define* (home-environment-services he)
  78. "Return all the services of home environment."
  79. (instantiate-missing-services
  80. (append (home-environment-user-services he)
  81. (home-environment-essential-services he))))
  82. (define* (home-environment-derivation he)
  83. "Return a derivation that builds home environment."
  84. (let* ((services (home-environment-services he))
  85. (home (fold-services services
  86. #:target-type home-service-type)))
  87. (service-value home)))
  88. (define* (home-environment-with-provenance he config-file)
  89. "Return a variant of HE that stores its own provenance information,
  90. including CONFIG-FILE, if available. This is achieved by adding an instance
  91. of HOME-PROVENANCE-SERVICE-TYPE to its services."
  92. (home-environment
  93. (inherit he)
  94. (services (cons (service home-provenance-service-type config-file)
  95. (home-environment-user-services he)))))
  96. (define-gexp-compiler (home-environment-compiler (he <home-environment>)
  97. system target)
  98. ((store-lift
  99. (lambda (store)
  100. (run-with-store store (home-environment-derivation he)
  101. #:system system
  102. #:target target)))))
  103. (define %profile-generation-rx
  104. ;; Regexp that matches profile generation.
  105. (make-regexp "(.*)-([0-9]+)-link$"))
  106. (define (home-generation-base file)
  107. "If FILE is a Home generation GC root such as \"guix-home-42-link\",
  108. return its corresponding base---e.g., \"guix-home\". Otherwise return #f.
  109. This is similar to the 'generation-profile' procedure but applied to Home
  110. generations."
  111. (match (regexp-exec %profile-generation-rx file)
  112. (#f #f)
  113. (m (let ((profile (match:substring m 1)))
  114. ;; Distinguish from a "real" profile and from a system generation.
  115. (and (file-exists? (string-append profile "/on-first-login"))
  116. (file-exists? (string-append profile "/profile/manifest"))
  117. profile)))))