-
-
Notifications
You must be signed in to change notification settings - Fork 14.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support XDG-conformant paths for internal Nix files #146515
base: staging
Are you sure you want to change the base?
Conversation
Ref: NixOS/nix#5588 This searches in $XDG_DATA_HOME/nix/profile everywhere where previously we only looked in ~/.nix-profile. This shouldn't break any compatibility for now. It is highly recommended to use nixpkgs with these changes if you want to use Nix with the XDG basedir PR, but not doing so shouldn't result in any dramatic breakage -- in fact, NixOS is perfectly usable without any user profile.
NIX_DEFEXPR="$HOME/.nix-defexpr" | ||
if ! [ -e "$NIX_DEFEXPR" ]; then | ||
if [ -n "$XDG_DATA_HOME" ]; then | ||
NIX_DEFEXPR="$XDG_DATA_HOME/nix/defexpr" | ||
else | ||
NIX_DEFEXPR="$HOME/.local/share/nix/defexpr" | ||
fi | ||
fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic like this could be useful for setting the nix-profile so users could just use that env var in their scripts instead of having to accommodate 3 possible separate locations
NIX_USER_PROFILE_PATH
perhaps?
on second thought that'll be nixos only but we'll want that on non nixos distros too so can nix somehow do it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nix has a setup script that has to be sourced in order to bring nix into the PATH, with the proper ssl certs for packages to use. So that would be a good place to define the variable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would require an update to be simultaneous in both Nix and nixpkgs, which is a lot more difficult to orchestrate correctly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM #zhfmsk
6e36b00
to
2ff1ea6
Compare
This needs to go to staging. I don't think we should squeeze in such a change last minute. There are probably more packages which need some adjustment and having that change a few months in unstable will probably reveal most of them. Especially DEs which heavily rely on XDG* shoulnd't break. |
@@ -717,7 +717,7 @@ If set to `true`, the standard environment will enable debug information in C/C+ | |||
For example, with GDB, you can add | |||
|
|||
``` | |||
set debug-file-directory ~/.nix-profile/lib/debug | |||
set debug-file-directory ~/.local/share/nix/profile/lib/debug |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
set debug-file-directory ~/.local/share/nix/profile/lib/debug | |
set debug-file-directory ~/.local/state/nix/profile/lib/debug |
@@ -204,7 +204,7 @@ Using `packageOverrides`, it is possible to manage packages declaratively. This | |||
} | |||
``` | |||
|
|||
To install it into our environment, you can just run `nix-env -iA nixpkgs.myPackages`. If you want to load the packages to be built from a working copy of `nixpkgs` you just run `nix-env -f. -iA myPackages`. To explore what's been installed, just look through `~/.nix-profile/`. You can see that a lot of stuff has been installed. Some of this stuff is useful some of it isn't. Let's tell Nixpkgs to only link the stuff that we want: | |||
To install it into our environment, you can just run `nix-env -iA nixpkgs.myPackages`. If you want to load the packages to be built from a working copy of `nixpkgs` you just run `nix-env -f. -iA myPackages`. To explore what's been installed, just look through your user profile (`$XDG_DATA_HOME/nix/profile`, or a legacy location `~/.nix-profile/`). You can see that a lot of stuff has been installed. Some of this stuff is useful some of it isn't. Let's tell Nixpkgs to only link the stuff that we want: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To install it into our environment, you can just run `nix-env -iA nixpkgs.myPackages`. If you want to load the packages to be built from a working copy of `nixpkgs` you just run `nix-env -f. -iA myPackages`. To explore what's been installed, just look through your user profile (`$XDG_DATA_HOME/nix/profile`, or a legacy location `~/.nix-profile/`). You can see that a lot of stuff has been installed. Some of this stuff is useful some of it isn't. Let's tell Nixpkgs to only link the stuff that we want: | |
To install it into our environment, you can just run `nix-env -iA nixpkgs.myPackages`. If you want to load the packages to be built from a working copy of `nixpkgs` you just run `nix-env -f. -iA myPackages`. To explore what's been installed, just look through your user profile (`$XDG_STATE_HOME/nix/profile`, or a legacy location `~/.nix-profile/`). You can see that a lot of stuff has been installed. Some of this stuff is useful some of it isn't. Let's tell Nixpkgs to only link the stuff that we want: |
@@ -233,7 +233,7 @@ To install it into our environment, you can just run `nix-env -iA nixpkgs.myPack | |||
|
|||
### Getting documentation {#sec-getting-documentation} | |||
|
|||
After building that new environment, look through `~/.nix-profile` to make sure everything is there that we wanted. Discerning readers will note that some files are missing. Look inside `~/.nix-profile/share/man/man1/` to verify this. There are no man pages for any of the Nix tools! This is because some packages like Nix have multiple outputs for things like documentation (see section 4). Let's make Nix install those as well. | |||
After building that new environment, look through `$XDG_DATA_HOME/nix/profile` (or, as noted above, `~/.nix-profile`) to make sure everything is there that we wanted. Discerning readers will note that some files are missing. Look inside `$XDG_DATA_HOME/nix/profile/share/man/man1/` to verify this. There are no man pages for any of the Nix tools! This is because some packages like Nix have multiple outputs for things like documentation (see section 4). Let's make Nix install those as well. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After building that new environment, look through `$XDG_DATA_HOME/nix/profile` (or, as noted above, `~/.nix-profile`) to make sure everything is there that we wanted. Discerning readers will note that some files are missing. Look inside `$XDG_DATA_HOME/nix/profile/share/man/man1/` to verify this. There are no man pages for any of the Nix tools! This is because some packages like Nix have multiple outputs for things like documentation (see section 4). Let's make Nix install those as well. | |
After building that new environment, look through `$XDG_STATE_HOME/nix/profile` (or, as noted above, `~/.nix-profile`) to make sure everything is there that we wanted. Discerning readers will note that some files are missing. Look inside `$XDG_STATE_HOME/nix/profile/share/man/man1/` to verify this. There are no man pages for any of the Nix tools! This is because some packages like Nix have multiple outputs for things like documentation (see section 4). Let's make Nix install those as well. |
XDG_DATA_HOME=${XDG_DATA_HOME:-$HOME/.local/share} | ||
export PATH=$XDG_DATA_HOME/nix/profile/bin:/nix/var/nix/profiles/default/bin:/sbin:/bin:/usr/sbin:/usr/bin | ||
export MANPATH=$XDG_DATA_HOME/nix/profile/share/man:/nix/var/nix/profiles/default/share/man:/usr/share/man |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
XDG_DATA_HOME=${XDG_DATA_HOME:-$HOME/.local/share} | |
export PATH=$XDG_DATA_HOME/nix/profile/bin:/nix/var/nix/profiles/default/bin:/sbin:/bin:/usr/sbin:/usr/bin | |
export MANPATH=$XDG_DATA_HOME/nix/profile/share/man:/nix/var/nix/profiles/default/share/man:/usr/share/man | |
XDG_DATA_HOME=${XDG_STATE_HOME:-$HOME/.local/share} | |
export PATH=$XDG_STATE_HOME/nix/profile/bin:/nix/var/nix/profiles/default/bin:/sbin:/bin:/usr/sbin:/usr/bin | |
export MANPATH=$XDG_STATE_HOME/nix/profile/share/man:/nix/var/nix/profiles/default/share/man:/usr/share/man |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't it be XDG_STATE_HOME=${XDG_STATE_HOME:-$HOME/.local/state}
?
XDG_DATA_HOME=${XDG_DATA_HOME:-$HOME/.local/share} | ||
if [ -d $XDG_DATA_HOME/nix/profile/etc/profile.d ]; then | ||
for i in $XDG_DATA_HOME/nix/profile/etc/profile.d/*.sh; do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
XDG_DATA_HOME=${XDG_DATA_HOME:-$HOME/.local/share} | |
if [ -d $XDG_DATA_HOME/nix/profile/etc/profile.d ]; then | |
for i in $XDG_DATA_HOME/nix/profile/etc/profile.d/*.sh; do | |
XDG_STATE_HOME=${XDG_STATE_HOME:-$HOME/.local/state} | |
if [ -d $XDG_STATE_HOME/nix/profile/etc/profile.d ]; then | |
for i in $XDG_STATE_HOME/nix/profile/etc/profile.d/*.sh; do |
@@ -14,7 +14,7 @@ | |||
# | |||
# Or if installed locally: | |||
# | |||
# source ~/.nix-profile/share/zsh-git-prompt/zshrc.sh | |||
# source $XDG_DATA_HOME/nix/profile/share/zsh-git-prompt/zshrc.sh |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# source $XDG_DATA_HOME/nix/profile/share/zsh-git-prompt/zshrc.sh | |
# source $XDG_STATE_HOME/nix/profile/share/zsh-git-prompt/zshrc.sh |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This won't work when XDG_STATE_HOME is not set which it isn't by default IIRC
+ DEFAULT_PATH += "/.nix-profile/bin:/nix/var/nix/profiles/default/bin:/run/current-system/sw/bin:/etc/profiles/per-user/"; | ||
+ DEFAULT_PATH += "/.nix-profile/bin:/nix/var/nix/profiles/default/bin:/run/current-system/sw/bin:/etc/profiles/per-user/:"; | ||
+ DEFAULT_PATH += pwd->pw_dir; | ||
+ DEFAULT_PATH += "/.local/share/nix/bin:"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+ DEFAULT_PATH += "/.local/share/nix/bin:"; | |
+ DEFAULT_PATH += "/.local/state/nix/bin:"; |
+ TEXMFNIXHOME = $XDG_DATA_HOME/nix/profile/share/texmf-nix | ||
+ TEXMFNIXFALLBACK = ~/.local/share/nix/profile/share/texmf-nix |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+ TEXMFNIXHOME = $XDG_DATA_HOME/nix/profile/share/texmf-nix | |
+ TEXMFNIXFALLBACK = ~/.local/share/nix/profile/share/texmf-nix | |
+ TEXMFNIXHOME = $XDG_STATE_HOME/nix/profile/share/texmf-nix | |
+ TEXMFNIXFALLBACK = ~/.local/state/nix/profile/share/texmf-nix |
|
||
impl Default for Format { | ||
fn default() -> Self { | ||
+ let data_home = std::env::var("XDG_DATA_HOME").unwrap_or("~/.local/share".to_string()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+ let data_home = std::env::var("XDG_DATA_HOME").unwrap_or("~/.local/share".to_string()); | |
+ let data_home = std::env::var("XDG_STATE_HOME").unwrap_or("~/.local/state".to_string()); |
@@ -16,6 +16,7 @@ | |||
(add-to-list 'package-directory-list "/run/current-system/sw/share/emacs/site-lisp/elpa") | |||
|
|||
;; optional. use this if you install emacs packages to user profiles (with nix-env) | |||
(add-to-list 'package-directory-list "~/.local/share/profile/nix/share/emacs/site-lisp/elpa") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(add-to-list 'package-directory-list "~/.local/share/profile/nix/share/emacs/site-lisp/elpa") | |
(add-to-list 'package-directory-list "~/.local/state/profile/nix/share/emacs/site-lisp/elpa") |
@pasqui23 I disagree with moving those files to
The profile, defexpr and channels list are quite important for the user, unlike the examples given (the repl history, for example). Removing any one of them will break the experience in a non-subtle way: things will just stop working. I would argue that this needs to be a separate PR in nix, which moves |
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/tweag-nix-dev-update-22/16251/1 |
@balsoft Can you rebase? Maybe we can get this landed :) |
@lovesegfault I'd like to first merge the correspondent Nix PR |
nix pr was merged 3 weeks ago |
This PR blocks bumping nixVersions.stable to 2.14. |
So is this PR stale? |
Ref: NixOS/nix#5588
This searches in
$XDG_DATA_HOME/nix/profile
everywhere wherepreviously we only looked in
~/.nix-profile
, ditto for.nix-channels
and.nix-defexpr
. This shouldn't break anycompatibility for now. It is highly recommended to use nixpkgs with
these changes if you want to use Nix with the XDG basedir PR, but not
doing so shouldn't result in any dramatic breakage -- in fact, NixOS
is perfectly usable without any user profile.
Things done
sandbox = true
set innix.conf
? (See Nix manual)nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD"
. Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/
)