Nh users - need help

I just installed nh. As a first thing i wanted to try out clean up feature.

nh clean all --keep 3 --dry
[sudo] password for arvindh: 
! Failed to read profiles directory dir="/root/.local/state/nix/profiles" error=Os { code: 2, kind: NotFound, message: "No such file or directory" } @ src/clean.rs:267

Welcome to nh clean
Keeping 3 generation(s)
Keeping paths newer than 0s

legend:
OK: path to be kept
DEL: path to be removed

gcroots (matching the following regex patterns)
- RE  .*/.direnv/.*
- RE  .*result.*
- DEL /home/mainuser/.dotfiles/result

/nix/var/nix/profiles/per-user/mainuser/channels
- OK  /nix/var/nix/profiles/per-user/mainuser/channels-2-link

/nix/var/nix/profiles/per-user/mainuser/profile
- OK  /nix/var/nix/profiles/per-user/mainuser/profile-10-link
- OK  /nix/var/nix/profiles/per-user/mainuser/profile-9-link

/nix/var/nix/profiles/per-user/root/channels
- OK  /nix/var/nix/profiles/per-user/root/channels-3-link
- OK  /nix/var/nix/profiles/per-user/root/channels-2-link

/home/mainuser/.local/state/nix/profiles/channels
- OK  /home/mainuser/.local/state/nix/profiles/channels-1-link

/nix/var/nix/profiles/system
- OK  /nix/var/nix/profiles/system-30-link
- OK  /nix/var/nix/profiles/system-29-link
- OK  /nix/var/nix/profiles/system-28-link
- DEL /nix/var/nix/profiles/system-27-link
- DEL /nix/var/nix/profiles/system-26-link
- DEL /nix/var/nix/profiles/system-25-link
- DEL /nix/var/nix/profiles/system-24-link

/home/mainuser/.local/state/nix/profiles/home-manager
- OK  /home/mainuser/.local/state/nix/profiles/home-manager-14-link
- OK  /home/mainuser/.local/state/nix/profiles/home-manager-13-link

> Performing garbage collection on the nix store

Question is, what is the file that its looking for ? my root dir doesn’t has a .local directory.

Generally, ~/.local/state is a convention as part of XDG Base Desktop specification. Kinda like ~/.config. It’s nice if programs can adhere to that, rather than just putting files wherever.

The nix commands use that convention, and use ~/.local/state/nix/profiles instead of … (EDIT: redact mistake).

Nix profiles are nix’s way of “installing packages”.

That /root/.local/state/nix doesn’t exist probably means you’ve never run sudo nix profile install nor sudo home-manager ... or such. So, not a problem.

Probaby it’d be tidier if nh didn’t emit a warning in this case, though.

:slightly_frowning_face: Now that went right over my head.

I kind of understood the way profile works. (correct me if im wrong,…) When installing something, it creates a different path for each package or even for same package but different version under the store and they all are orchestrated using symlinks on need basis (i mean using the env). This is what i understood from the link you have provided.

So, since i haven’t done any installation using profile this path to place all the installations are currently redirected to ~/.nix-profile, am i right ?!

Yes, i haven’t tried installing any pkg using profile. Instead i have been adding packages using configuration.nix or home.nix so far.
May i ask whats the effect of installing a package through .nix file and profile. I mean when can we use this method to install something.

Whats the actual/better “nix’ers way”?

Ah, I meant it more as a “for your information”. “XDG specification” sounds fancy, but it’s just a description for where programs should put the config files (& other files they might need).

Ah. I was mistaken about ~/.nix-profile and ~/.local/state/nix/profiles.

~/.nix-profile is a convenient symlink to the user’s current profile.

~/.local/state/nix/profiles is just a folder where local profiles can go.

e.g. home manager uses that dir for the home-manager profile.

e.g. you can try readlink ~/.local/state/nix/profiles/home-manager, and this points to e.g. home-manager-15-link.

– You can look through ~/.local/state/nix/profiles/home-manager-15-link or so, you’ll see it has /activate and /bin/home-manager-generation and other files. – When you run home-manager switch, this home-manager profile gets updated to point to a new build.

nix profile install adds a package to the user’s profile. e.g. running nix profile install nixpkgs#cowsay means you’ll have cowsay in ~/.nix-profile/bin.

nix-env --install and nix profile install come with their own footguns. It’s easy to make mistakes when using it that way, causing problems that are difficult to understand (& so are difficult to ask for help for). – It’s often better to just use nix shell nixpkgs#cowsay, or to use Home Manager, or install a system in a global config. – See e.g.

:+1: got it.

understood.

Got the caveat of using env & profile ,i better will stick with .nix :smile:
And thanks for the link Depreciate the use of nix-env to install packages? :+1: which gave more insight on the development procedure or process too (haven’t gone through the entire thread yet)

So back to the question, how do i resolve this warning. i get it

but, out of curiosity and interest, how do i resolve that warning &

how do i achieve this ?

sudo mkdir -p /root/.local/state/nix/profiles

probably solves this.

Ah. It’s the software developers who maintain that.

You as a user can put files wherever you want.

But some users want programs to look for the config files in ~/.config/<program>, and so those users want the software developers to make the software do that by default.

Thanks a lot :handshake: @rgoulter for your time and explanation over my silly/noobie questions, learnt a lot about nix over one topic actually.

I thought there was some other command that created the file and linked it to something or somewhere at the backend. For now i will follow as you’ve said.

I will approach the project maintainer and see, let that be my first open source contribution atleast :saluting_face:.

For the XDG? Ah, Nix already does that, which is good.

The thing to approach nh for is to check whether it’s the program that’s responsible for this “Failed to read profiles directory” warning. If so, it should consider the case where the directory doesn’t exist for root.

1 Like

Okay. And thanks a lot for the heads up to be way more precise to the maintainer on what to be asked for.