Support XDG-conformant paths for internal Nix files#146515
Support XDG-conformant paths for internal Nix files#146515balsoft wants to merge 3 commits intoNixOS:stagingfrom
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.
There was a problem hiding this comment.
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.
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.
That would require an update to be simultaneous in both Nix and nixpkgs, which is a lot more difficult to orchestrate correctly.
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. |
|
|
||
| ``` | ||
| 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.
| set debug-file-directory ~/.local/share/nix/profile/lib/debug | |
| set debug-file-directory ~/.local/state/nix/profile/lib/debug |
| ``` | ||
|
|
||
| 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.
| 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: |
| ### 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.
| 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.
| 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.
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.
| 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 |
| # 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.
| # 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.
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.
| + 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.
| + 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.
| + 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()); |
| (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.
| (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: |
|
@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/profileeverywhere wherepreviously we only looked in
~/.nix-profile, ditto for.nix-channelsand.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 = trueset 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/)