Why "/nix/var/nix/profiles/per-user" is empty?

I don’t want to run a daemon on my OS. I also want to be able to run installed nix packages for all OS users.

Therefore:

I have an empty user ($NIX_USER_NAME), only for nix operations.

su $NIX_USER_NAME -c “cd /home/$NIX_USER_NAME; wget https://nixos.org/nix/install; bash install; source ~/.nix-profile/etc/profile.d/nix.sh”

Now I can run nix commands via: (I have an alias for below command)

su $NIX_USER_NAME -c “/home/$NIX_USER_NAME/.nix-profile/bin/nix-env -iA firefox”

But this folder is empty:

/nix/var/nix/profiles/per-user

On old versions of nix (before 2 years) above folder was not empty. What happened? I want to run firefox from here:

/nix/var/nix/profiles/per-user/$NIX_USER_NAME/bin/firefox

This is an imperative method for installing software on nix and is not the recommended standard practice.

A better practice is to specify packages to system and users individually through the master /etc/nixos/configuration.nix file.

Heres a snip that’ll provide some context for this.

users.users.mephistopheles.packages = [ pkgs.firefox pkgs.thunderbird ]

This option users.users.<user> = can be stated multiple times for different users.
This should provide a solution to you for your problem, after a rebuild the bin’s should be available only to the profile they are installed under in the sys config.

There are also a number of options specifically for firefox available to top level in the config. You can find more here if you are interested in reading, https://search.nixos.org/options?channel=24.11&from=0&size=50&sort=relevance&type=packages&query=firefox

Thank you for your message :pray:

I don’t use NixOS. Therefore I dont have ‘/etc/nixos’ directory.

I only installed nix package manager and I installed firefox. Firefox works properly. Firefox is just an example. I have installed another app. I just wrote firefox for example.

But my issue is that “profile” directory is empty. It was not empty when I had install before 1-2 years before.

I know my installation-pratice is not recommended, but you can think I will use nix packages only via “nix_user”. The result will not change. “Profile” is still empty.

Aah. I see.

What OS are you running and can you post the full output and maybe a stack trace?

I use Fedora latest stable version. I installed nix today with command which I sent on my first post.

The output is clear. I can install any package with nix without any warning or error. The installed apps works perfect by the way.

I don’t think that this is a bug. Something has been changed.

If you still need an output please tell me which command’s output you want.

Thank you again. :pray:

You mentioned no daemon and you installed nix today, assuming you followed this >> Download | Nix & NixOS doc, im guessing you installed nix using the single user instance described with sh <(curl -L https://nixos.org/nix/install) --no-daemon

The flavor text underneath:

Above command will perform a single-user installation of Nix, meaning that nix is owned by the invoking user. You should run this under your usual user account, not as root. The script will invoke sudo to create /nix if it doesn’t already exist.

In this event, a single user install wouldnt include a per-user directory, or it would be empty as the only user capable of using nix is you. So it would get written to home directory.
You can try invoking the program you installed with nix with the debug flags, verbose flags, or running a which command on it to see where the command is being executed from, which should reveal the bin location.

I actually JUST found this.
This should be your answer, credit goes to this guy at unix stack exchange.

After having created a VM just to play with a fresh installation of nix (the package manager, not the distro), I finally figured it out. Apparently, the default profile, for a “–no-daemon” installation is ~/.local/state/nix/profiles/profile. I wish this was documented somewhere, but at least people can find it here.

Sorry I did not mention it before. Yes I already saw that directory. But I’m sure there were another copy of that directory under “/nix/var/nix/profiles/per-user”.

Something has been change :frowning:

It would be really good because “/nix/var/nix/profiles/per-user” is accessible by all users on my OS as default. I would be able to run all apps from there :frowning: I was using nix for a long time with that way without any error. Now all my dreams shattered :frowning:

That looks to be the old way of doing things, but i can see why it was changed at least for the single user instance of nix. Reason being is its not suggested using root for a single user instance, and typically, for most production environments and especially managed corporate environments, you NEED root perms to write to the root / directory which isnt possible for non admin accounts.

A single instance install now installs the bin directory to ~/.local directory and updates your shell path which would be the correct way to step down permissions on a system level with minimal interference.

If you wish to continue using this older method, a simple solution is simply sim linking the whole profile directory to /nix/var/nix/profiles
Barring that, you would need to do a daemon install.

1 Like

I will try to install nix on my HOME directory.

nix run --store $HOME/nix

UPDATE:

I tried. But official-doc says don’t:

https://nix.dev/manual/nix/2.22/installation/building-source

Warning

It is best not to change the Nix store from its default, since doing so makes it impossible to use pre-built binaries from the standard Nixpkgs channels — that is, all packages will need to be built from source.

If you are trying to install something for multiple users, another approach would be to install nix for each user individually. SU to the user you need to execute some nix installed software on, install nix to that profile, and then grant RW access to your admin account.
But this would be annoyingly tedious.

But ive been chewing on it for a while and there are older versions of nix you can install and pin instead of latest/stable version. If an older version of nix did what you wanted, it might be worth trying to roll back to those older version of nix.
Check out this:

Installing a pinned Nix version from a URL

Version-specific installation URLs for all Nix versions since 1.11.16 can be found at releases.nixos.org. The corresponding SHA-256 hash can be found in the directory for the given version.

These install scripts can be used the same as usual:

 curl -L https://releases.nixos.org/nix/nix-<version>/install | sh

Source: https://releases.nixos.org/nix/nix-2.16.1/manual/installation/installing-binary.html

Version [2.25.3] for nix is the current version according to the nix downloads section.

I cant find a release schedule, but assuming the usual versioning practices, start with v 2.1.x, then 2.0.x and so on stepping down until you find a version that does what you remember it doing.

Nevermind, i found a release schedule which includes previous version.

https://endoflife.date/nix

Thank you for your help :pray:

I don’t want to stick with old versions. I never install something old.

I don’t install many apps via nix. Therefore I will run apps one by finding executable via below command:

sudo ls -l /home/nix_user/.nix-profile/bin

Above command prints me where is the original executable file. Example print:

/nix/store/firefox-hashX/bin/firefox

I will run firefox directly without sudo. As default all OS users can “read” and “execute” all paths under:

/nix/store

In the future maybe I will use symbolic links or shell-aliases directly to run executable inside bin.