about summary refs log tree commit diff
path: root/src/nix-env/nix-env.cc
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2019-10-10T07·14+0200
committerEelco Dolstra <edolstra@gmail.com>2019-10-10T07·42+0200
commit21f48ff26afab05febbc08c0c14617fc47b74d6d (patch)
tree96535cc8d503d306bc33a8a97e1fa528b7a5d3c9 /src/nix-env/nix-env.cc
parente3d44a3b83e85eefbb7cbfbd21dc46ef7efa3f2e (diff)
nix-env: Ignore failures creating ~/.nix-profile and ~/.nix-defexpr
https://hydra.nixos.org/build/102803093
(cherry picked from commit c3aaf3b8da1a925c569389f13a861816a781a3c8)
Diffstat (limited to 'src/nix-env/nix-env.cc')
-rw-r--r--src/nix-env/nix-env.cc34
1 files changed, 20 insertions, 14 deletions
diff --git a/src/nix-env/nix-env.cc b/src/nix-env/nix-env.cc
index ec7ed504b8ed..3292f546ab42 100644
--- a/src/nix-env/nix-env.cc
+++ b/src/nix-env/nix-env.cc
@@ -1328,14 +1328,16 @@ static int _main(int argc, char * * argv)
         globals.instSource.systemFilter = "*";
 
         if (!pathExists(globals.instSource.nixExprPath)) {
-            createDirs(globals.instSource.nixExprPath);
-            replaceSymlink(
-                fmt("%s/profiles/per-user/%s/channels", settings.nixStateDir, getUserName()),
-                globals.instSource.nixExprPath + "/channels");
-            if (getuid() != 0)
+            try {
+                createDirs(globals.instSource.nixExprPath);
                 replaceSymlink(
-                    fmt("%s/profiles/per-user/root/channels", settings.nixStateDir),
-                    globals.instSource.nixExprPath + "/channels_root");
+                    fmt("%s/profiles/per-user/%s/channels", settings.nixStateDir, getUserName()),
+                    globals.instSource.nixExprPath + "/channels");
+                if (getuid() != 0)
+                    replaceSymlink(
+                        fmt("%s/profiles/per-user/root/channels", settings.nixStateDir),
+                        globals.instSource.nixExprPath + "/channels_root");
+            } catch (Error &) { }
         }
 
         globals.dryRun = false;
@@ -1430,14 +1432,18 @@ static int _main(int argc, char * * argv)
 
         if (globals.profile == "") {
             Path profileLink = getHome() + "/.nix-profile";
-            if (!pathExists(profileLink)) {
-                replaceSymlink(
-                    getuid() == 0
-                    ? settings.nixStateDir + "/profiles/default"
-                    : fmt("%s/profiles/per-user/%s/profile", settings.nixStateDir, getUserName()),
-                    profileLink);
+            try {
+                if (!pathExists(profileLink)) {
+                    replaceSymlink(
+                        getuid() == 0
+                        ? settings.nixStateDir + "/profiles/default"
+                        : fmt("%s/profiles/per-user/%s/profile", settings.nixStateDir, getUserName()),
+                        profileLink);
+                }
+                globals.profile = absPath(readLink(profileLink), dirOf(profileLink));
+            } catch (Error &) {
+                globals.profile = profileLink;
             }
-            globals.profile = absPath(readLink(profileLink), dirOf(profileLink));
         }
 
         op(globals, opFlags, opArgs);