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

Does nix has a plan to comply with XDG Base Directory Spec? #1079

Closed
Abdillah opened this issue Oct 2, 2016 · 33 comments · Fixed by #5588
Closed

Does nix has a plan to comply with XDG Base Directory Spec? #1079

Abdillah opened this issue Oct 2, 2016 · 33 comments · Fixed by #5588
Assignees
Labels
feature Feature request or proposal UX The way in which users interact with Nix. Higher level than UI.

Comments

@Abdillah
Copy link

Abdillah commented Oct 2, 2016

Written here, @svanderburg said that Nix try to comply as close as possible with standard (well, with FHS). Whilst, it is failed to fully comply with FHS, why we don't try to comply with XDG Base Directory Spec, which more make sense to users?

Nix programs create three directories at my $HOME. Honestly, it looks very bad for me (by far no complaints on the Internet sadly).

I wanted to create a patch for this if granted.

Best,
Abdillah

@edolstra
Copy link
Member

edolstra commented Oct 3, 2016

I assume you're referring to ~/.nix-defexpr, ~/.nix-channels etc. Those are very old and they may even predate the XDG. We can't change them since that would break compatibility with existing installations. However, most of these files will become obsolete with the new Nix command line interface.

New files do respect the XDG. For example, Nix stores various cache files in ~/.cache/nix.

@Abdillah
Copy link
Author

Abdillah commented Oct 5, 2016

However, most of these files will become obsolete with the new Nix command line interface.

Hmm.. I just install nix & nixos a week ago, so it should be "new" right 😄
And what do you mean obsolete? Honestly, I haven't seen any sign of it. Can you point me some?

I found three files, and yes, those are,
.nix-defexpr -> /nix/store/some-nixpkgs still used by nix-env
.nix-profile -> /nix/var/nix/profiles/.../default not sure who use this, myself?
.nix-channels file used by nix-channel
I thought in early nix, are there more so you said "most of these files"?

Then, how can I help on this? I love nix and my clean ~ 😸

@severen
Copy link
Member

severen commented Oct 8, 2016

@edolstra used past tense when he said "However, most of these files will become obsolete with the new Nix command line interface.", so perhaps you could assume it's either not developed yet or isn't released yet.

@Abdillah
Copy link
Author

Abdillah commented Oct 8, 2016

@SShrike okay then.
Hope we get chance to resolve this.

@nhooyr
Copy link

nhooyr commented Oct 12, 2016

@edolstra well we could do what git does to maintain backwards compatibility. Use $XDG_CONFIG_HOME if it exists but if not, use ~/.nix-whatever. And when creating new files, always use $XDG_CONFIG_HOME.

@hajdamak
Copy link

hajdamak commented Jan 21, 2019

Are there any plans to introduce something like @nhooyr described?

@grahamc
Copy link
Member

grahamc commented Jan 21, 2019

I don't think anyone is working on this project, or working on a plan for this project. It might be possible that a PR implementing that behavior + docs would be accepted.

@edolstra
Copy link
Member

I'm not opposed to it, but I'm not sure it's really worth it. It's likely to cause all sorts of confusion (e.g. when ~/.nix-channels and ~/.local/share/nix/channels both exist).

@hajdamak
Copy link

@edolstra Your fist comment in this thread mentioned new Nix command line interface. Is this currently being worked on?

@edolstra
Copy link
Member

Yes, the new nix command in Nix >= 2.0 uses ~/.config/nix. However it doesn't have replacements for nix-channel and nix-env yet. Hopefully soon.

@hajdamak
Copy link

So the plan is that new nix command will no longer use .nix-profile, .nix-channels and .nix-defexpr and keep necessary information in ~/.config/nix?
Is it described somewhere?

@wangkev
Copy link

wangkev commented Aug 29, 2020

Are there any updates here? Would definitely appreciate this.

@Ericson2314
Copy link
Member

Ericson2314 commented Aug 30, 2020

Yeah, it would be good to try some new directories for the old stuff, c.f. Git supporting /.gitconfig and /.config/git/... Even if flakes is stabilized, I still imagine people will not all stop using channels and what-not instantly, so I think this is worth it.

@xeruf
Copy link

xeruf commented Sep 24, 2020

4 years ago, it was stated that these would become obsolete. What's going on? My home being cluttered is so incredibly annoying...
Why not migrate softly like @nhooyr suggested?

@stale
Copy link

stale bot commented Mar 26, 2021

I marked this as stale due to inactivity. → More info

@stale stale bot added the stale label Mar 26, 2021
@GovanifY
Copy link
Member

This is definitely not stale, it'll have to happen at some point

@stale stale bot removed the stale label Mar 31, 2021
@TLATER
Copy link

TLATER commented Jun 23, 2021

On the opposite end of this, I'm using the new nix commands, and I still have this clutter in my home directory. What is their purpose at this point? In my case the files just seem to be empty or contain [ ], is this just leftover?

@luciorq
Copy link

luciorq commented Oct 26, 2021

On the opposite end of this, I'm using the new nix commands, and I still have this clutter in my home directory. What is their purpose at this point? In my case the files just seem to be empty or contain [ ], is this just leftover?

Can someone expand on this?

@06kellyjac
Copy link
Member

Probably:

λ cat ~/.nix-defexpr/channels/manifest.nix
[ ]

As a note for me ~/.nix-defexpr/channels_root/ and ~/.nix-profile/ has a bunch of stuff in it

It'd be good to get a list of empty or [ ] files from @TLATER

@TLATER
Copy link

TLATER commented Oct 26, 2021

tlater ~ $ find -L .nix-defexpr -type f -printf "%p\n" -exec cat {} +
.nix-defexpr/channels_root/manifest.nix
.nix-defexpr/channels/manifest.nix
[ ][ ]%                                                                                           
tlater ~ $ cat .nix-channels
tlater ~ $ cat .nix-profile/manifest.nix
[ ]%

That said, I now realize this is likely because I'm using flakes, so neither my user nor root are using any channels. Not that that's any less annoying, of course.

If you are also using flakes, and still have debris in there, keep in mind that you likely should delete those channels manually at some point.

@06kellyjac
Copy link
Member

Yeah I've switched to flakes on a machine that wasn't originally using them.

Would none of this come from this config?:

  mkRegistry = attrs: lib.mapAttrs (_: flake: { inherit flake; }) attrs;
  defaultModules = [
    {
      nix = {
        nixPath = [
          "nixpkgs=${nixpkgs}"
          "home-manager=${home-manager}"
          "nixpkgs-master=${nixpkgs-master}"
          "nur=${nur}"
        ];
        registry = mkRegistry { inherit nixpkgs home-manager nixpkgs-master nur; };
      };
    }
  ];

@TLATER
Copy link

TLATER commented Oct 26, 2021

Unlikely, given I have those settings set too: https://github.com/TLATER/nixos-hosts/blob/master/flake.nix#L47

nix-channel --list and sudo nix-channel --list will probably give you some output, delete the channels with nix-channel --remove (both for root and your user), and you should get the same output I do :)

@balsoft
Copy link
Member

balsoft commented Nov 17, 2021

Everyone who's interested, please help review and test #5588

@nixos-discourse
Copy link

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/tweag-nix-dev-update-22/16251/1

@stale stale bot added the stale label Aug 12, 2022
@fricklerhandwerk fricklerhandwerk added feature Feature request or proposal UX The way in which users interact with Nix. Higher level than UI. and removed stale labels Sep 12, 2022
@balsoft
Copy link
Member

balsoft commented Feb 10, 2023

Now if you set use-xdg-base-directories = true in your /etc/nix/nix.conf, all the "classic" Nix tools (nix-env, nix-channel, ...) and nix profile will use ~/.local/state/nix instead of dotfiles in your ~.

@Ramblurr
Copy link

I'm trying to figure out how to install nix and take advantage of this feature..

I have use-xdg-base-directories = true in my /etc/nix/nix.conf

I use the snippet sh <(curl -L https://releases.nixos.org/nix/nix-2.14.1/install) --no-daemon

But at the end it tells me to source /home/ramblurr/.nix-profile/etc/profile.d/nix.sh but this file doesn't exist. It also doesn't exist in ~/.config/nix nor ~/.local/state/nix

@balsoft
Copy link
Member

balsoft commented Mar 24, 2023

Hi @Ramblurr , we're working on better documentation and support for use-xdg-base-directories right now.

As for your problem, you should do source /home/ramblurr/.local/state/nix/profile/etc/profile.d/nix.sh .

@Ramblurr
Copy link

thanks @balsoft ! That solved it.

@Freed-Wu
Copy link
Contributor

Yes, the new nix command in Nix >= 2.0 uses ~/.config/nix. However it doesn't have replacements for nix-channel and nix-env yet. Hopefully soon.

Does it exist any progress of ~/.config/nix/nix-channel?

@balsoft
Copy link
Member

balsoft commented Jul 12, 2023

@Freed-Wu yes. Please set use-xdg-base-directories = true in your /etc/nix/nix.conf, and then nix-channel will use ~/.local/state/nix/channels.

@Freed-Wu
Copy link
Contributor

After nix.settings.use-xdg-base-directories = true;, my zsh's $fpath/$path still exist .nix-profile, is it a bug of zsh package?

$ print -l $path
/run/wrappers/bin
/home/wzy/.nix-profile/bin
/etc/profiles/per-user/wzy/bin
/nix/var/nix/profiles/default/bin
/run/current-system/sw/bin
$ print -l $fpath
/home/wzy/.nix-profile/share/zsh/site-functions
/home/wzy/.nix-profile/share/zsh/5.9/functions
/home/wzy/.nix-profile/share/zsh/vendor-completions
/etc/profiles/per-user/wzy/share/zsh/site-functions
/etc/profiles/per-user/wzy/share/zsh/5.9/functions
/etc/profiles/per-user/wzy/share/zsh/vendor-completions
/nix/var/nix/profiles/default/share/zsh/site-functions
/nix/var/nix/profiles/default/share/zsh/5.9/functions
/nix/var/nix/profiles/default/share/zsh/vendor-completions
/run/current-system/sw/share/zsh/site-functions
/run/current-system/sw/share/zsh/5.9/functions
/run/current-system/sw/share/zsh/vendor-completions
/nix/store/jg5k4ksj3silfqyw0id9wd99rakcz0ws-zsh-5.9/share/zsh/5.9/functions

@Freed-Wu
Copy link
Contributor

I know the reason. It comes from

$ cat /nix/store/s0ii95lj2kc67gphakd3vll887kmcknv-set-environment|rg NIX_PROFILES
79:export NIX_PROFILES="/run/current-system/sw /nix/var/nix/profiles/default /etc/profiles/per-user/$USER $HOME/.nix-profile"

However, /nix/store/s0ii95lj2kc67gphakd3vll887kmcknv-set-environment is generated:

$ head -n1 /nix/store/s0ii95lj2kc67gphakd3vll887kmcknv-set-environment
# DO NOT EDIT -- this file has been generated automatically.

So I'll find another solution to fix this bug.

@Freed-Wu
Copy link
Contributor

I have reported this bug NixOS/nixpkgs#243826

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Feature request or proposal UX The way in which users interact with Nix. Higher level than UI.
Projects
None yet
Development

Successfully merging a pull request may close this issue.