aboutsummaryrefslogtreecommitdiff
path: root/src/libstore
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2019-10-21 16:07:19 +0200
committerEelco Dolstra <edolstra@gmail.com>2019-10-21 16:07:19 +0200
commita7aabd7cc785bbf34ad29101672677ced18a7fdd (patch)
treee5635720323ddfe9d2070370c91c6f3e4d566dbb /src/libstore
parenta07da2fd7a889c225847556c0d4bf88384995274 (diff)
Add getDefaultProfile() function
Diffstat (limited to 'src/libstore')
-rw-r--r--src/libstore/profiles.cc18
-rw-r--r--src/libstore/profiles.hh4
2 files changed, 22 insertions, 0 deletions
diff --git a/src/libstore/profiles.cc b/src/libstore/profiles.cc
index 4c6af567a..29f6f6c17 100644
--- a/src/libstore/profiles.cc
+++ b/src/libstore/profiles.cc
@@ -256,4 +256,22 @@ string optimisticLockProfile(const Path & profile)
}
+Path getDefaultProfile()
+{
+ Path profileLink = getHome() + "/.nix-profile";
+ try {
+ if (!pathExists(profileLink)) {
+ replaceSymlink(
+ getuid() == 0
+ ? settings.nixStateDir + "/profiles/default"
+ : fmt("%s/profiles/per-user/%s/profile", settings.nixStateDir, getUserName()),
+ profileLink);
+ }
+ return absPath(readLink(profileLink), dirOf(profileLink));
+ } catch (Error &) {
+ return profileLink;
+ }
+}
+
+
}
diff --git a/src/libstore/profiles.hh b/src/libstore/profiles.hh
index 5fa1533de..78645d8b6 100644
--- a/src/libstore/profiles.hh
+++ b/src/libstore/profiles.hh
@@ -64,4 +64,8 @@ void lockProfile(PathLocks & lock, const Path & profile);
rebuilt. */
string optimisticLockProfile(const Path & profile);
+/* Resolve ~/.nix-profile. If ~/.nix-profile doesn't exist yet, create
+ it. */
+Path getDefaultProfile();
+
}