"created 1 symlinks in user environment" but where?

I tried the following:

$ nix-channel --update
unpacking channels...
created 1 symlinks in user environment

It’d be helpful if the output was more like

$ nix-channel --update
unpacking channels...
created 1 symlinks in user environment: /path/to/link -> /path/to/file

So that we can learn what it is doing as we go. As a newb I don’t have an idea what symlink it made.

EDIT: I’m assuming it is one of these:

$ ll /nix/var/nix/profiles/per-user/joe/
total 20
drwxr-xr-x 2 joe joe 4096 Jan  6 13:15 ./
drwxr-xr-x 3 joe joe 4096 Jan  6 13:08 ../
lrwxrwxrwx 1 joe joe   15 Jan  6 13:15 channels -> channels-2-link/
lrwxrwxrwx 1 joe joe   60 Jan  6 13:08 channels-1-link -> /nix/store/5ihyps67n9s330vb2xfbsxbgfl1m0vp1-user-environment/
lrwxrwxrwx 1 joe joe   60 Jan  6 13:15 channels-2-link -> /nix/store/1z56618cvl1q1015dz9pjny00qq1q7hd-user-environment/
lrwxrwxrwx 1 joe joe   14 Jan  6 13:08 profile -> profile-1-link/
lrwxrwxrwx 1 joe joe   60 Jan  6 13:08 profile-1-link -> /nix/store/00sxzkdjx5vm529yqkc2s5zmb9ip711q-user-environment/


It is a bit difficult to adapt this message, as it is pretty generic and appears in many places. You may do not want them all printed on the console.

To dig a bit deeper, you are updating the channels, which means that you are creating a new channels-<id>-link symlink to a new derivation that contains the updated channels.

In my case the interesting channels are stored in root’s profile, for the whole nixos system. The set of channels (channels) points to channels-55-link which in turn points to /nix/store/6338w5976r049z49xq6inaj5xvdaa3s8-user-environment
Note how this derivation is called user-environment. It is the same “user environment” as in the message “created 1 symlinks in user environment”.

$ tree /nix/var/nix/profiles/per-user/root          
├── channels -> channels-56-link
├── channels-55-link -> /nix/store/6338w5976r049z49xq6inaj5xvdaa3s8-user-environment
└── channels-56-link -> /nix/store/a31cydlm61yvpks4n44w0xx8zv8kp8h4-user-environment

To understand the symlink count, you need to expand that path. You then discover that it contains two channels, and the manifest. The manifest is not counted in the list of symlinks as per the source code. In my case, I have two channels and nix-channel --update prints “created 2 symlinks in user environment”.

$ tree /nix/store/6338w5976r049z49xq6inaj5xvdaa3s8-user-environment
├── manifest.nix -> /nix/store/qmgr338dnnhzfiynnnmwndwpalxcjvs1-env-manifest.nix
├── nixos -> /nix/store/1d583i19f28g05z0kmpbmmkrsgkkxrl1-nixos-20.03pre204199.3140fa89c51/nixos
└── release -> /nix/store/80498pq1xn4pmxr23iwm9ikrkam502zz-release-17.03.1949.78e9665b48f/release

So the part that print that message has no access to all the /nix/var/nix logic. It just collects named derivations and symlinks the name to the derivation, and adds a manifest.

Getting a more verbose output for nix-channel is not trivial as the bulk of the job is done by nix-env, which is also very terse.
Have a look at https://github.com/NixOS/nix/blob/3ad4a332eb704a4b6f2644cefbcfc5f406b39ca4/src/nix-channel/nix-channel.cc#L128-L150 for how nix-channel calls nix-env.
The relevant lines of code for nix-env are at https://github.com/NixOS/nix/blob/3ad4a332eb704a4b6f2644cefbcfc5f406b39ca4/src/nix-env/nix-env.cc#L709-L711 where you can see that the only message is at the debug level, and remain pretty uninformative: "switching to new user environment".

1 Like

Thanks for the detailed reply. That’s quite a lot of information. At a higher level, what is that message useful for?

It’s not useful. It is just not correctly hidden by the --quiet flag passed to nix-env. You can just ignore it.

1 Like

It’s useful in that it tells me whether the nix-channel --update command actually updated anything (and therefore whether I should rebuild my environment).

1 Like

In this case, is it also useful in that if the system breaks we can correlate it with the new symlink location?

I have no idea what I’d ever do with the information about what the actual new symlinks are. If the system breaks, I’d correlate it with when it broke and rollback.

What if you do a few updates before you notice something is broken?

Then I won’t have the output of nix-channel --update on hand to refer to anyway.

I don’t generally do nix-channel --update without rebuilding my environment anyway, but if I did and it broke after a few updates, I can just rollback repeatedly until the environment build works.

1 Like