guix: home: Ensure symlink is properly created. Ensure the $HOME symlink to the profile is created at the right time, after the profile is built. When creating the symlink if it does not exist yet, allow overriding an existing symlink and error out only when $HOME is a directory and the data directory already exist. * guix/scripts/home.scm (ensure-home-profile): Allow overriding existing symlink. (perform-action): Ensure home profile only after the derivation is built.
guix/scripts/home.scm
162 | 162 | ||
163 | 163 | (when %home %current-home | |
164 | 164 | (let ((home (false-if-exception (lstat %home)))) | |
165 | - | (if home | |
166 | - | (unless (equal? (readlink %home) %current-home) | |
167 | - | (if (false-if-exception (lstat data-directory)) | |
168 | - | (leave (G_ "Your $HOME directory (~a) is not a symlink to the home profile, | |
169 | - | and it cannot be moved as ~a already exists on the filesystem.~%") | |
170 | - | %home data-directory) | |
171 | - | (rename-file %home data-directory))) | |
172 | - | (symlink %current-home %home))))) | |
165 | + | (cond | |
166 | + | ((equal? (stat:type home) 'symlink) | |
167 | + | (symlink %current-home %home)) | |
168 | + | ((false-if-exception (lstat data-directory)) | |
169 | + | (leave (G_ "Your $HOME directory (~a) is not a symlink to the home | |
170 | + | profile, and it cannot be moved as ~a already exists on the filesystem.~%") | |
171 | + | %home data-directory)) | |
172 | + | ((not home) | |
173 | + | (symlink %current-home %home)) | |
174 | + | (else | |
175 | + | (rename-file %home data-directory) | |
176 | + | (symlink %current-home %home)))))) | |
173 | 177 | ||
174 | 178 | (define (list-generations pattern) | |
175 | 179 | "Display in a human-readable format all the home generations matching | |
… | |||
201 | 205 | (define println | |
202 | 206 | (cut format #t "~a~%" <>)) | |
203 | 207 | ||
204 | - | (when (eq? action 'reconfigure) | |
205 | - | (ensure-home-profile (home-data-directory home))) | |
206 | - | ||
207 | 208 | (with-store store | |
208 | 209 | (let* ((drv (run-with-store store (home->derivation home))) | |
209 | 210 | (profile (derivation->output-path drv))) | |
… | |||
218 | 219 | ((reconfigure) | |
219 | 220 | (newline) | |
220 | 221 | (format #t (G_ "Activating home...~%")) | |
222 | + | (ensure-home-profile (home-data-directory home)) | |
221 | 223 | (let* ((number (generation-number %current-home)) | |
222 | 224 | (generation (generation-file-name %current-home (+ 1 number)))) | |
223 | 225 | (switch-symlinks generation profile) |