aboutsummaryrefslogtreecommitdiff
path: root/src/libexpr
diff options
context:
space:
mode:
authorJohn Ericson <John.Ericson@Obsidian.Systems>2023-07-24 14:02:05 -0400
committerJohn Ericson <John.Ericson@Obsidian.Systems>2023-08-02 12:54:48 -0400
commit9b908fa70a07219a110ddd63ec3593c2c2269918 (patch)
tree484f4a4fb02229f0ce79ba40cfd7945fad1e7896 /src/libexpr
parentd00469ebf94dba4ae30120c1ba36085ac20443b8 (diff)
Factor out `nix-defexpr` path computation
Avoid duplicated code, and also avoid "on the fly" path construction (which makes it harder to keep track of which paths we use). The factored out code doesn't create the Nix state dir anymore, but this is fine because other in nix-env and nix-channel does: - nix-channel: Line 158 in this commit - nix-env: Line 1407 in this commit
Diffstat (limited to 'src/libexpr')
-rw-r--r--src/libexpr/eval-settings.cc9
-rw-r--r--src/libexpr/eval-settings.hh5
2 files changed, 13 insertions, 1 deletions
diff --git a/src/libexpr/eval-settings.cc b/src/libexpr/eval-settings.cc
index 422aaf8d5..93b4a5289 100644
--- a/src/libexpr/eval-settings.cc
+++ b/src/libexpr/eval-settings.cc
@@ -63,7 +63,7 @@ Strings EvalSettings::getDefaultNixPath()
};
if (!evalSettings.restrictEval && !evalSettings.pureEval) {
- add(settings.useXDGBaseDirectories ? getStateDir() + "/nix/defexpr/channels" : getHome() + "/.nix-defexpr/channels");
+ add(getNixDefExpr() + "/channels");
add(rootChannelsDir() + "/nixpkgs", "nixpkgs");
add(rootChannelsDir());
}
@@ -92,4 +92,11 @@ EvalSettings evalSettings;
static GlobalConfig::Register rEvalSettings(&evalSettings);
+Path getNixDefExpr()
+{
+ return settings.useXDGBaseDirectories
+ ? getStateDir() + "/nix/defexpr"
+ : getHome() + "/.nix-defexpr";
+}
+
}
diff --git a/src/libexpr/eval-settings.hh b/src/libexpr/eval-settings.hh
index 043af6cab..e6666061a 100644
--- a/src/libexpr/eval-settings.hh
+++ b/src/libexpr/eval-settings.hh
@@ -95,4 +95,9 @@ struct EvalSettings : Config
extern EvalSettings evalSettings;
+/**
+ * Conventionally part of the default nix path in impure mode.
+ */
+Path getNixDefExpr();
+
}