diff options
author | Naïm Favier <n@monade.li> | 2022-06-22 11:24:20 +0200 |
---|---|---|
committer | Naïm Favier <n@monade.li> | 2022-06-23 01:11:33 +0200 |
commit | 155c57c17131770a33dbd86055684d3605a0d505 (patch) | |
tree | 6d09cd69fc7056cdd3db5b7ce3847f8b458224ca /src | |
parent | 7e301fd74e929af916116a04d84e130f9e0112de (diff) |
nix develop: save XDG_DATA_DIRS for loadable completion
Diffstat (limited to 'src')
-rw-r--r-- | src/nix/develop.cc | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/nix/develop.cc b/src/nix/develop.cc index 2a3fc0213..6d9ad9942 100644 --- a/src/nix/develop.cc +++ b/src/nix/develop.cc @@ -276,15 +276,25 @@ struct Common : InstallableCommand, MixProfile const BuildEnvironment & buildEnvironment, const Path & outputsDir = absPath(".") + "/outputs") { + // A list of colon-separated environment variables that should be + // prepended to, rather than overwritten, in order to keep the shell usable. + // Please keep this list minimal in order to avoid impurities. + static const char * const savedVars[] = { + "PATH", // for commands + "XDG_DATA_DIRS", // for loadable completion + }; + std::ostringstream out; out << "unset shellHook\n"; - out << "nix_saved_PATH=\"$PATH\"\n"; + for (auto & var : savedVars) + out << fmt("nix_saved_%s=\"$%s\"\n", var, var); buildEnvironment.toBash(out, ignoreVars); - out << "PATH=\"$PATH:$nix_saved_PATH\"\n"; + for (auto & var : savedVars) + out << fmt("%s=\"$%s:$nix_saved_%s\"\n", var, var, var); out << "export NIX_BUILD_TOP=\"$(mktemp -d -t nix-shell.XXXXXX)\"\n"; for (auto & i : {"TMP", "TMPDIR", "TEMP", "TEMPDIR"}) |