Error: .nix-profile is nota symlink

$ nix-env -iA nixos.wget
error: ‘/nix/var/nix/profiles/per-user/game’ is not a symlink

Don’t use nix-env, especially if you are on NixOS (vs. NIx on another Distro).

If you need a program only once or very seldom, use nix-shell or nix run, otherwise, add it to your config.

Random getting started thread in this forum: Help me get started - Best practice, nvim, learning the language - #3 by TLATER
If you search a round a bit, you will find many more threads of this kind.

2 Likes

@wamserma is correct, to install a package on NixOS you should add it to your system packages in /etc/nix/configuration.nix:

{ config, pkgs, ... }:

{
    # [... other options ...]
    environment.systemPackages = with pkgs; [
      # ... other packages ...
      wget
      # ... other packages ...
    ];
    # ... other options ...
}

And then run nixos-rebuild switch afterwards. The package is then installed for all users.

But even though nix-env is not the recommended way to install software on NixOS, this is still a weird issue that I’d like to help debug.

Could you run stat ~/.nix-profile and ls -la /nix/var/nix/profiles/per-user and post the output here? The error message you posted indicates to me that the symlink to the profile is broken.

to fix, i think i ran:

sudo rm -rf /nix/var/nix/profiles/per-user/game
rm ~/.nix-profile
nix-env -iA wget # this worked

Yeah that makes sense. I think you have to run it as nix-env -iA nixos.wget, but still, glad to hear you got it working!

1 Like