From 61db74a687e36e842077c5c2f4b2e2c7afcd814a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludovic=20Court=C3=A8s?= Date: Sun, 31 Jul 2022 23:00:53 +0200 Subject: [PATCH] home: Add 'home-generation-base'. This reverts commit 670818a4049edb8a77a5b596fbc7558bde57165c, thereby reinstating 5df8f7802e8b45855e8f84830677001dc631e4f7. * 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)))))