From patchwork Mon Jul 5 15:37:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew Tropin X-Patchwork-Id: 31382 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 8498927BC6B; Tue, 13 Jul 2021 19:19:16 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS, T_DKIM_INVALID,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 951AF27BC82 for ; Tue, 13 Jul 2021 19:19:15 +0100 (BST) Received: from localhost ([::1]:53440 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m3Mzy-0004h9-KU for patchwork@mira.cbaines.net; Tue, 13 Jul 2021 14:19:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36850) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m3Mzm-0004gM-GF for guix-patches@gnu.org; Tue, 13 Jul 2021 14:19:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:58651) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m3Mzm-0007jL-8d for guix-patches@gnu.org; Tue, 13 Jul 2021 14:19:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1m3Mzm-0000VM-5s for guix-patches@gnu.org; Tue, 13 Jul 2021 14:19:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#49546] [PATCH v2 1/4] home-services: Add most essential home services Resent-From: Andrew Tropin Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Tue, 13 Jul 2021 18:19:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 49546 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 49546@debbugs.gnu.org X-Debbugs-Original-To: guix-patches@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.16262002971832 (code B ref -1); Tue, 13 Jul 2021 18:19:02 +0000 Received: (at submit) by debbugs.gnu.org; 13 Jul 2021 18:18:17 +0000 Received: from localhost ([127.0.0.1]:41955 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1m3Mz2-0000TR-J2 for submit@debbugs.gnu.org; Tue, 13 Jul 2021 14:18:17 -0400 Received: from lists.gnu.org ([209.51.188.17]:40880) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1m3Myz-0000TH-Vb for submit@debbugs.gnu.org; Tue, 13 Jul 2021 14:18:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36642) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m3Myz-0004Nk-Py for guix-patches@gnu.org; Tue, 13 Jul 2021 14:18:13 -0400 Received: from mail-lj1-x22c.google.com ([2a00:1450:4864:20::22c]:35581) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m3Myx-00079n-Ln for guix-patches@gnu.org; Tue, 13 Jul 2021 14:18:13 -0400 Received: by mail-lj1-x22c.google.com with SMTP id 141so14828052ljj.2 for ; Tue, 13 Jul 2021 11:18:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=trop-in.20150623.gappssmtp.com; s=20150623; h=from:to:subject:in-reply-to:date:message-id:mime-version :content-transfer-encoding; bh=tfBClv/FCRsR0HdJJTBP+7HSsGD39vexKccgzPh04xQ=; b=fIxwTdfykvBTa98/WLbmmm654veURwYOOSkR5bAVtIOCDDy25zumgZ//kKpytE2c+I SHHppv3y52lADyyhFS+rc7O6LlJwpDpRhZVx5OLzSD0+eOiyuR2OL5jnNiboPlpfRA6K EPJFrlj2bQnRtF8CoeWe16bCbD4t0kdPWtlv6nBClmTCILM5vitHp+vUevOiXkU4oCNB bv3h36i/tAsd5S/t18uYvB7ELxlWDLWYkHwN4Dcx4J3pYieMVOvhcGYf9FrreBduUirO 9QGModP/2gYc7K975UCmgHc7XY5szqhOwKq4JEhjnpbxitVvmQqtINdubvZF9DzlIUDT pFBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:in-reply-to:date:message-id :mime-version:content-transfer-encoding; bh=tfBClv/FCRsR0HdJJTBP+7HSsGD39vexKccgzPh04xQ=; b=mZHlonjvuWvFY7UxfuFFDuUE256INoX/KwB11PXcalHRrW1he5hYIyaU2K2Ne+TbWr 2q3KbDjNpLzo4ibRAovVnTMsoy1E3piIAeYf+wgZ8LKcU8LUiddViK2Q6Jfbbw/ltH4U 0ZN1t79yWjD/0HuPr76oQdkt5DZXBv470TZupFCgF5UgEjnII6PDJxD8NgbpiNHc/ROq o5QXMAj9XHoJNKmpQHDuotTJw+shRzzeIZ6YrIcNdzi8iwGT1iix2spYnfODVHticUCk Uv2EQMGgFPE+iRX0ZDkWXZ6jDvN0kwJ6PX3IoghZoBrpjy+q0Zr84GDYgy8L/AuCHPie x3jg== X-Gm-Message-State: AOAM530K2tP9iXvTLnoFkoyJsZ0bWVNWjA0oD4aupLFECx+zMXbVpOwz egp4H5WXl/PDQTVcP9ApB4t86wYa9GJ8Jw== X-Google-Smtp-Source: ABdhPJwHAn9WljUNdFdUZDTIbvC4n1kZdQED2tS3tZ6bx9t185xhtAOMBsvmrMeHxPe/Ay8TRVZklQ== X-Received: by 2002:a05:651c:1507:: with SMTP id e7mr5281528ljf.9.1626200289418; Tue, 13 Jul 2021 11:18:09 -0700 (PDT) Received: from localhost (109-252-93-92.nat.spd-mgts.ru. [109.252.93.92]) by smtp.gmail.com with ESMTPSA id f14sm1985694ljk.42.2021.07.13.11.18.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Jul 2021 11:18:08 -0700 (PDT) From: Andrew Tropin In-Reply-To: <87bl76m6b7.fsf@trop.in> Date: Mon, 5 Jul 2021 18:37:13 +0300 Message-ID: <878s2am68u.fsf@trop.in> MIME-Version: 1.0 Received-SPF: none client-ip=2a00:1450:4864:20::22c; envelope-from=andrew@trop.in; helo=mail-lj1-x22c.google.com X-Spam_score_int: 15 X-Spam_score: 1.5 X-Spam_bar: + X-Spam_report: (1.5 / 5.0 requ) BAYES_00=-1.9, DATE_IN_PAST_96_XX=3.405, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches 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 (will be introudced in a separate patch series), which creates links for various dotfiles (like $XDG_CONFIG_HOME/$APP/...) 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. --- gnu/home-services.scm | 328 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 328 insertions(+) create mode 100644 gnu/home-services.scm diff --git a/gnu/home-services.scm b/gnu/home-services.scm new file mode 100644 index 0000000000..a89a061a81 --- /dev/null +++ b/gnu/home-services.scm @@ -0,0 +1,328 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright © 2021 Andrew Tropin +;;; Copyright © 2021 Xinglu Chen +;;; +;;; 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 (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 (srfi srfi-1) + #:use-module (ice-9 match) + + #:export (home-service-type + home-profile-service-type + home-environment-variables-service-type + home-files-service-type + home-run-on-first-login-service-type + home-activation-service-type) + + #:re-export (service + service-type + service-extension)) + +;;; 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. +;;; +;;; 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 + (map identity + ;;(options->transformation transformations) + (delete-duplicates packages eq?)))))))))) + +;; MAYBE: Add a list of transformations for packages. It's better to +;; place it in home-profile-service-type to affect all profile +;; packages and prevent conflicts, when other packages relies on +;; non-transformed version of package. +(define home-profile-service-type + (service-type (name 'home-profile) + (extensions + (list (service-extension home-service-type + packages->profile-entry))) + (compose concatenate) + (extend append) + (description + "This is the @dfn{home profile} and can be found in +@file{~/.guix-home/profile}. It contains packages and +configuration files that the user has declared in their +@code{home-environment} record."))) + +(define (environment-variables->setup-environment-script vars) + "Return a file that can be sourced by a POSIX compliant shell which +initializes the environment. The file will source the home +environment profile, set some default environment variables, and set +environment variables provided in @code{vars}. @code{vars} is a list +of pairs (@code{(key . value)}), @code{key} is a string and +@code{value} is a string or gexp. + +If value is @code{#f} variable will be omitted. +If value is @code{#t} variable will be just exported. +For any other, value variable will be set to the @code{value} and +exported." + (define (warn-about-duplicate-defenitions) + (fold + (lambda (x acc) + (when (equal? (car x) (car acc)) + (warning + (G_ "duplicate definition for `~a' environment variable ~%") (car x))) + x) + (cons "" "") + (sort vars (lambda (a b) + (stringsetup-environment-script))) + (compose concatenate) + (extend append) + (default-value '()) + (description "Set the environment variables."))) + +(define (files->files-directory files) + "Return a @code{files} directory that contains FILES." + (define (assert-no-duplicates files) + (let loop ((files files) + (seen (set))) + (match files + (() #t) + (((file _) rest ...) + (when (set-contains? seen file) + (raise (formatted-message (G_ "duplicate '~a' entry for files/") + file))) + (loop rest (set-insert file seen)))))) + + ;; Detect duplicates early instead of letting them through, eventually + ;; leading to a build failure of "files.drv". + (assert-no-duplicates files) + + (file-union "files" files)) + +(define (files-entry files) + "Return an entry for the @file{~/.guix-home/files} +directory containing FILES." + (with-monad %store-monad + (return `(("files" ,(files->files-directory files)))))) + +(define home-files-service-type + (service-type (name 'home-files) + (extensions + (list (service-extension home-service-type + files-entry))) + (compose concatenate) + (extend append) + (default-value '()) + (description "Configuration files for programs that +will be put in @file{~/.guix-home/files}."))) + +(define (compute-on-first-login-script _ gexps) + (gexp->script + "on-first-login" + #~(let* ((xdg-runtime-dir (or (getenv "XDG_RUNTIME_DIR") + (format #f "/run/user/~a" (getuid)))) + (flag-file-path (string-append + xdg-runtime-dir "/on-first-login-executed")) + (touch (lambda (file-name) + (call-with-output-file file-name (const #t))))) + ;; XDG_RUNTIME_DIR dissapears on logout, that means such trick + ;; allows to launch on-first-login script on first login only + ;; after complete logout/reboot. + (when (not (file-exists? flag-file-path)) + (begin #$@gexps (touch flag-file-path)))))) + +(define (on-first-login-script-entry m-on-first-login) + "Return, as a monadic value, an entry for the on-first-login script +in the home environment directory." + (mlet %store-monad ((on-first-login m-on-first-login)) + (return `(("on-first-login" ,on-first-login))))) + +(define home-run-on-first-login-service-type + (service-type (name 'home-run-on-first-login) + (extensions + (list (service-extension + home-service-type + on-first-login-script-entry))) + (compose identity) + (extend compute-on-first-login-script) + (default-value #f) + (description "Run gexps on first user login. Can be +extended with one gexp."))) + + +(define (compute-activation-script init-gexp gexps) + (gexp->script + "activate" + #~(let* ((he-init-file (lambda (he) (string-append he "/setup-environment"))) + (he-path (string-append (getenv "HOME") "/.guix-home")) + (new-home-env (getenv "GUIX_NEW_HOME")) + (new-home (or new-home-env + ;; Path of the activation file if called interactively + (dirname (car (command-line))))) + (old-home-env (getenv "GUIX_OLD_HOME")) + (old-home (or old-home-env + (if (file-exists? (he-init-file he-path)) + (readlink he-path) + #f)))) + (if (file-exists? (he-init-file new-home)) + (let* ((port ((@ (ice-9 popen) open-input-pipe) + (format #f "source ~a && env" + (he-init-file new-home)))) + (result ((@ (ice-9 rdelim) read-delimited) "" port)) + (vars (map (lambda (x) + (let ((si (string-index x #\=))) + (cons (string-take x si) + (string-drop x (1+ si))))) + ((@ (srfi srfi-1) remove) + string-null? + (string-split result #\newline))))) + (close-port port) + (map (lambda (x) (setenv (car x) (cdr x))) vars) + + (setenv "GUIX_NEW_HOME" new-home) + (setenv "GUIX_OLD_HOME" old-home) + + #$@gexps + + ;; Do not unset env variable if it was set outside. + (unless new-home-env (setenv "GUIX_NEW_HOME" #f)) + (unless old-home-env (setenv "GUIX_OLD_HOME" #f))) + (format #t "\ +Activation script was either called or loaded by file from this direcotry: +~a +It doesn't seem that home environment is somewhere around. +Make sure that you call ./activate by symlink from -home store item.\n" + new-home))))) + +(define (activation-script-entry m-activation) + "Return, as a monadic value, an entry for the activation script +in the home environment directory." + (mlet %store-monad ((activation m-activation)) + (return `(("activate" ,activation))))) + +(define home-activation-service-type + (service-type (name 'home-activation) + (extensions + (list (service-extension + home-service-type + activation-script-entry))) + (compose identity) + (extend compute-activation-script) + (default-value #f) + (description "Run gexps to activate the current +generation of home environment and update the state of the home +directory. @command{activate} script automatically called during +reconfiguration or generation switching. This service can be extended +with one gexp, but many times, and all gexps must be idempotent."))) + From patchwork Mon Jul 5 15:39:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Tropin X-Patchwork-Id: 31381 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 8F5B627BC6B; Tue, 13 Jul 2021 19:19:15 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS, T_DKIM_INVALID,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id A115D27BC85 for ; Tue, 13 Jul 2021 19:19:14 +0100 (BST) Received: from localhost ([::1]:53432 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m3Mzx-0004gj-Nn for patchwork@mira.cbaines.net; Tue, 13 Jul 2021 14:19:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36852) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m3Mzn-0004gW-3b for guix-patches@gnu.org; Tue, 13 Jul 2021 14:19:03 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:58653) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m3Mzm-0007jx-PU for guix-patches@gnu.org; Tue, 13 Jul 2021 14:19:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1m3Mzm-0000Vb-Mf for guix-patches@gnu.org; Tue, 13 Jul 2021 14:19:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#49547] [PATCH v2 2/4] home-services: Add home-run-on-change-service-type Resent-From: Andrew Tropin Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Tue, 13 Jul 2021 18:19:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 49547 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 49547@debbugs.gnu.org X-Debbugs-Original-To: guix-patches@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.16262003001850 (code B ref -1); Tue, 13 Jul 2021 18:19:02 +0000 Received: (at submit) by debbugs.gnu.org; 13 Jul 2021 18:18:20 +0000 Received: from localhost ([127.0.0.1]:41958 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1m3Mz6-0000Tk-By for submit@debbugs.gnu.org; Tue, 13 Jul 2021 14:18:20 -0400 Received: from lists.gnu.org ([209.51.188.17]:40882) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1m3Mz4-0000Tc-CU for submit@debbugs.gnu.org; Tue, 13 Jul 2021 14:18:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36670) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m3Mz4-0004Nx-6f for guix-patches@gnu.org; Tue, 13 Jul 2021 14:18:18 -0400 Received: from mail-lf1-x12d.google.com ([2a00:1450:4864:20::12d]:35509) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m3Mz2-0007Cn-NW for guix-patches@gnu.org; Tue, 13 Jul 2021 14:18:17 -0400 Received: by mail-lf1-x12d.google.com with SMTP id i5so22114249lfe.2 for ; Tue, 13 Jul 2021 11:18:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=trop-in.20150623.gappssmtp.com; s=20150623; h=from:to:subject:in-reply-to:date:message-id:mime-version; bh=CM4tFsqYNLOPPbf/KJDGWYjTRZjO1d6HTCQncmSQDsA=; b=ynszYC6lcSGABGuK08P/983Xf4xZxlQrEddaSc5FVJZvq9eEQSJN86mAdINxnAvae4 GHlxGkt4CKCpszFYeXhF8Kntq7POpD25eSz8lOvOGGSMIjnHWC+6iq9FZ3nmX6MJ2IhH 4lL5JAI/IieXztl/BlUTejwDbUk2ogH99I0a8PRzSaZZWkSEy+hkHj8LI23JQ0w08jrR anBNqaZqn9KwqNFy3Wr6Cz97vJ8yh7RPJJJmG1+S3HMUq1DurlVLJOFESK+YUB3rSVOZ PbqbmnBK8xF1ZwKoII49Qj/rsldGZEAlA4PYCk6pCOSr6cqoTrTZ0cJreNPKwBNby78n XSJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:in-reply-to:date:message-id :mime-version; bh=CM4tFsqYNLOPPbf/KJDGWYjTRZjO1d6HTCQncmSQDsA=; b=XIzqeJ336MF/FsE0MBlqIFzIcA0Owie94afF/TAnHOt2Tt/hhIAUR1j4UGJIeu1HPL FDyaHL0+NSIxofHdqKrWD7DxG61+P0ykNVtAOo37oVsT38cPc/catJeD5W4vKLAPWoPS X+665hoSYV0h+eQ+dZw1SUQ2mW/95CEyCiolgmKx7PskG9H4IP09/sKCems6aSFHo3/l EUOM13WWsDH25AL3ISnFXZ7LP8s3jyQ6zoMXpr8QjK4uHlgO5f3yMnSarySgert36w5y pQuifArtg60tECLVYDrC3ag1ED4qF/q3HOik0fjPDMPjLybRi1R4ChUgj8A0sas7nleJ O2uQ== X-Gm-Message-State: AOAM532OhhKopGclw01bnbUNvREerFiSyqWOEb4u4TVDBjAu38xQ5zL1 M2IObAdk2VJUXu1THI19VviwWwmE+YBPoQ== X-Google-Smtp-Source: ABdhPJy2z8lEXcDnqlvVmFFromu5iZkHVrImwfZln8nTgx8umvF5TyIMG2SpvgM1JjFDae+ZPULhyA== X-Received: by 2002:a05:6512:1594:: with SMTP id bp20mr4458549lfb.178.1626200293999; Tue, 13 Jul 2021 11:18:13 -0700 (PDT) Received: from localhost (109-252-93-92.nat.spd-mgts.ru. [109.252.93.92]) by smtp.gmail.com with ESMTPSA id w7sm1514611lfu.52.2021.07.13.11.18.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Jul 2021 11:18:13 -0700 (PDT) From: Andrew Tropin In-Reply-To: <87bl76m6b7.fsf@trop.in> Date: Mon, 5 Jul 2021 18:39:44 +0300 Message-ID: <875yxem679.fsf@trop.in> MIME-Version: 1.0 Received-SPF: none client-ip=2a00:1450:4864:20::12d; envelope-from=andrew@trop.in; helo=mail-lf1-x12d.google.com X-Spam_score_int: 15 X-Spam_score: 1.5 X-Spam_bar: + X-Spam_report: (1.5 / 5.0 requ) BAYES_00=-1.9, DATE_IN_PAST_96_XX=3.405, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches Service allows to trigger actions during activation if file or directory specified by pattern is changed. --- gnu/home-services.scm | 95 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 94 insertions(+), 1 deletion(-) diff --git a/gnu/home-services.scm b/gnu/home-services.scm index a89a061a81..fadad3133e 100644 --- a/gnu/home-services.scm +++ b/gnu/home-services.scm @@ -37,7 +37,8 @@ home-environment-variables-service-type home-files-service-type home-run-on-first-login-service-type - home-activation-service-type) + home-activation-service-type + home-run-on-change-service-type) #:re-export (service service-type @@ -326,3 +327,95 @@ directory. @command{activate} script automatically called during reconfiguration or generation switching. This service can be extended with one gexp, but many times, and all gexps must be idempotent."))) + +;;; +;;; On-change. +;;; + +(define (compute-on-change-gexp eval-gexps? pattern-gexp-tuples) + #~(begin + (define (equal-regulars? file1 file2) + "Check if FILE1 and FILE2 are bit for bit identical." + (let* ((cmp-binary #$(file-append + (@ (gnu packages base) diffutils) "/bin/cmp")) + (status (system* cmp-binary file1 file2))) + (= status 0))) + + (define (equal-symlinks? symlink1 symlink2) + "Check if SYMLINK1 and SYMLINK2 are pointing to the same target." + (string=? (readlink symlink1) (readlink symlink2))) + + (define (equal-directories? dir1 dir2) + "Check if DIR1 and DIR2 have the same content." + (define (ordinary-file file) + (not (or (string=? file ".") + (string=? file "..")))) + (let* ((files1 (scandir dir1 ordinary-file)) + (files2 (scandir dir2 ordinary-file))) + (if (equal? files1 files2) + (map (lambda (file) + (equal-files? + (string-append dir1 "/" file) + (string-append dir2 "/" file))) + files1) + #f))) + + (define (equal-files? file1 file2) + "Compares files, symlinks or directories of the same type." + (case (file-type file1) + ((directory) (equal-directories? file1 file2)) + ((symlink) (equal-symlinks? file1 file2)) + ((regular) (equal-regulars? file1 file2)) + (else + (display "The file type is unsupported by on-change service.\n") + #f))) + + (define (file-type file) + (stat:type (lstat file))) + + (define (something-changed? file1 file2) + (cond + ((and (not (file-exists? file1)) + (not (file-exists? file2))) #f) + ((or (not (file-exists? file1)) + (not (file-exists? file2))) #t) + + ((not (eq? (file-type file1) (file-type file2))) #t) + + (else + (not (equal-files? file1 file2))))) + + (define expressions-to-eval + (map + (lambda (x) + (let* ((file1 (string-append (getenv "GUIX_OLD_HOME") "/" (car x))) + (file2 (string-append (getenv "GUIX_NEW_HOME") "/" (car x))) + (_ (format #t "Comparing ~a and\n~10t~a..." file1 file2)) + (any-changes? (something-changed? file1 file2)) + (_ (format #t " done (~a)\n" + (if any-changes? "changed" "same")))) + (if any-changes? (cadr x) ""))) + '#$pattern-gexp-tuples)) + + (if #$eval-gexps? + (begin + (display "Evaling on-change gexps.\n\n") + (for-each primitive-eval expressions-to-eval) + (display "On-change gexps evaluation finished.\n\n")) + (display "\ +On-change gexps won't evaluated, disabled by service configuration.\n")))) + +(define home-run-on-change-service-type + (service-type (name 'home-run-on-change) + (extensions + (list (service-extension + home-activation-service-type + identity))) + (compose concatenate) + (extend compute-on-change-gexp) + (default-value #t) + (description "\ +G-expressions to run if the specified files have changed since the +last generation. The extension should be a list of lists where the +first element is the pattern for file or directory that expected to be +changed, and the second element is the G-expression to be evaluated."))) From patchwork Mon Jul 5 15:41:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Tropin X-Patchwork-Id: 31384 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id B3DF327BC82; Tue, 13 Jul 2021 19:19:23 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS, T_DKIM_INVALID,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 816C327BC6B for ; Tue, 13 Jul 2021 19:19:23 +0100 (BST) Received: from localhost ([::1]:54092 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m3N06-0005DV-Km for patchwork@mira.cbaines.net; Tue, 13 Jul 2021 14:19:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36854) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m3Mzn-0004ge-Vu for guix-patches@gnu.org; Tue, 13 Jul 2021 14:19:04 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:58655) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m3Mzn-0007kd-CP for guix-patches@gnu.org; Tue, 13 Jul 2021 14:19:03 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1m3Mzn-0000Vp-9J for guix-patches@gnu.org; Tue, 13 Jul 2021 14:19:03 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#49548] [PATCH v2 3/4] home-services: Add home-provenance-service-type Resent-From: Andrew Tropin Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Tue, 13 Jul 2021 18:19:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 49548 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 49548@debbugs.gnu.org X-Debbugs-Original-To: guix-patches@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.16262003051875 (code B ref -1); Tue, 13 Jul 2021 18:19:03 +0000 Received: (at submit) by debbugs.gnu.org; 13 Jul 2021 18:18:25 +0000 Received: from localhost ([127.0.0.1]:41962 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1m3MzA-0000U6-N9 for submit@debbugs.gnu.org; Tue, 13 Jul 2021 14:18:25 -0400 Received: from lists.gnu.org ([209.51.188.17]:40884) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1m3Mz8-0000Tx-ED for submit@debbugs.gnu.org; Tue, 13 Jul 2021 14:18:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36700) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m3Mz8-0004OD-8H for guix-patches@gnu.org; Tue, 13 Jul 2021 14:18:22 -0400 Received: from mail-lj1-x22d.google.com ([2a00:1450:4864:20::22d]:43780) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m3Mz5-0007GK-RO for guix-patches@gnu.org; Tue, 13 Jul 2021 14:18:22 -0400 Received: by mail-lj1-x22d.google.com with SMTP id r20so31330399ljd.10 for ; Tue, 13 Jul 2021 11:18:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=trop-in.20150623.gappssmtp.com; s=20150623; h=from:to:subject:in-reply-to:date:message-id:mime-version; bh=JNmk8SBqP9V9Iy5rMbBqYemUyGchx/1P+h8VkN8PBK0=; b=E2js3qIy2ZoH7uUQsUo8U3kd84mYbGk+nghCXldIlwyOyqmmnW+c3Yb28U40qVaPF0 gYg2re+n167k2a/LUw9+qjpBGNCfHMfr5iU6CXzSxOMPgcuru3vWEZk06aKEU8QKfJun 4/0CF0HrwbtVFtmGgyJSKJ5thaKoN1Mc3oLTQwiW30egFMdT4aRoje6mvlgNgMeWK5Ho uqWKCcxhFGSqcf/Ds90S0DI8OpHbPAnibauH5Ou/HaHUCABRyvYVmnh5nuOjihil8LFC 9KTaM6M9Yu+4igT0uOxV5bqEedMKCduj30S+YZRKiOEE0VeLED9SxzaDoyRgscQK2KYD G4QQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:in-reply-to:date:message-id :mime-version; bh=JNmk8SBqP9V9Iy5rMbBqYemUyGchx/1P+h8VkN8PBK0=; b=N70Lh7IeDZN7k3vsObJbwHbR2DCRrHMFVycNTtS1sXf6QT9DOY4JTd51Ip5w/tAyvx fhttdCHoon2ysHxT1lvvE6YC/i2M3WqfsOzGHPPeZhR9g2dLhx2oXqXgyR5RUPNIZH/6 g0fmyuHEnZD6DPuwIzk7vR1Rzz9JdYTM2fn/0XrStIuZTtr5W1P8If0jCUwJw7BE3/eE JWTbOsq2vaBIAXnmsG8l37Uk8r67DXEMLt0JeFOXy+OMDUxzcx5oxspOuku8a2aoVVmm Dgh5Sz1A4nX2K8AYIR+x+cFe9pPhqSFuOGEAmQVc8QKJF+SGapRSgzM6cHgF7c9oxK7/ PRxw== X-Gm-Message-State: AOAM531C9euJZvCstKptpIXRCxtR2SxeK/lyWgmLVkZRAf8OK9XDCHgK Txg1zEvlkGVazuO033R7iB6hYx5LAKEbpg== X-Google-Smtp-Source: ABdhPJwVM5lYa51rcRIPaqkIiW1UcCcCWLw0c/mX3Fmd7jf7YVY31AUVqBhyBpiIGL4YgQlAQXXR9A== X-Received: by 2002:a2e:854e:: with SMTP id u14mr5250281ljj.466.1626200297761; Tue, 13 Jul 2021 11:18:17 -0700 (PDT) Received: from localhost (109-252-93-92.nat.spd-mgts.ru. [109.252.93.92]) by smtp.gmail.com with ESMTPSA id a25sm2002746ljj.114.2021.07.13.11.18.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Jul 2021 11:18:17 -0700 (PDT) From: Andrew Tropin In-Reply-To: <87bl76m6b7.fsf@trop.in> Date: Mon, 5 Jul 2021 18:41:07 +0300 Message-ID: <871r82m66t.fsf@trop.in> MIME-Version: 1.0 Received-SPF: none client-ip=2a00:1450:4864:20::22d; envelope-from=andrew@trop.in; helo=mail-lj1-x22d.google.com X-Spam_score_int: 15 X-Spam_score: 1.5 X-Spam_bar: + X-Spam_report: (1.5 / 5.0 requ) BAYES_00=-1.9, DATE_IN_PAST_96_XX=3.405, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches * gnu/home-services.scm (home-provenance-service-type, sexp->home-provenance, home-provenance): New variables. --- gnu/home-services.scm | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/gnu/home-services.scm b/gnu/home-services.scm index fadad3133e..ffcee22bb8 100644 --- a/gnu/home-services.scm +++ b/gnu/home-services.scm @@ -38,7 +38,10 @@ home-files-service-type home-run-on-first-login-service-type home-activation-service-type - home-run-on-change-service-type) + home-run-on-change-service-type + home-provenance-service-type + + fold-home-service-types) #:re-export (service service-type @@ -419,3 +422,25 @@ G-expressions to run if the specified files have changed since the last generation. The extension should be a list of lists where the first element is the pattern for file or directory that expected to be changed, and the second element is the G-expression to be evaluated."))) + + +;;; +;;; Provenance tracking. +;;; + +(define home-provenance-service-type + (service-type + (name 'home-provenance) + (extensions + (list (service-extension + home-service-type + (service-extension-compute + (first (service-type-extensions provenance-service-type)))))) + (default-value #f) ;the HE config file + (description "\ +Store provenance information about the home environment in the home +environment itself: the channels used when building the home +environment, and its configuration file, when available."))) + +(define sexp->home-provenance sexp->system-provenance) +(define home-provenance system-provenance) From patchwork Mon Jul 5 15:41:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Tropin X-Patchwork-Id: 31383 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id D52C727BC6B; Tue, 13 Jul 2021 19:19:16 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS, T_DKIM_INVALID,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id A164527BC82 for ; Tue, 13 Jul 2021 19:19:16 +0100 (BST) Received: from localhost ([::1]:53520 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m3Mzz-0004jy-LS for patchwork@mira.cbaines.net; Tue, 13 Jul 2021 14:19:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36858) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m3Mzo-0004gu-AB for guix-patches@gnu.org; Tue, 13 Jul 2021 14:19:04 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:58657) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m3Mzn-0007l3-UX for guix-patches@gnu.org; Tue, 13 Jul 2021 14:19:03 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1m3Mzn-0000W4-Rm for guix-patches@gnu.org; Tue, 13 Jul 2021 14:19:03 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#49549] [PATCH v2 4/4] home-services: Add fold-home-service-types function Resent-From: Andrew Tropin Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Tue, 13 Jul 2021 18:19:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 49549 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 49549@debbugs.gnu.org X-Debbugs-Original-To: guix-patches@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.16262003071884 (code B ref -1); Tue, 13 Jul 2021 18:19:03 +0000 Received: (at submit) by debbugs.gnu.org; 13 Jul 2021 18:18:27 +0000 Received: from localhost ([127.0.0.1]:41964 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1m3MzD-0000UK-8B for submit@debbugs.gnu.org; Tue, 13 Jul 2021 14:18:27 -0400 Received: from lists.gnu.org ([209.51.188.17]:40890) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1m3MzA-0000U5-LA for submit@debbugs.gnu.org; Tue, 13 Jul 2021 14:18:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36720) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m3MzA-0004OY-Fm for guix-patches@gnu.org; Tue, 13 Jul 2021 14:18:24 -0400 Received: from mail-lj1-x22e.google.com ([2a00:1450:4864:20::22e]:41664) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m3Mz9-0007Ik-4W for guix-patches@gnu.org; Tue, 13 Jul 2021 14:18:24 -0400 Received: by mail-lj1-x22e.google.com with SMTP id e20so31326261ljn.8 for ; Tue, 13 Jul 2021 11:18:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=trop-in.20150623.gappssmtp.com; s=20150623; h=from:to:subject:in-reply-to:date:message-id:mime-version; bh=yrAKTn9umLbx/fYv7ew4SyzS2m+ivTBR/NGZXsOMMRg=; b=vWxv2PrMkfPi8SzgAh3q979pD8VaJ0zvW+2iHrDiovUeuTYpayoiLvhZ86pkZuu0+8 6uVAthw3U5+VEJ2UpasxIN0t3Pa/yiahnXH1eRDSBuSAFP+wtA5RCDV804n7tTEhqKKX KDiv7dyraguy2Q7Tr0nEon3bWhhqzeimbl3WAln+zHS/io2vghBs9IhhSOD26Q18s9OB ipYsKmxtchzXTz04s9W6x/6Tb+L/P7beHxDAuJWM84H8YLj2obdbNKpJPuYWXnNRnSQg IPKBB49crFdElskuvu4iwCL4n18bFSq1suvyfy8ad8/cidch1l+v095JrYscYPv5Vhpi Z6Cw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:in-reply-to:date:message-id :mime-version; bh=yrAKTn9umLbx/fYv7ew4SyzS2m+ivTBR/NGZXsOMMRg=; b=X3jWPxgU7M+IoCgSGNjPGdc4cA0PAaWSFqu+0Bp03tpIG3+NfXif841Q5Dwa5iMlsf UUS1KZ1IaW2kCsckUB8jQfICn0el/OdQWpDn/ds01ZHj/q2Zub9p7uiANIY9mxoh/o6N hXuz7w5iG5yhfL3WAPU/dpa1rnSkjna6no67SMG1y9rcLv4Z37jC89d5r4hF0JnVTKyu VT38eRBVApa/ZoRD04Ez47gRfQQUdVa0l+84ta/EUgbCLETSuInq5/99+sAOD9V5RcQe JxdXXvlb8XkDFFnK7PZHpQook46ozyvpyRgbzhGe4ThcI9963n2YBo0wl5jpmFKRhnF+ cpMg== X-Gm-Message-State: AOAM5314i5pNpUDSSs1okyWEaV1Hh2SeWPkTeTtv+TS3pSaNoo9+dWOh leQGOpqeR3zGz3vCYapKkjOKAA2HjkDtKg== X-Google-Smtp-Source: ABdhPJx9B0/fenFXkw54J6IAM8jhJXeuG7N+PAqmP05+nAHX0hFyp1U3WBTlsiDNVpWED+6a9VpECw== X-Received: by 2002:a2e:9090:: with SMTP id l16mr3185209ljg.275.1626200301397; Tue, 13 Jul 2021 11:18:21 -0700 (PDT) Received: from localhost (109-252-93-92.nat.spd-mgts.ru. [109.252.93.92]) by smtp.gmail.com with ESMTPSA id c9sm2001116ljb.22.2021.07.13.11.18.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Jul 2021 11:18:21 -0700 (PDT) From: Andrew Tropin In-Reply-To: <87bl76m6b7.fsf@trop.in> Date: Mon, 5 Jul 2021 18:41:45 +0300 Message-ID: <87y2aakrly.fsf@trop.in> MIME-Version: 1.0 Received-SPF: none client-ip=2a00:1450:4864:20::22e; envelope-from=andrew@trop.in; helo=mail-lj1-x22e.google.com X-Spam_score_int: 15 X-Spam_score: 1.5 X-Spam_bar: + X-Spam_report: (1.5 / 5.0 requ) BAYES_00=-1.9, DATE_IN_PAST_96_XX=3.405, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches * gnu/home-services.scm (parent-directory, %guix-home-root-directory, %service-type-path, all-home-service-modules, fold-home-service-types): New variables. --- gnu/home-services.scm | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/gnu/home-services.scm b/gnu/home-services.scm index ffcee22bb8..78e5603edf 100644 --- a/gnu/home-services.scm +++ b/gnu/home-services.scm @@ -444,3 +444,29 @@ environment, and its configuration file, when available."))) (define sexp->home-provenance sexp->system-provenance) (define home-provenance system-provenance) + + +;;; +;;; Searching +;;; + +(define (parent-directory directory) + "Get the parent directory of DIRECTORY" + (string-join (drop-right (string-split directory #\/) 1) "/")) + +(define %guix-home-root-directory + ;; Absolute file name of the module hierarchy. + (parent-directory (dirname (search-path %load-path "gnu/home-services.scm")))) + +(define %service-type-path + ;; Search path for service types. + (make-parameter `((,%guix-home-root-directory . "gnu/home-services")))) + +(define (all-home-service-modules) + "Return the default set of home-service modules." + (cons (resolve-interface '(gnu home-services)) + (all-modules (%service-type-path) + #:warn warn-about-load-error))) + +(define* (fold-home-service-types proc seed) + (fold-service-types proc seed (all-home-service-modules)))