'nix-env -iA nixos.cmd' instead of 'nixpkgs.cmd'

Every time I run the virtual command “cmd” and 'cmd isn’t installed. I receive a ‘command-not-found’ message that shows me how to.
Fine up to this point, the suggested installation command is:

$ cmd
The program 'cmd' is currently not installed. You can install it by typing:
nix-env -iA nixpkgs.cmd

but I use a NixOS, not nix as package mgr.
I like an answer like this:

$ cmd
The program 'cmd' is currently not installed. You can install it by typing:
nix-env -iA nixos.cmd

How to fix it? Thanks in advance.

Here is my prob in real live

my configuration.nix for nix-index and my zsh

Here is a snippet for enabling nix-index and ‘zsh’

# zsh.nix
{ config, pkgs, ... }:
{

#       Z  S  H
 programs.command-not-found.enable = false;
 # programs.zsh.interactiveShellInit = ''
 #	source ${pkgs.nix-index}/etc/profile.d/command-not-found.sh '';
 programs.bash.interactiveShellInit = ''
 	source ${pkgs.nix-index}/etc/profile.d/command-not-found.sh '';

 programs.nix-index =        { #damit command: nix-locate pattern
        enable = true; # enable nix-index, a file database for nixpkgs.
    	package = pkgs.nix-index;
    	enableBashIntegration = true;
    	enableZshIntegration = true;    
    	};
 
# enable zsh system-wide use
users.defaultUserShell = pkgs.zsh;
# add a shell to /etc/shells
environment.shells = with pkgs; [ zsh ];
  programs.zsh = {
        enable  = true;
        enableCompletion = true; # enable zsh completion interactive zsh
        enableBashCompletion = true;
        enableLsColors = true;
        syntaxHighlighting.enable = true;   # enable zsh-syntax-highlighting
        autosuggestions.enable = true;      	# enable zsh-autosuggestions

    interactiveShellInit = ''
    # wird bei Initialisierung einer interaktiven Zsh-Shell ausgeführt.
        source ${pkgs.nix-index}/etc/profile.d/command-not-found.sh
        # test -f $ZDOTDIR/zshrc.zsh && source $ZDOTDIR/zshrc.zsh
                           '';
    promptInit = ''
           # [[ ! -f "$ZDOTDIR/prompt/p10k-fancy-v02.zsh" ]] || source "$ZDOTDIR/prompt/p10k-fancy-v02.zsh"
            # /share/zsh/prompt/basic-prompt.zsh
               '';
       histSize = 10000;
       histFile = "$ZDOTDIR/history/zhistory";
       setOptions = [        # see man 1 zshoptions
            "APPEND_HISTORY"       "INC_APPEND_HISTORY"
            "SHARE_HISTORY"        "EXTENDED_HISTORY"
            "HIST_IGNORE_DUPS"    "HIST_IGNORE_ALL_DUPS"
            "HIST_FIND_NO_DUPS"   "HIST_SAVE_NO_DUPS"
            "RM_STAR_WAIT"        "PRINT_EXIT_VALUE"
            "SH_WORD_SPLIT"       "CORRECT"
            "NOTIFY"          	  "INTERACTIVE_COMMENTS"
            "ALIAS_FUNC_DEF"      "EXTENDEDGLOB"
            "AUTO_CD"     	  "NOMATCH"       #   "no_global_rcs"
                        ]; };
}

You shouldn’t be using nix-env on NixOS, that’s what the config is for.

1 Like

I know nixos main feature as a declarative OS. This is why I use no Package Mgr and no Flake.
My SW adding workflow consists in try-before declaration. I like to test it, afterwards I paste packages into my enviroment package area in my configuration.nix
.

I’d suggest to use nix-shell, then.