;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2021-2023 Andrew Tropin ;;; Copyright © 2021 Xinglu Chen ;;; Copyright © 2022-2023 Ludovic Courtès ;;; ;;; This file is part of GNU Guix. ;;; ;;; GNU Guix is free software; you can redistribute it and/or modify it ;;; under the terms of the GNU General Public License as published by ;;; the Free Software Foundation; either version 3 of the License, or (at ;;; your option) any later version. ;;; ;;; GNU Guix is distributed in the hope that it will be useful, but ;;; WITHOUT ANY WARRANTY; without even the implied warranty of ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;;; GNU General Public License for more details. ;;; ;;; You should have received a copy of the GNU General Public License ;;; along with GNU Guix. If not, see . (define-module (gnu home services) #:use-module (gnu services) #:use-module ((gnu packages package-management) #:select (guix)) #:use-module ((gnu packages base) #:select (coreutils)) #:use-module (guix channels) #:use-module (guix monads) #:use-module (guix store) #:use-module (guix gexp) #:use-module (guix profiles) #:use-module (guix sets) #:use-module (guix ui) #:use-module (guix discovery) #:use-module (guix diagnostics) #:use-module (guix i18n) #:use-module (guix modules) #:use-module (guix memoization) #:use-module (srfi srfi-1) #:use-module (srfi srfi-9) #:use-module (ice-9 match) #:use-module (ice-9 vlist) #:export (home-service-type home-profile-service-type home-environment-variables-service-type home-files-service-type home-xdg-configuration-files-service-type home-xdg-data-files-service-type home-run-on-first-login-service-type home-activation-service-type home-run-on-change-service-type home-provenance-service-type literal-string literal-string? literal-string-value with-shell-quotation-bindings environment-variable-shell-definitions home-files-directory xdg-configuration-files-directory xdg-data-files-directory fold-home-service-types lookup-home-service-types home-provenance define-service-type-mapping system->home-service-type %initialize-gettext) #:re-export (service service-type service-extension for-home for-home?)) ;;; Comment: ;;; ;;; This module is similar to (gnu system services) module, but ;;; provides Home Services, which are supposed to be used for building ;;; home-environment. ;;; ;;; Home Services use the same extension as System Services. Consult ;;; (gnu system services) module or manual for more information. ;;; ;;; home-service-type is a root of home services DAG. ;;; ;;; home-profile-service-type is almost the same as profile-service-type, at least ;;; for now. ;;; ;;; home-environment-variables-service-type generates a @file{setup-environment} ;;; shell script, which is expected to be sourced by login shell or other program, ;;; which starts early and spawns all other processes. Home services for shells ;;; automatically add code for sourcing this file, if person do not use those home ;;; services they have to source this script manually in their's shell *profile ;;; file (details described in the manual). ;;; ;;; home-files-service-type is similar to etc-service-type, but doesn't extend ;;; home-activation, because deploy mechanism for config files is pluggable ;;; and can be different for different home environments: The default one is ;;; called symlink-manager, which creates links for various dotfiles and xdg ;;; configuration files to store, but is possible to implement alternative ;;; approaches like read-only home from Julien's guix-home-manager. ;;; ;;; home-run-on-first-login-service-type provides an @file{on-first-login} guile ;;; script, which runs provided gexps once, when user makes first login. It can ;;; be used to start user's Shepherd and maybe some other process. It relies on ;;; assumption that /run/user/$UID will be created on login by some login ;;; manager (elogind for example). ;;; ;;; home-activation-service-type provides an @file{activate} guile script, which ;;; do three main things: ;;; ;;; - Sets environment variables to the values declared in ;;; @file{setup-environment} shell script. It's necessary, because user can set ;;; for example XDG_CONFIG_HOME and it should be respected by activation gexp of ;;; symlink-manager. ;;; ;;; - Sets GUIX_NEW_HOME and possibly GUIX_OLD_HOME vars to paths in the store. ;;; Later those variables can be used by activation gexps, for example by ;;; symlink-manager or run-on-change services. ;;; ;;; - Run all activation gexps provided by other home services. ;;; ;;; home-run-on-change-service-type allows to trigger actions during ;;; activation if file or directory specified by pattern is changed. ;;; ;;; Code: (define (home-derivation entries mextensions) "Return as a monadic value the derivation of the 'home' directory containing the given entries." (mlet %store-monad ((extensions (mapm/accumulate-builds identity mextensions))) (lower-object (file-union "home" (append entries (concatenate extensions)))))) (define home-service-type ;; This is the ultimate service type, the root of the home service ;; DAG. The service of this type is extended by monadic name/item ;; pairs. These items end up in the "home-environment directory" as ;; returned by 'home-environment-derivation'. (service-type (name 'home) (extensions '()) (compose identity) (extend home-derivation) (default-value '()) (description "Build the home environment top-level directory, which in turn refers to everything the home environment needs: its packages, configuration files, activation script, and so on."))) (define (packages->profile-entry packages) "Return a system entry for the profile containing PACKAGES." ;; XXX: 'mlet' is needed here for one reason: to get the proper ;; '%current-target' and '%current-target-system' bindings when ;; 'packages->manifest' is called, and thus when the 'package-inputs' ;; etc. procedures are called on PACKAGES. That way, conditionals in those ;; inputs see the "correct" value of these two parameters. See ;; . (mlet %store-monad ((_ (current-target-system))) (return `(("profile" ,(profile (content (packages->manifest