From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id 4IxTNdt7C2FvbQEAgWs5BA (envelope-from ) for ; Thu, 05 Aug 2021 07:49:15 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id CFLUMNt7C2FIMAAAbx9fmQ (envelope-from ) for ; Thu, 05 Aug 2021 05:49:15 +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 701D322D71 for ; Thu, 5 Aug 2021 07:49:15 +0200 (CEST) Received: from localhost ([::1]:46936 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mBWFm-0002AS-Hj for larch@yhetil.org; Thu, 05 Aug 2021 01:49:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36732) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mBWFa-0001ku-RL for guix-patches@gnu.org; Thu, 05 Aug 2021 01:49:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:34106) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mBWFa-0001B3-LV for guix-patches@gnu.org; Thu, 05 Aug 2021 01:49:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mBWFa-0006nw-Kx for guix-patches@gnu.org; Thu, 05 Aug 2021 01:49:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#49419] [PATCH v4 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: Thu, 05 Aug 2021 05:49:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 49419 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 49419@debbugs.gnu.org Received: via spool by 49419-submit@debbugs.gnu.org id=B49419.162814250426055 (code B ref 49419); Thu, 05 Aug 2021 05:49:02 +0000 Received: (at 49419) by debbugs.gnu.org; 5 Aug 2021 05:48:24 +0000 Received: from localhost ([127.0.0.1]:45641 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mBWEx-0006mB-Ul for submit@debbugs.gnu.org; Thu, 05 Aug 2021 01:48:24 -0400 Received: from mail-lf1-f53.google.com ([209.85.167.53]:46673) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mBWEw-0006ld-61 for 49419@debbugs.gnu.org; Thu, 05 Aug 2021 01:48:22 -0400 Received: by mail-lf1-f53.google.com with SMTP id n17so6144869lft.13 for <49419@debbugs.gnu.org>; Wed, 04 Aug 2021 22:48: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:references:date:message-id:mime-version; bh=YlAzzSc+mdsxWuVnzk3GnyglD9z4SEk3pY2qS7tWLcg=; b=UcbkQCoQ3EizV+TlbZBDsq/VvdgOr9jOsz40hH+aP6qdnkgZkBtrZ/UYZwJWH0Ru7c Jxq169HKsB/aYVWCcIOBtE1+l/KWRjrMwv2nDeEqyn50Nc2ApK5ZFBj5kdnfbYUNmCuv XLeIauI4ioQSl2/f3s+pUMROroO9zZa2tvc/et3kFUxZCEJb8DxIcCQmSyB67TosQGJU ZsBVpXmH8pVD7vBI30sTwj7IIGp8dDX1O3bFVP4AXv5Fc83SeTZw76rD+Cx30Tk+Bs3A GlFYaBOdbPMcfadlfkWrd471CPj8Ziyj57mdqD8T1wek0GjE6I9N9hwQPaLc9UIasG08 2TaA== 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:references:date :message-id:mime-version; bh=YlAzzSc+mdsxWuVnzk3GnyglD9z4SEk3pY2qS7tWLcg=; b=lMLJVCorCtPrU1Xb/gOXdZgqKb6Q01aWNeYbeOBv6wlIteDx90jL5xNy02m9XgbNaY rCguSz2ziKmIBZbaimeL7vDY9n7AR7/pfKGX9kn4AwS0JWfUdiYzNi8p4CeM22iLotsq F1NYDJEWRbZCdXnFDwBWPILfYEGl/lwon/3dTTzU/fwfDRS95mINlV4WphdSUTfEr6Wp 8TFh0zBlUV1y0/LrdKPro6Wnse1jhEgX0XbJpakB6eiHGE6l8Kf/GtL1G28U4THfV+X3 yqbynyfYpNXtY1oZxdKhsXdZBepblsso0n1zBrMw7uq37f0R3jWHUfkuGqQpMPiS+Sw4 Lbew== X-Gm-Message-State: AOAM531VecMfZuqtGCb1lvSunh5NIhL+aGtGS6uYXCnSMmQRyYMAbyVi d5HtV+vxRmzr9Svyb2H6ayYelKm808zbpYX6 X-Google-Smtp-Source: ABdhPJz39VQoM2yIZgGrdaBNDh4h7csKuWcUfL2AZBDYn5l9SMz1Zxy8R+d+TkihlCXig7pgZ2FWjQ== X-Received: by 2002:ac2:4150:: with SMTP id c16mr2305289lfi.127.1628142496105; Wed, 04 Aug 2021 22:48:16 -0700 (PDT) Received: from localhost ([109.252.93.92]) by smtp.gmail.com with ESMTPSA id j10sm401306lfk.286.2021.08.04.22.48.15 for <49419@debbugs.gnu.org> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Aug 2021 22:48:15 -0700 (PDT) From: Andrew Tropin In-Reply-To: <87tuk4mors.fsf@trop.in> References: <87y2akhiz1.fsf@trop.in> <87tuk4mors.fsf@trop.in> Date: Thu, 05 Aug 2021 08:46:22 +0300 Message-ID: <87mtpwmok1.fsf@trop.in> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha512; protocol="application/pgp-signature" 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=1628142555; 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:references:references: list-id:list-help:list-unsubscribe:list-subscribe:list-post: dkim-signature; bh=zlfr6k7UstkhCPVChs5vj/2RlyPxmuuHu3055MyJPRk=; b=e7Phghdu9e3TwbDUUsDWWmJonS92fBpP2p4fEefmSSHzUyH+byAllwTFG6A67XcFm9nSTy STHE68DD64i2lCx2BfcRktCdMAPOMck876PEyyKP5NKwOfXPBscE4+TZV9VQjj1KsH7GpY 15Q5YeizeQAUEDckBNJ5tuvM6mffNUasBU94TwXU2pH82uPIr4t6n+BDGxTp2zlXeyj4dq r/VAI0U5KltVq3SYPprox7rz52QaakNwwAa0fVymMhiO+IScX38fEa5/f1JH003t2p+7o2 pNuh4kEWS05c2mlMwI0R/AXbamHW3OcVQdz4RgrgbOPtugkqA5Ee4lXWOvn7NA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1628142555; a=rsa-sha256; cv=none; b=g9uo1ipEZ6oX6NsON7Bfq1NucWseiXAng9rud37BMylmWEC/88u4kqpI4gUfqSvv9OJBsc x0Wc8d21a3etoHdmbCE4M8lwMED3+7/zzbqgTSBq0XC0reNiQ9Ru/ylNofmgqFjgakYQQA BpVdp7Q596M53fyCTiST/8UtZBmt40trpvk5VeDkSRQEWiIVNLPAHc5CJ88rwdiPxRrqcS id28rMki9wNW41DfLJUnXnVbDkN7IaqF/eF250w034MvIABwVhu8ss2csC/uJvGwdGe5ys GVgDU3/VhycwoJJZxN0JQqEViofmfR5jYRcE7gDS7O9XFQlYCBYXdhSvdCf3tA== 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=UcbkQCoQ; 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: -1.02 Authentication-Results: aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=trop-in.20150623.gappssmtp.com header.s=20150623 header.b=UcbkQCoQ; 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: 701D322D71 X-Spam-Score: -1.02 X-Migadu-Scanner: scn0.migadu.com X-TUID: jTVFeHHb8VVv --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable * gnu/home-services.scm (home-run-on-change-service-type): New variable. =2D-- gnu/home-services.scm | 103 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 102 insertions(+), 1 deletion(-) diff --git a/gnu/home-services.scm b/gnu/home-services.scm index 4a6458abec..32b59f55df 100644 =2D-- 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 =2D home-activation-service-type) + home-activation-service-type + home-run-on-change-service-type) =20 #:re-export (service service-type @@ -92,6 +93,9 @@ ;;; ;;; - 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: =20 =20 @@ -366,3 +370,100 @@ directory. @command{activate} script automatically c= alled during reconfiguration or generation switching. This service can be extended with one gexp, but many times, and all gexps must be idempotent."))) =20 + +;;; +;;; 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"= )) + (stats1 (lstat file1)) + (stats2 (lstat file2))) + (cond + ((=3D (stat:ino stats1) (stat:ino stats2)) #t) + ((not (=3D (stat:size stats1) (stat:size stats2))) #f) + + (else (=3D (system* cmp-binary file1 file2) 0))))) + + (define (equal-symlinks? symlink1 symlink2) + "Check if SYMLINK1 and SYMLINK2 are pointing to the same target." + (string=3D? (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=3D? file ".") + (string=3D? 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."))) =2D-=20 2.32.0 --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQJDBAEBCgAtFiEEKEGaxlA4dEDH6S/6IgjSCVjB3rAFAmELey4PHGFuZHJld0B0 cm9wLmluAAoJECII0glYwd6wBiUP/i7ILAYn7hh1SE8feonHznL7sbUOZqosToMy rXfI3XIW8xGQr3Br4rDzWnYSgPYVnrBYzibzBV7K8Wl6oNhQNARneHKAsgNNEPXN yLkzc1IDsHtcF8MGOZ4/2ANvyckkS6u0xz3/P0qjlsP60Zew5fGvMJb/+MFthq5+ 4hynnDk8XuRlQN/4qq6Zwhr7Mgzuaq9n8L7IyVusWYmgh4M2WviOzTlST01Q/2ta XgaRJ6XNz0QtP0dLNaIG+5LEVSfxtZfVW5/xVBxo+VRhNG8i/adTnsAcL+/gpFiy lDiblx+nrwwk6ybuk8ms+QlR0FSE5j4Oz6NQglsZ+JMZe8JqvGZoZs+lL6ZaIWMH JAaZfWLJhZRxaCX9Kej3Z9TsKweR/ettYZHPRXFc+5AlolPUUB0IppUPQJYxg+jn Idcd8P893GUqHcEp6m7Bz5aotIGuMGumWECw3pXiMGOYx9vfjlCr32u3J/fqy2cg zzF3nFyEejCa+SZp3d/uzkBPuFabzhy+/uaxXk8aXlyBCUk/w9ZCjqtb0eqpnrGd tbdSkz/R7XhDgJlgoK/st5bidP/pCRR1lRmBoUR/4imZzO6WCwxIp2rUjb268rh2 sZsf7iOX00Gg1NlPACPIwJwa6IS0lce8V0gRgxOnCm+AsdIn8u+6/oFa65emyU1S W2ljCkCO =WGSU -----END PGP SIGNATURE----- --=-=-=--