From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id aDDdLyTZ7WBqRAEAgWs5BA (envelope-from ) for ; Tue, 13 Jul 2021 20:19:16 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id UF5xKyTZ7WA8awAAB5/wlQ (envelope-from ) for ; Tue, 13 Jul 2021 18:19:16 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 277232B8F4 for ; Tue, 13 Jul 2021 20:19:16 +0200 (CEST) Received: from localhost ([::1]:53432 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m3Mzz-0004gj-1U for larch@yhetil.org; Tue, 13 Jul 2021 14:19:15 -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 Content-Type: text/plain 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+larch=yhetil.org@gnu.org Sender: "Guix-patches" X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1626200356; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type:resent-cc:resent-from:resent-sender: resent-message-id:in-reply-to:in-reply-to:list-id:list-help: list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=Hxjqzi8NuA+jjbXv7PpjYjM8VwHVY4j7XPpmS6F3s9w=; b=Xv1ehUiL5opkUB4CS4j9thjYZq59FhmkLMNf9cW9qkjr9akYz91XP4trCvssoJeH/rkTEf SUbSaqvE3BxFgAtzBWEWyBMrh8/Fb9QoPHdsIKGNz93GF7lCFZaZjWxqsJcuOFmy3dkeDD 7pbHC2xoQt4fxWhBEFs4oId6xnlCXOnolCEQiIeTYP2+MkE/it3Ni7vml7S8dz96bJxvyk 9jvlRyqi6wd6xlw3EBzXlg4qNXYCEhJQW4dP9qPrTuedJDJgoyhNmgvP+nqWiOkCUwW/dO 4LrS4PY6+24OJfU43aSVN9wLvhYnUvslGsP3bgn6i59EkPAoRSR4BR/B488Wpw== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1626200356; a=rsa-sha256; cv=none; b=COm4k6lXyQ3LwvBT3hqLLxpisBjWA+ib6a9Vmhu6QICXNbDnGrnRuCX+7Uj+Y6tAhg238z VZmseUrX9AfujzEVMNcwaflQBQA3WkN5YW85XXgjUGhrz122sOIJKg4PnDYe0xT0C7gZKk 1h6A135QtGCRPjTeN8gLQNo7f3L5zLn+o1obiMSZMoiS7KWdwbbc0DResFy2e3lRbrbJo6 vz9egzbL3cuZb5jfUUdcKnkQK6g7uLIDpNLaK2tUfZ0DS7247+Hc61r4fbZqFV5jWNd0B+ AZd3EpvBCqf8ZOqTtR7nKbjVotZ49rUBiBGkOWGBsahBCKZ7/S9fbGobYR2cvA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=trop-in.20150623.gappssmtp.com header.s=20150623 header.b=ynszYC6l; dmarc=none; spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Migadu-Spam-Score: -0.40 Authentication-Results: aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=trop-in.20150623.gappssmtp.com header.s=20150623 header.b=ynszYC6l; dmarc=none; spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Migadu-Queue-Id: 277232B8F4 X-Spam-Score: -0.40 X-Migadu-Scanner: scn0.migadu.com X-TUID: Kzo5y7qBJqdH 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."))) -- 2.32.0