Commit | Line | Data |
---|---|---|
3db349cb AK |
1 | ;;; guix-profiles.el --- Guix profiles |
2 | ||
a0ad8ab0 AK |
3 | ;; Copyright © 2014, 2015, 2016 Alex Kost <alezost@gmail.com> |
4 | ;; Copyright © 2015 Mathieu Lirzin <mthl@openmailbox.org> | |
3db349cb AK |
5 | |
6 | ;; This file is part of GNU Guix. | |
7 | ||
8 | ;; GNU Guix is free software; you can redistribute it and/or modify | |
9 | ;; it under the terms of the GNU General Public License as published by | |
10 | ;; the Free Software Foundation, either version 3 of the License, or | |
11 | ;; (at your option) any later version. | |
12 | ||
13 | ;; GNU Guix is distributed in the hope that it will be useful, | |
14 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | ;; GNU General Public License for more details. | |
17 | ||
18 | ;; You should have received a copy of the GNU General Public License | |
19 | ;; along with this program. If not, see <http://www.gnu.org/licenses/>. | |
20 | ||
21 | ;;; Code: | |
22 | ||
bd6163d1 ML |
23 | (require 'guix-config) |
24 | ||
3db349cb AK |
25 | (defvar guix-user-profile |
26 | (expand-file-name "~/.guix-profile") | |
27 | "User profile.") | |
28 | ||
a0ad8ab0 AK |
29 | (defvar guix-system-profile |
30 | (concat guix-config-state-directory "/profiles/system") | |
31 | "System profile.") | |
32 | ||
3db349cb | 33 | (defvar guix-default-profile |
38056615 | 34 | (concat guix-config-state-directory |
3db349cb AK |
35 | "/profiles/per-user/" |
36 | (getenv "USER") | |
37 | "/guix-profile") | |
38 | "Default Guix profile.") | |
39 | ||
40 | (defvar guix-current-profile guix-default-profile | |
41 | "Current profile.") | |
42 | ||
260795b7 AK |
43 | (defvar guix-system-profile-regexp |
44 | (concat "\\`" (regexp-quote guix-system-profile)) | |
45 | "Regexp matching system profiles.") | |
46 | ||
47 | (defun guix-system-profile? (profile) | |
48 | "Return non-nil, if PROFILE is a system one." | |
49 | (string-match-p guix-system-profile-regexp profile)) | |
50 | ||
3db349cb AK |
51 | (defun guix-profile-prompt (&optional default) |
52 | "Prompt for profile and return it. | |
53 | Use DEFAULT as a start directory. If it is nil, use | |
54 | `guix-current-profile'." | |
55 | (let* ((path (read-file-name "Profile: " | |
56 | (file-name-directory | |
57 | (or default guix-current-profile)))) | |
58 | (path (directory-file-name (expand-file-name path)))) | |
59 | (if (string= path guix-user-profile) | |
60 | guix-default-profile | |
61 | path))) | |
62 | ||
63 | (defun guix-set-current-profile (path) | |
64 | "Set `guix-current-profile' to PATH. | |
65 | Interactively, prompt for PATH. With prefix, use | |
66 | `guix-default-profile'." | |
67 | (interactive | |
68 | (list (if current-prefix-arg | |
69 | guix-default-profile | |
70 | (guix-profile-prompt)))) | |
71 | (setq guix-current-profile path) | |
72 | (message "Current profile has been set to '%s'." | |
73 | guix-current-profile)) | |
74 | ||
75 | (provide 'guix-profiles) | |
76 | ||
77 | ;;; guix-profiles.el ends here |