From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id oE0vLpez9WDmtgAAgWs5BA (envelope-from ) for ; Mon, 19 Jul 2021 19:17:11 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id GPHqKZez9WDKcgAA1q6Kng (envelope-from ) for ; Mon, 19 Jul 2021 17:17:11 +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 2504F1749C for ; Mon, 19 Jul 2021 19:17:11 +0200 (CEST) Received: from localhost ([::1]:53164 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m5WtC-0001qT-9q for larch@yhetil.org; Mon, 19 Jul 2021 13:17:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42806) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m5WsC-0000FK-0t for guix-patches@gnu.org; Mon, 19 Jul 2021 13:16:09 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:48672) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m5Ws6-0004bD-NQ for guix-patches@gnu.org; Mon, 19 Jul 2021 13:16:07 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1m5Ws6-0000vO-GQ for guix-patches@gnu.org; Mon, 19 Jul 2021 13:16:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#49419] [PATCH v3 2/4] home-services: Add home-run-on-change-service-type References: <87y2akhiz1.fsf@trop.in> Resent-From: Andrew Tropin Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Mon, 19 Jul 2021 17:16: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.16267149371936 (code B ref 49419); Mon, 19 Jul 2021 17:16:02 +0000 Received: (at 49419) by debbugs.gnu.org; 19 Jul 2021 17:15:37 +0000 Received: from localhost ([127.0.0.1]:60210 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1m5Wrh-0000Ud-0M for submit@debbugs.gnu.org; Mon, 19 Jul 2021 13:15:37 -0400 Received: from mail-lf1-f51.google.com ([209.85.167.51]:45719) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1m5Wre-0000Mo-S1 for 49419@debbugs.gnu.org; Mon, 19 Jul 2021 13:15:35 -0400 Received: by mail-lf1-f51.google.com with SMTP id s13so9973956lfi.12 for <49419@debbugs.gnu.org>; Mon, 19 Jul 2021 10:15:34 -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=4T1NvBI/PBjgT7dYtoDFyHLWKROkJqiISaqS3KrtH4M=; b=byObvKyvh7JyRQIf7jIgzzgCkdixnJuN8fgL960XfnKaKwwqiz/x2BAjEUVh4/7Dad 6FEqotJBJa+uTEatR46eVhhNkS5eEKGbxJCD88iWLH45jNx0GKMzisJZE6YO4FF7/CqH Yr8uR/ivaEd3fhbDjqxr5qSYoXuvX+/k4F696APGrICzdPCERwTh4oL2BXQ427fhjiuH Val6Vc2W3V/YCuZuERFhBg1U1Ea0UkYn8eyMRKiRsH+VZjBnkWxl6ovPrAlC+zJTguqM TTB2h18l59MFOMOem4RmeuY7dXRadQ0AhTZLWy6yj17OugxBenQOo9HtLLTvpfvIObhE r8/g== 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=4T1NvBI/PBjgT7dYtoDFyHLWKROkJqiISaqS3KrtH4M=; b=iu8MEYcqaE8N0bn8EmWAWnZyVeETLi/Q3/2+ULRN0/97bgwdRCKUCXk9nnd/EEGftf 20fKl8dlV0C0YMAlKbNUFQtdUv0xbAP3piEs0yc8OVyMFkYR6s3rwVMxH3W9LTdPe2Y3 sRi4KEqRlZ73z8eHf+V73bGYz3WI4s7Jh3xEo20bO8Di1etNYjaBPxVgROWGzrBsqO8s ETyWzfmZ/S8AoFz+N779Z3H2nZfeH6TbGc6FGERx2rjFZmBR5e+nxpz4L1qcE1521XyL etaLaAII7dSL6O7Mw694zncaiRRNC/A07nO+4gKr/8mPSNjMmxnI80JsS1qYIxUpADer mEDA== X-Gm-Message-State: AOAM531hyhH1XpGAoJ3Pp6cohcZT/Nxkj5oUK4N8RC/6C8EtmhCB4Jli sUQKKAbH60aaB2yQenHOKa2vgfGHBguD9g== X-Google-Smtp-Source: ABdhPJwpPVOQc5sovcU4Xyma7Rq5M1me3at9F/mwKO2OEQckIQcDqvzYamGDoYbzhfkThjt1jwPmoA== X-Received: by 2002:ac2:4187:: with SMTP id z7mr18572970lfh.574.1626714928816; Mon, 19 Jul 2021 10:15:28 -0700 (PDT) Received: from localhost ([85.249.24.60]) by smtp.gmail.com with ESMTPSA id x19sm1331004lfd.275.2021.07.19.10.15.27 for <49419@debbugs.gnu.org> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Jul 2021 10:15:28 -0700 (PDT) From: Andrew Tropin In-Reply-To: <87v956g1g5.fsf@trop.in> Date: Mon, 5 Jul 2021 18:39:44 +0300 Message-ID: <87sg0ag19m.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=1626715031; 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=kDRCVFWZT90ktqmRd/t403NWdJV/PdlTWbfjqVUMuJg=; b=kJY67Vn5E2YjkIhYYWUapbhwGlaFveD+xLb96Kh/yqYeMYwRhduFuR1/xSnAFPuTukLS8y 4KOXClpxn2U57pA2/u4euHqPGMMeihtkruQS84k+UhQUyfj2PJsZrncQm+STD0YNRes0UN tBUSizEt6sBi9ohHVtVXWjXXnNFgJYer7kLdByEIe/oIxWPfZGmaIUoYlKpxPndYu4iRPM v/ICWpaX5dcZDOT5F2pS4W4osjaPgvhZ6IVnii5jxBe3Fj0V8BbAA139XJfaqOyUfA0cY7 O45sEx1/N5iysXpi0N6BAKcs6jUo4uOr5Cy3Rdyjn2Ruc4FJgrbb+cVrU4Wr7Q== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1626715031; a=rsa-sha256; cv=none; b=cQfDz6Pi7haK/mlgWJQsh+IDODEcR2EUkN8Iyq8WOzacTJSfCVbqxxch9HeuL/DIaN8z0f hObATELhHPf72BfY/WmLkhHNgfi28eGu5+OMyhBVC4NSsaNzaetpgTm8Lm5RSXQxQYjpLz QnN5QPiDK/F4LNX6LXsV7xdND3eqT2NMheLnhT+NRvK4sfgOPyy1Ag470Ojfw7pEBX24qs s0GbtdqFbm4NCWVNPtwpq3qWayjoShdJUDrnXWI2tTOuWwOFzPSa32TyPInTdQCUgupGlS VQ58yVSZ/fLDBJLzoyKOI61USqWw1+AkXZMSmzEUl3lZwemTyDwZN8jG8qU+Zg== 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=byObvKyv; 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.01 Authentication-Results: aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=trop-in.20150623.gappssmtp.com header.s=20150623 header.b=byObvKyv; 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: 2504F1749C X-Spam-Score: -0.01 X-Migadu-Scanner: scn1.migadu.com X-TUID: njK4HWP5LG1/ --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Service allows to trigger actions during activation if file or directory specified by pattern is changed. =2D-- gnu/home-services.scm | 100 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 99 insertions(+), 1 deletion(-) diff --git a/gnu/home-services.scm b/gnu/home-services.scm index a89a061a81..bcb6dd80df 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 @@ -326,3 +327,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/6IgjSCVjB3rAFAmD1NpUPHGFuZHJld0B0 cm9wLmluAAoJECII0glYwd6wl0QP/0TbNHav4kQ7KiQKF9M3HPWz3qNeLMO+SgBs MGx/1kApFVTrph8Ua2u17IRKlvxggxzrj2wOjHgs5z0pauMx7s2sdKQ4ficHIEqv wuTdo5xI0/eWkYY+fBVd3ErYtSUxv3uqZz5SgJUeq/rUtCul7u1EC0bTDn95aLwX 6NDcb9AwuWCdKUKF+VBODMvdsc4ve34oddlYbVFA7ct6SP8O7KclcUl/p69CHwND UCzSOrq6D3Nt2pOqbwjLnmhWQr+nJFIoLqRlqf0sBxZBMX6YNk37QqEygVuzvfCZ vuszh1yjfDggbgd0DeUqAiVI03KO9QgO1Xr1ZlmUOJsdhqy1xqdG8ifu4hoBc2Cb bcLxj/7Ei6/u3p8+Ls95n9i/C3ir/gGXtyBcNBnYJoPEL7rOEJGstv4VMNF8cMR1 12PAzO5edQbLFaMNLGhKyOncQPDQshQJWaAr7oybXG7GoyJ3uPmWLBSJi+8lLAUi jbmn8GIrY1x9KyFpVNznjkQ90FQpCAJQwCO0vKnPErhisA4FyKR7NA2d/1Z2djnX sGQNU04j1JA8TkYNsW6o+WKXkaUqugZGBfc3460MGFBaqA0DNqvj5lisXpRb3R7T xZIorW8/rojQGqNTQr4qogX5RTQo1I0FoUuHgLvDJ3BA+EAA33zgwlsXzkntXSC8 nU9CQUD/ =J3I4 -----END PGP SIGNATURE----- --=-=-=--