diff mbox series

[bug#56618,1/2] home: Add 'home-generation-base'.

Message ID 20220717152117.23452-1-ludo@gnu.org
State Accepted
Headers show
Series Let 'guix gc -d' delete old Home generations | expand

Checks

Context Check Description
cbaines/applying patch fail View Laminar job
cbaines/issue success View issue

Commit Message

Ludovic Courtès July 17, 2022, 3:21 p.m. UTC
* gnu/home.scm (%profile-generation-rx): New variable.
(home-generation-base): New procedure.
---
 gnu/home.scm | 26 ++++++++++++++++++++++++--
 1 file changed, 24 insertions(+), 2 deletions(-)

Comments

Andrew Tropin July 18, 2022, 12:51 p.m. UTC | #1
On 2022-07-17 17:21, Ludovic Courtès wrote:

> * 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 <andrew@trop.in>
> +;;; Copyright © 2022 Ludovic Courtès <ludo@gnu.org>
>  ;;;
>  ;;; 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 <home-environment>)
>        (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)))

Is home environment and operating system a profile itself?  They reside
in /var/guix/profile, but they have profile/ directory inside, so do
they profiles themselves?  I don't propose any changes, just asking.

> +          ;; 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)))))
Ludovic Courtès July 19, 2022, 8:01 a.m. UTC | #2
Hi,

Andrew Tropin <andrew@trop.in> skribis:

> Is home environment and operating system a profile itself?  They reside
> in /var/guix/profile, but they have profile/ directory inside, so do
> they profiles themselves?

No, they’re not profiles (they contain a profile), so they need to be
treated specially for the purposes of ‘guix gc -d’.

Ludo’.
diff mbox series

Patch

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 <andrew@trop.in>
+;;; Copyright © 2022 Ludovic Courtès <ludo@gnu.org>
 ;;;
 ;;; 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 <home-environment>)
       (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)))))