From patchwork Sun Jul 17 15:21:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ludovic_Court=C3=A8s?= X-Patchwork-Id: 40719 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 1850527BBEA; Sun, 17 Jul 2022 16:22:12 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,SPF_HELO_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id CB1CA27BBE9 for ; Sun, 17 Jul 2022 16:22:11 +0100 (BST) Received: from localhost ([::1]:53484 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oD65z-0006Oq-0R for patchwork@mira.cbaines.net; Sun, 17 Jul 2022 11:22:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50598) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oD65r-0006Ob-4f for guix-patches@gnu.org; Sun, 17 Jul 2022 11:22:03 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:50583) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oD65q-0002SK-P3 for guix-patches@gnu.org; Sun, 17 Jul 2022 11:22:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oD65q-0004XX-Kv for guix-patches@gnu.org; Sun, 17 Jul 2022 11:22:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#56618] [PATCH 1/2] home: Add 'home-generation-base'. References: <20220717151930.23383-1-ludo@gnu.org> In-Reply-To: <20220717151930.23383-1-ludo@gnu.org> Resent-From: Ludovic =?utf-8?q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sun, 17 Jul 2022 15:22:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 56618 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 56618@debbugs.gnu.org Cc: Ludovic =?utf-8?q?Court=C3=A8s?= Received: via spool by 56618-submit@debbugs.gnu.org id=B56618.165807129517394 (code B ref 56618); Sun, 17 Jul 2022 15:22:02 +0000 Received: (at 56618) by debbugs.gnu.org; 17 Jul 2022 15:21:35 +0000 Received: from localhost ([127.0.0.1]:48339 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oD65P-0004WU-0X for submit@debbugs.gnu.org; Sun, 17 Jul 2022 11:21:35 -0400 Received: from eggs.gnu.org ([209.51.188.92]:37618) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oD65K-0004W3-6b for 56618@debbugs.gnu.org; Sun, 17 Jul 2022 11:21:32 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:47290) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oD65F-0002Os-0e; Sun, 17 Jul 2022 11:21:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:Date:Subject:To:From:in-reply-to: references; bh=gtUPtd+LlNFmIcF70LQhtSEUq6aZFfCvH3vVXB9Yo7M=; b=aw9cv2pvXMpnec vFOM6QXtlGZxyfCiD9BSZjBrSolJzpblhqYN5ei3nzz5rbEdAUAl2snSFe9+kN4HXsSlyQAFcQz0z S2HSNG+TgnTpgrQein+V76KBDrcKSrid2agxiWvm9hRho3F5nRJsFzawDzXWtmpb33Z1SZSSQUAtZ 4qWfSWHUX+n2fZMSXlROjQ32QDSaWM4r7ByTPXIsLse2jkbXf6fq92EwAVNtgsMsjKccphdbi1C8g 3xzNBfRHwq3KKBTPCKybh/uyfQUpBYKp7OQkCRYRVLZG1hcam1Y4aUgm0My8cQqQLF0gy64NDi1P3 J5hybL2Hlp21PcP/JxWw==; Received: from 91-160-117-201.subs.proxad.net ([91.160.117.201]:56420 helo=gnu.org) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oD65E-0001jK-Hv; Sun, 17 Jul 2022 11:21:24 -0400 From: Ludovic =?utf-8?q?Court=C3=A8s?= Date: Sun, 17 Jul 2022 17:21:16 +0200 Message-Id: <20220717152117.23452-1-ludo@gnu.org> X-Mailer: git-send-email 2.36.1 MIME-Version: 1.0 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.scm (%profile-generation-rx): New variable. (home-generation-base): New procedure. --- gnu/home.scm | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/gnu/home.scm b/gnu/home.scm index a9f0a469a5..4ddbafe412 100644 --- a/gnu/home.scm +++ b/gnu/home.scm @@ -1,5 +1,6 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2021 Andrew Tropin +;;; Copyright © 2022 Ludovic Courtès ;;; ;;; This file is part of GNU Guix. ;;; @@ -27,7 +28,8 @@ (define-module (gnu home) #:use-module (guix diagnostics) #:use-module (guix gexp) #:use-module (guix store) - + #:use-module (ice-9 match) + #:use-module (ice-9 regex) #:export (home-environment home-environment? this-home-environment @@ -38,7 +40,9 @@ (define-module (gnu home) home-environment-services home-environment-location - home-environment-with-provenance)) + home-environment-with-provenance + + home-generation-base)) ;;; Comment: ;;; @@ -114,3 +118,21 @@ (define-gexp-compiler (home-environment-compiler (he ) (run-with-store store (home-environment-derivation he) #:system system #:target target))))) + +(define %profile-generation-rx + ;; Regexp that matches profile generation. + (make-regexp "(.*)-([0-9]+)-link$")) + +(define (home-generation-base file) + "If FILE is a Home generation GC root such as \"guix-home-42-link\", +return its corresponding base---e.g., \"guix-home\". Otherwise return #f. + +This is similar to the 'generation-profile' procedure but applied to Home +generations." + (match (regexp-exec %profile-generation-rx file) + (#f #f) + (m (let ((profile (match:substring m 1))) + ;; Distinguish from a "real" profile and from a system generation. + (and (file-exists? (string-append profile "/on-first-login")) + (file-exists? (string-append profile "/profile/manifest")) + profile)))))