guix-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug#32998] [PATCH 2/2] pull: Turn ~/.config/guix/current into a symlink


From: Ludovic Courtès
Subject: [bug#32998] [PATCH 2/2] pull: Turn ~/.config/guix/current into a symlink to /var/guix/profiles.
Date: Tue, 9 Oct 2018 12:16:25 +0200

This is more consistent with what 'guix package' does, more pleasant for
users (we no longer clobber ~/.config/guix), and more
cluster-friendly (since /var/guix/profiles is usually an NFS share
already.)

* guix/scripts/pull.scm (%current-profile, %user-profile-directory): New
variables.
(migrate-generations, ensure-default-profile): New procedures.
(guix-pull): Use %CURRENT-PROFILE by default.  Call
'ensure-default-profile'.
* doc/guix.texi (Invoking guix pull): Adjust 'guix package -p
~/.config/guix/current' example.
---
 doc/guix.texi         |  2 +-
 guix/scripts/pull.scm | 65 +++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 63 insertions(+), 4 deletions(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index 3c116fc0b..c6e474955 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -2831,7 +2831,7 @@ generation---i.e., the previous Guix---and so on:
 $ guix package -p ~/.config/guix/current --roll-back
 switched from generation 3 to 2
 $ guix package -p ~/.config/guix/current --delete-generations=1
-deleting /home/charlie/.config/guix/current-1-link
+deleting /var/guix/profiles/per-user/charlie/current-guix-1-link
 @end example
 
 The @command{guix pull} command is usually invoked with no arguments,
diff --git a/guix/scripts/pull.scm b/guix/scripts/pull.scm
index 0d65857be..042b493ae 100644
--- a/guix/scripts/pull.scm
+++ b/guix/scripts/pull.scm
@@ -226,6 +226,66 @@ Download and deploy the latest version of Guix.\n"))
       (report-git-error err))))
 
 
+;;;
+;;; Profile.
+;;;
+
+(define %current-profile
+  ;; The "real" profile under /var/guix.
+  (string-append %profile-directory "/current-guix"))
+
+(define %user-profile-directory
+  ;; The user-friendly name of %CURRENT-PROFILE.
+  (string-append (config-directory #:ensure? #f) "/current"))
+
+(define (migrate-generations profile directory)
+  "Migration the generations of PROFILE to DIRECTORY."
+  (format (current-error-port)
+          (G_ "Migrating profile generations to '~a'...~%")
+          %profile-directory)
+  (for-each (lambda (generation)
+              (let ((source (generation-file-name profile generation))
+                    (target (string-append directory "/current-guix-"
+                                           (number->string generation)
+                                           "-link")))
+                (rename-file source target)))
+            (profile-generations profile)))
+
+(define (ensure-default-profile)
+  (catch 'system-error
+    (lambda ()
+      ;; Note: The /per-user directory, parent of %PROFILE-DIRECTORY, is
+      ;; created by the daemon.  Assume it already exists.
+      (mkdir %profile-directory))
+    (lambda args
+      (unless (= EEXIST (system-error-errno args))
+        (format (current-error-port)
+                (G_ "error: while creating directory `~a': ~a~%")
+                %profile-directory
+                (strerror (system-error-errno args)))
+        (format (current-error-port)
+                (G_ "Please create the `~a' directory, with you as the 
owner.~%")
+                %profile-directory))))
+
+  ;; In 0.15.0+ we'd create ~/.config/guix/current-[0-9]*-link symlinks.  Move
+  ;; them to %PROFILE-DIRECTORY.
+  (unless (string=? %profile-directory
+                    (dirname (canonicalize-profile %user-profile-directory)))
+    (migrate-generations %user-profile-directory %profile-directory))
+
+  ;; Recreate ~/.config/guix/current.  Recreating it is a way to have an
+  ;; up-to-date mtime on the link, which we can then use to determine the time
+  ;; of the last update (XXX: we could do better...).
+  (let ((link %user-profile-directory))
+    (false-if-exception (delete-file link))
+    (catch 'system-error
+      (lambda ()
+        (symlink %current-profile link))
+      (lambda args
+        (leave (G_ "while creating symlink '~a': ~a~%")
+               link (strerror (system-error-errno args)))))))
+
+
 ;;;
 ;;; Queries.
 ;;;
@@ -438,9 +498,8 @@ Use '~/.config/guix/channels.scm' instead."))
                                           (list %default-options)))
             (cache    (string-append (cache-directory) "/pull"))
             (channels (channel-list opts))
-            (profile  (or (assoc-ref opts 'profile)
-                          (string-append (config-directory) "/current"))))
-
+            (profile  (or (assoc-ref opts 'profile) %current-profile)))
+       (ensure-default-profile)
        (cond ((assoc-ref opts 'query)
               (process-query opts profile))
              ((assoc-ref opts 'dry-run?)
-- 
2.19.0






reply via email to

[Prev in Thread] Current Thread [Next in Thread]