Skip to content

Commit 0fb4744

Browse files
committed
nix-env: Create ~/.nix-defexpr automatically
(cherry picked from commit c9159f8)
1 parent f66108f commit 0fb4744

File tree

3 files changed

+12
-30
lines changed

3 files changed

+12
-30
lines changed

scripts/nix-profile-daemon.sh.in

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,6 @@ __ETC_PROFILE_NIX_SOURCED=1
55
export NIX_USER_PROFILE_DIR="@localstatedir@/nix/profiles/per-user/$USER"
66
export NIX_PROFILES="@localstatedir@/nix/profiles/default $HOME/.nix-profile"
77

8-
if test -w $HOME; then
9-
# Set up a default Nix expression from which to install stuff.
10-
if [ ! -e $HOME/.nix-defexpr -o -L $HOME/.nix-defexpr ]; then
11-
rm -f $HOME/.nix-defexpr
12-
mkdir -p $HOME/.nix-defexpr
13-
if [ "$USER" != root ]; then
14-
ln -s @localstatedir@/nix/profiles/per-user/root/channels $HOME/.nix-defexpr/channels_root
15-
fi
16-
fi
17-
fi
18-
19-
208
# Set $NIX_SSL_CERT_FILE so that Nixpkgs applications like curl work.
219
if [ ! -z "${NIX_SSL_CERT_FILE:-}" ]; then
2210
: # Allow users to override the NIX_SSL_CERT_FILE

scripts/nix-profile.sh.in

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,6 @@ if [ -n "$HOME" ] && [ -n "$USER" ]; then
77

88
NIX_USER_PROFILE_DIR=@localstatedir@/nix/profiles/per-user/$USER
99

10-
if [ -w "$HOME" ]; then
11-
# Set up a default Nix expression from which to install stuff.
12-
__nix_defexpr="$HOME"/.nix-defexpr
13-
[ -L "$__nix_defexpr" ] && rm -f "$__nix_defexpr"
14-
mkdir -m 0755 -p "$__nix_defexpr"
15-
if [ "$USER" != root ] && [ ! -L "$__nix_defexpr"/channels_root ]; then
16-
ln -s @localstatedir@/nix/profiles/per-user/root/channels "$__nix_defexpr"/channels_root
17-
fi
18-
unset __nix_defexpr
19-
fi
20-
2110
# Append ~/.nix-defexpr/channels to $NIX_PATH so that <nixpkgs>
2211
# paths work when the user has fetched the Nixpkgs channel.
2312
export NIX_PATH=${NIX_PATH:+$NIX_PATH:}$HOME/.nix-defexpr/channels

src/nix-env/nix-env.cc

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -193,12 +193,6 @@ static void loadDerivations(EvalState & state, Path nixExprPath,
193193
}
194194

195195

196-
static Path getDefNixExprPath()
197-
{
198-
return getHome() + "/.nix-defexpr";
199-
}
200-
201-
202196
static long getPriority(EvalState & state, DrvInfo & drv)
203197
{
204198
return drv.queryMetaInt("priority", 0);
@@ -1330,9 +1324,20 @@ static int _main(int argc, char * * argv)
13301324
Globals globals;
13311325

13321326
globals.instSource.type = srcUnknown;
1333-
globals.instSource.nixExprPath = getDefNixExprPath();
1327+
globals.instSource.nixExprPath = getHome() + "/.nix-defexpr";
13341328
globals.instSource.systemFilter = "*";
13351329

1330+
if (!pathExists(globals.instSource.nixExprPath)) {
1331+
createDirs(globals.instSource.nixExprPath);
1332+
replaceSymlink(
1333+
fmt("%s/profiles/per-user/%s/channels", settings.nixStateDir, getUserName()),
1334+
globals.instSource.nixExprPath + "/channels");
1335+
if (getuid() != 0)
1336+
replaceSymlink(
1337+
fmt("%s/profiles/per-user/root/channels", settings.nixStateDir),
1338+
globals.instSource.nixExprPath + "/channels_root");
1339+
}
1340+
13361341
globals.dryRun = false;
13371342
globals.preserveInstalled = false;
13381343
globals.removeAll = false;

0 commit comments

Comments
 (0)