Follow XDG Base Directory standard#5588
Conversation
|
Just as a note - this is a breaking for tooling that relies on this, like nixos-infect Also this PR is related: #5226 |
|
Very excited for this and #5226! Before it was argued that "well, nix channel is getting deprecated anyways", but I agree it is better to do this anyways, it's just a good look 😎. |
scripts/install-nix-from-closure.sh
Outdated
| # shellcheck source=./nix-profile.sh.in | ||
| . "$nix/etc/profile.d/nix.sh" | ||
|
|
||
| NIX_LINK=$HOME/.nix-profile |
There was a problem hiding this comment.
Why is it called "NIX_LINK", instead of something like NIX_PROFILE_DIR?
That's really a nitpick, but you've asked to read it through)
There was a problem hiding this comment.
Because it was named like that in some other place :)
I suppose this is a good opportunity to rename the var.
|
A few notes:
|
Everything will be replaced eventually. I think channels are still going to be here for a while, so it'd be nice to not pollute user's home directories in the meantime.
Sure! #5226 should handle that. I'll help merge the two together if needed. |
|
Note: this PR needs a corresponding nixpkgs change. |
| NIX_LINK="$NIX_LINK_NEW" | ||
| else | ||
| if [ -e "$NIX_LINK_NEW" ]; then | ||
| warning="\033[1;35mwarning:\033[0m" |
There was a problem hiding this comment.
I am not sure if we want to check if the terminal supports those escape sequences but I bet it would be safe to assume it does.
|
|
||
| ```console | ||
| $ nix-store -q --graph ~/.nix-profile | dot -Tps > graph.ps | ||
| $ nix-store -q --graph $XDG_DATA_HOME/nix/profile | dot -Tps > graph.ps |
There was a problem hiding this comment.
Examples shouldn't use XDG_DATA_HOME because it may not be set (it isn't on my system). It's better to just use ~/.local/share/nix/profile in examples since very few people will use something else.
Maybe the same applies to the documentation, since references to $XDG_DATA_HOME/nix/profile are harder to understand than ~/.local/share/nix/profile.
There was a problem hiding this comment.
I fully agree for this example here, but for documentation I think it's important to let the people know we're (kinda) following the XDG spec and not just putting things in ~/.local/share.
please don't get rid of *nix-profile many users depend on it |
|
Also I would argue that |
| expressions from each subscribed channel in this directory. | ||
|
|
||
| - `~/.nix-profile`\ | ||
| - `$XDG_DATA_HOME/nix/profile`\ |
There was a problem hiding this comment.
| - `$XDG_DATA_HOME/nix/profile`\ | |
| - `$XDG_STATE_HOME/nix/profile`\ |
| symlink points to `prefix/var/nix/profiles/default`. The `PATH` | ||
| environment variable should include `~/.nix-profile/bin` for the | ||
| user environment to be visible to the user. | ||
| environment variable should include `$XDG_DATA_HOME/nix/bin` for |
There was a problem hiding this comment.
| environment variable should include `$XDG_DATA_HOME/nix/bin` for | |
| environment variable should include `$XDG_STATE_HOME/nix/bin` for |
|
|
||
| This operation makes *path* the current profile for the user. That is, | ||
| the symlink `~/.nix-profile` is made to point to *path*. | ||
| the symlink `$XDG_DATA_HOME/nix/profile` (or `~/.nix-profile`, if it |
There was a problem hiding this comment.
| the symlink `$XDG_DATA_HOME/nix/profile` (or `~/.nix-profile`, if it | |
| the symlink `$XDG_STATE_HOME/nix/profile` (or `~/.nix-profile`, if it |
| Location of the Nix profile. Defaults to the target of the symlink | ||
| `~/.nix-profile`, if it exists, or `/nix/var/nix/profiles/default` | ||
| otherwise. | ||
| `~/.nix-profile`, if it exists, or `$XDG_DATA_HOME/nix/profile`, |
There was a problem hiding this comment.
| `~/.nix-profile`, if it exists, or `$XDG_DATA_HOME/nix/profile`, | |
| `~/.nix-profile`, if it exists, or `$XDG_STATE_HOME/nix/profile`, |
|
|
||
| ```console | ||
| $ nix-store -q --graph ~/.nix-profile | dot -Tps > graph.ps | ||
| $ nix-store -q --graph ~/.local/share/nix/profile | dot -Tps > graph.ps |
There was a problem hiding this comment.
| $ nix-store -q --graph ~/.local/share/nix/profile | dot -Tps > graph.ps | |
| $ nix-store -q --graph ~/.local/state/nix/profile | dot -Tps > graph.ps |
tests/nix-channel.sh
Outdated
| # Do an install. | ||
| nix-env -i dependencies-top | ||
| [ -e $TEST_HOME/.nix-profile/foobar ] | ||
| [ -e $TEST_HOME/.local/share/nix/profile/foobar ] |
There was a problem hiding this comment.
| [ -e $TEST_HOME/.local/share/nix/profile/foobar ] | |
| [ -e $TEST_HOME/.local/state/nix/profile/foobar ] |
tests/nix-channel.sh
Outdated
| ln -s $(readlink $TEST_HOME/.local/share/nix/profile) $TEST_HOME/.nix-profile | ||
| cp -r $TEST_HOME/.local/share/nix/defexpr $TEST_HOME/.nix-defexpr | ||
| cp -r $TEST_HOME/.local/share/nix/channels $TEST_HOME/.nix-channels | ||
| rm -rf $TEST_HOME/.local/share/nix |
There was a problem hiding this comment.
| ln -s $(readlink $TEST_HOME/.local/share/nix/profile) $TEST_HOME/.nix-profile | |
| cp -r $TEST_HOME/.local/share/nix/defexpr $TEST_HOME/.nix-defexpr | |
| cp -r $TEST_HOME/.local/share/nix/channels $TEST_HOME/.nix-channels | |
| rm -rf $TEST_HOME/.local/share/nix | |
| ln -s $(readlink $TEST_HOME/.local/state/nix/profile) $TEST_HOME/.nix-profile | |
| cp -r $TEST_HOME/.local/state/nix/defexpr $TEST_HOME/.nix-defexpr | |
| cp -r $TEST_HOME/.local/state/nix/channels $TEST_HOME/.nix-channels | |
| rm -rf $TEST_HOME/.local/state/nix |
tests/nix-channel.sh
Outdated
| # Do an install. | ||
| nix-env -i dependencies-top | ||
| [ -e $TEST_HOME/.nix-profile/foobar ] | ||
| ! [ -e $TEST_HOME/.local/share/nix ] |
There was a problem hiding this comment.
| ! [ -e $TEST_HOME/.local/share/nix ] | |
| ! [ -e $TEST_HOME/.local/state/nix ] |
tests/user-envs.sh
Outdated
|
|
||
| mkdir -p $TEST_HOME | ||
| nix-env --switch-profile $profiles/test | ||
| stat $HOME/.local/share/nix/profile |
There was a problem hiding this comment.
| stat $HOME/.local/share/nix/profile | |
| stat $HOME/.local/state/nix/profile |
tests/user-envs.sh
Outdated
| rm -rf $HOME/.local/share/nix/defexpr | ||
| mkdir -p $HOME/.local/share/nix | ||
| ln -s $(pwd)/user-envs.nix $HOME/.local/share/nix/defexpr |
There was a problem hiding this comment.
| rm -rf $HOME/.local/share/nix/defexpr | |
| mkdir -p $HOME/.local/share/nix | |
| ln -s $(pwd)/user-envs.nix $HOME/.local/share/nix/defexpr | |
| rm -rf $HOME/.local/state/nix/defexpr | |
| mkdir -p $HOME/.local/state/nix | |
| ln -s $(pwd)/user-envs.nix $HOME/.local/state/nix/defexpr |
|
I hadn't heard of |
|
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: |
|
I agree As to That said, I don't think it needs an XDG equivalent. One can always symlink |
|
Big +1 on this PR -- By the way, it seems like PipeWire is using the new XDG state dir, too. ~
❯ ls -al ~/.local/state
total 2
drwx------ 4 cole cole 4 Mar 4 01:53 .
drwxr-xr-x 4 cole cole 4 Nov 26 22:47 ..
drwx------ 3 cole cole 3 Nov 26 22:47 pipewire
drwx------ 2 cole cole 4 Mar 8 13:17 wireplumberEDIT: Per Artturin on Matrix, |
|
I don't want to be too greedy, but I'd happily run this on my systems if it were rebased and applied against nixUnstable easily. |
|
rebased and applied @pasqui23 suggestions of switching to |
|
|
|
Thanks @Artturin , pushed your version here |
|
Oh good! This is better. |
src/nix-channel/nix-channel.cc
Outdated
| createDirs(getStateDir() + "/nix"); | ||
| channelsList = getStateDir() + "/nix/channels"; |
There was a problem hiding this comment.
| createDirs(getStateDir() + "/nix"); | |
| channelsList = getStateDir() + "/nix/channels"; | |
| auto dir = getStateDir() + "/nix"; | |
| createDirs(dir); | |
| channelsList = dir + "/channels"; |
There was a problem hiding this comment.
applied your suggestions in my branch
|
Wow, sorry about that. I wonder why the tests passed :/ |
|
Actually, do you still have Could you check the I can't reproduce this with |
|
Can't reproduce with 2.14.0 either: This is NixOS, so maybe other distros are broken? |
|
I can confirm I think this is an issue in the install scripts after all. Sorry for the noise 😅 |
|
Ah, this might be the problem: https://github.com/NixOS/nix/pull/5588/files#diff-68e663aabb64bc761187fcc02c1e8fc085109072294796a9cd6af4df20205f38R12 If you don't have |
|
For the moment, I plan on putting the fire out with NixOS/nixpkgs#218858 (using EDIT: I haven't tested myself on NixOS, but I reproduced this in an Ubuntu VM and GitHub Actions CI, both of which use the installer scripts, etc. |
|
OK, finished bisecting earlier, and this PR is indeed the culprit: (where 2384d36 is the actual commit and 9ebbe35 is the merge; I had to Currently in the middle of trying things manually in a VM (which is a bit of a pain, since I'm relying on the installer tests CI stuff to upload the install script and tarball somewhere that I can FWIW, directly after installing, these are the full bisect log |
|
Maybe-not-perfect fix is up: #7925 |
mikeland73
left a comment
There was a problem hiding this comment.
When XDG is not set, we set
NIX_LINK_NEW=$HOME/.local/state/nix/profile
but I think it should be
NIX_LINK_NEW=$HOME/.local/state/nix/profiles/profile/ ?
(at least that seems to be where nix is creating profile symlink in 2.14.0)
| if [ -n "$XDG_STATE_HOME" ]; then | ||
| NIX_LINK_NEW="$XDG_STATE_HOME/nix/profile" | ||
| else | ||
| NIX_LINK_NEW=$HOME/.local/state/nix/profile |
There was a problem hiding this comment.
Should this be NIX_LINK_NEW=$HOME/.local/state/nix/profiles/profile/ ?
There was a problem hiding this comment.
What does make you think we want to profile/profiles? That looks like a bug to me.
There was a problem hiding this comment.
@SuperSandro2000 I'm not familiar with the nix source code, but when I do a single user install on a fresh docker ubuntu, nix adds the following sym link:
~/.nix-profile -> ~/.local/state/nix/profiles/profile
Do we not want this value to match that?
If ~/.nix-profile doesn't exist and $XDG_STATE_HOME is not set, we end up with NIX_LINK_NEW=$HOME/.local/state/nix/profile but this link target doesn't exist on my install.
There was a problem hiding this comment.
It seems like there is both ~/.local/share/nix/profiles/profile and ~/.local/state/nix/profile. The former is the actual profile, the latter is a symlink to it. I think this should be simplified by putting the profiles in state and removing the useless indirection (compatibility is only needed for ~/.nix-profile when not using xdg-base-dirs)
(Or keep the profiles in share, we've had enough breakage already)
There was a problem hiding this comment.
Yes this is what I called out in #5588 (comment). I think rather than trying to support 4(!) combinations, we should do all the XDG stuff (this and home directories) together so there are just 2 combinations.
|
Another seemingly related failure in home-manager even after bumping install-nix-action to v20: |
|
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: |
|
For those wondering, this landed in 2.14.0. |
|
2.14.0 is still broken (although now for different reasons). The current installed still points to 2.13.3. |
|
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: |
|
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: |


XDG Base Directory is a standard for locations for storing various
files. Nix has a few files which seem to fit in the standard, but
currently use a custom location directly in the user's
~, pollutingit:
~/.nix-profile~/.nix-defexpr~/.nix-channelsThis pull request makes new Nix installations follow the XDG spec and
instead use the following locations:
$XDG_DATA_HOME/nix/profile$XDG_DATA_HOME/nix/defexpr$XDG_DATA_HOME/nix/channelsIf
$XDG_DATA_HOMEis not set, it is assumed to be~/.local/share.Old locations are preferred if they exist, but for new installations
(or after cleaning the home dir) new, XDG-conformant locations are
used by default.
Closes #1079
Checklist for maintainers
tests/**.sh)~~ (no substantial change in behavior)