NixOS Unfree packages not in path when installed via configuration.nix

Hey everyone!

Just giving NixOS for a spin. Having an issue installing unfree packages and them being available when installed via configuration.nix into a user profile. So in my case in configuration.nix:

nixpkgs.config.allowUnfree = true;
users.users.jasonh= {
    name = "jason";
    home = "/home/jason";
    isNormalUser = true;
    extraGroups = [ "wheel" ]; # Enable ‘sudo’ for the user.
    packages = with pkgs; [
      htop alacritty zsh zsh-powerlevel10k oh-my-zsh powerline-fonts fzf font-awesome al
bert neofetch autorandr arandr firefox slack spotify vscode
    ];
    shell = pkgs.zsh;
  };

And after rebuilding and switching:

$ nix-env -q

alacritty-0.4.2
albert-0.16.1
arandr-0.1.10
autorandr-1.9
firefox-76.0
git-minimal-2.25.4
go-1.14.1
mkpasswd-5.5.5
neofetch-6.1.0
rofi-1.5.4
vim-8.2.0013
zsh-5.7.1

I’d expect vscode, slack, and spotify to be in that list, but alas. Running code or slack or spotify all give a command not found which makes sense since it’s not listed in ~/.nix-profile/bin. However running:

$ nix-store -q --requisites /run/current-system ~/.nix-profile | grep vscode
/nix/store/zxs3r37wwklf08shw3nkybdm5dhibpc5-vscode-1.44.1

show that the package is there. And running:

$ nix-shell -p vscode --run "code"

launches it. Also, if I install it to the system:

  environment.systemPackages = with pkgs; [
    wget vim alacritty zsh vscode
  ];

Running code launches as expected.

Am I missing something about packages and user profiles? Thanks for looking and making it this far :slight_smile:

It is because there are essentially two mostly separate ways of managing packages and so you need to enable non-free software in both places. This is described here.

The declarative way you are using in configuration.nix and imperatively via nix-env. Unless I am mistaken, only software you install with nix-env will show up in nix-env. If you mix and match both methods haphazardly, it can be kind of a pain to keep track of what you have installed. Installing system-wide software with nix-env as you would with a traditional Linux distro also limits the reproducibility of nixos which is one of the primary benefits.

Lastly, since much of your declarative software is showing up in nix-env -q, I suspect you have most of those packages installed twice.

To be fair, I am still learning myself here.

Gotcha - I like the declarative approach so I’ll clean up any imperative packages installed.

Hmm, so how do I get those packages install declaratively into my path…

Ah ok - it was my user config. I had the following before:

users.users.jasonh= {
    name = "jason";
    home = "/home/jason";
    isNormalUser = true;
    extraGroups = [ "wheel" ]; # Enable ‘sudo’ for the user.
    packages = with pkgs; [
      htop alacritty zsh zsh-powerlevel10k oh-my-zsh powerline-fonts fzf font-awesome al
bert neofetch autorandr arandr firefox slack spotify vscode
    ];
    shell = pkgs.zsh;
  };

and in the PATH - /etc/profiles/per-user/<VALUE>/bin doesn’t pull from the name key, instead it pulls from the name of the attribute set. So PATH had:

/etc/profiles/per-user/jason/bin

but things were going to:

/etc/profiles/per-user/jasonh/bin

I wonder if that’s a bug. But problem solved!