about summary refs log tree commit diff
path: root/src/nix-env
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2019-10-09T17·50+0200
committerEelco Dolstra <edolstra@gmail.com>2019-10-09T22·00+0200
commit0fb4744467b08e4ea50a39716d697764bea229d4 (patch)
tree49a199f227a6cb14d95959aea1395be711d25929 /src/nix-env
parentf66108f738b43bf822b06d7ab62c0b7129fb454c (diff)
nix-env: Create ~/.nix-defexpr automatically
(cherry picked from commit c9159f86cc9a2fc07e2ab1217c2d8a8824123df4)
Diffstat (limited to 'src/nix-env')
-rw-r--r--src/nix-env/nix-env.cc19
1 files changed, 12 insertions, 7 deletions
diff --git a/src/nix-env/nix-env.cc b/src/nix-env/nix-env.cc
index c7b6bdaafbc2..ec7ed504b8ed 100644
--- a/src/nix-env/nix-env.cc
+++ b/src/nix-env/nix-env.cc
@@ -193,12 +193,6 @@ static void loadDerivations(EvalState & state, Path nixExprPath,
 }
 
 
-static Path getDefNixExprPath()
-{
-    return getHome() + "/.nix-defexpr";
-}
-
-
 static long getPriority(EvalState & state, DrvInfo & drv)
 {
     return drv.queryMetaInt("priority", 0);
@@ -1330,9 +1324,20 @@ static int _main(int argc, char * * argv)
         Globals globals;
 
         globals.instSource.type = srcUnknown;
-        globals.instSource.nixExprPath = getDefNixExprPath();
+        globals.instSource.nixExprPath = getHome() + "/.nix-defexpr";
         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)
+                replaceSymlink(
+                    fmt("%s/profiles/per-user/root/channels", settings.nixStateDir),
+                    globals.instSource.nixExprPath + "/channels_root");
+        }
+
         globals.dryRun = false;
         globals.preserveInstalled = false;
         globals.removeAll = false;