Skip to content
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

Draft
wants to merge 3 commits into
base: staging
Choose a base branch
from

Conversation

balsoft
Copy link
Member

@balsoft balsoft commented Nov 18, 2021

Ref: NixOS/nix#5588

This searches in $XDG_DATA_HOME/nix/profile everywhere where
previously we only looked in ~/.nix-profile, ditto for
.nix-channels and .nix-defexpr. 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.

Things done
  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandbox = true set in nix.conf? (See Nix manual)
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 21.11 Release Notes (or backporting 21.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

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.
@github-actions github-actions bot added 6.topic: emacs Text editor 6.topic: haskell 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 6.topic: TeX Issues regarding texlive and TeX in general 6.topic: vim 8.has: documentation This PR adds or changes documentation 8.has: module (update) This PR changes an existing module in `nixos/` labels Nov 18, 2021
Comment on lines +623 to +630
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
Copy link
Member

@Artturin Artturin Nov 19, 2021

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?

Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

@cab404 cab404 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM #zhfmsk

@SuperSandro2000
Copy link
Member

This needs to go to staging.


#140168 (comment)

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.

@balsoft balsoft changed the base branch from master to staging November 22, 2021 13:46
@@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

Comment on lines +267 to +269
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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

Copy link
Contributor

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}?

Comment on lines +300 to +302
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# source $XDG_DATA_HOME/nix/profile/share/zsh-git-prompt/zshrc.sh
# source $XDG_STATE_HOME/nix/profile/share/zsh-git-prompt/zshrc.sh

Copy link
Member

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:";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
+ DEFAULT_PATH += "/.local/share/nix/bin:";
+ DEFAULT_PATH += "/.local/state/nix/bin:";

Comment on lines +15 to +16
+ TEXMFNIXHOME = $XDG_DATA_HOME/nix/profile/share/texmf-nix
+ TEXMFNIXFALLBACK = ~/.local/share/nix/profile/share/texmf-nix
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
+ 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());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
+ 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")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
(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")

@balsoft
Copy link
Member Author

balsoft commented Nov 23, 2021

@pasqui23 I disagree with moving those files to $XDG_STATE_HOME. As per the standard (emphasis mine):

The $XDG_STATE_HOME contains state data that should persist between (application) restarts, but that is not important or portable enough to the user that it should be stored in $XDG_DATA_HOME

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 repl-history to the XDG_STATE_HOME.

@nixos-discourse
Copy link

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

@lovesegfault
Copy link
Member

@balsoft Can you rebase? Maybe we can get this landed :)

@balsoft
Copy link
Member Author

balsoft commented Apr 11, 2022

@lovesegfault I'd like to first merge the correspondent Nix PR

@SuperSandro2000 SuperSandro2000 added the 2.status: merge conflict This PR has merge conflicts with the target branch label Apr 11, 2022
@Artturin Artturin added the 12.approvals: 1 This PR was reviewed and approved by one reputable person label May 4, 2022
@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Nov 2, 2022
@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Feb 24, 2023
@Artturin
Copy link
Member

Artturin commented Mar 1, 2023

nix pr was merged 3 weeks ago

@SuperSandro2000
Copy link
Member

This PR blocks bumping nixVersions.stable to 2.14.

@infinisil infinisil mentioned this pull request May 22, 2023
12 tasks
@wegank wegank removed the 12.approvals: 1 This PR was reviewed and approved by one reputable person label Sep 7, 2023
@nyabinary
Copy link
Contributor

So is this PR stale?

@wegank wegank added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Mar 19, 2024
@wegank wegank marked this pull request as draft March 20, 2024 15:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.status: merge conflict This PR has merge conflicts with the target branch 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md 6.topic: emacs Text editor 6.topic: haskell 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 6.topic: TeX Issues regarding texlive and TeX in general 6.topic: vim 8.has: documentation This PR adds or changes documentation 8.has: module (update) This PR changes an existing module in `nixos/` 10.rebuild-darwin: 501+ 10.rebuild-darwin: 2501-5000 10.rebuild-linux: 501+ 10.rebuild-linux: 5001+
Projects
None yet
Development

Successfully merging this pull request may close these issues.