Some question about nix-channel git commit version and packages

  1. Is there any benefit using nix-channel than git clone [nixpkgs-unstable github repository](https://github.com/NixOS/nixpkgs-channels)?
    -> well, i think if cloning, i can’t use cache.nixos.org… and can’t find nix expression like <nixpkgs>… and anything else?

  2. when i nix-env -u <package>, for instance, openjdk8u is upgraded to openjdk11 not latest cache’s openjdk8u. how can i upgrade package to latest cache’s pre-built binary?

If you are using NixOS, nix channels are, I think, the driver of interactions like this,

$ lsof
The program ‘lsof’ is currently not installed. It is provided by
several packages. You can install it by typing one of the following:
  nix-env -iA nixos.busybox
  nix-env -iA nixos.lsof

That is, a missing executable is tied to a package name (which I typically pull in with nix-shell, rather than nix-env). I find this quite handy, so even though my NIX_PATH points to a normal git clone, I still have a channel set up just for this feature.

1 Like

This is amazing! But it seems to only work in bash by default. If I prefer to use zsh as my shell, do you know how I can enable this feature there?

I just tested on my NixOS machine and I don’t get this behavior even in bash.

> bash -l
$ lsof
lsof: command not found

$

Do I have to do something to enable this?

Good question, I hope someone can weigh in. As far as I can remember, I didn’t do anything to enable that feature, but my NixOS system was installed a long time ago…

Should be on by default.

Ryan

Ah, I do have that enable flag set to true, which explains why it works in bash. Any idea why it may not be working for me in zsh?

Thanks!

This might happen if you’re on the nixpkgs channel instead of the nixos one. Check if this file exists:

/nix/var/nix/profiles/per-user/root/channels/nixos/programs.sqlite

Looks like it’s on for me, it’s just that the database doesn’t contain lsof. If I try e.g. gifasm then it works. Pretty weird that my /nix/var/nix/profiles/per-user/root/channels/nixos/programs.sqlite doesn’t list lsof.

You can also use nix-index which gives you a little more control over how the db is generated:

$ nix-env -iA nixpkgs.nix-index
$ nix-index

then adding this to your profile:

source $HOME/.nix-profile/etc/profile.d/command-not-found.sh

You can also do some neat things with the programs.sqlite table. For instance, get all of the 3 letter commands in Nixpkgs:

nix run nixpkgs.sqlite -c sqlite3 /nix/var/nix/profiles/per-user/root/channels/nixos/programs.sqlite 'select * from programs where length(name) = 3 and system = "x86_64-linux";'

BTW, I figured out how to get this working in zsh. It’s just a matter of invoking command-not-found when the shell detects that a command failed, which is done by defining the command_not_found_handler function in zsh:

function command_not_found_handler () {
    command-not-found "$1"
}

For me it works in fish, too.
And you don’t even need a channel.

I have nixpkgs pinned for my system and make command-not-found work with this configuration: programs.command-not-found.dbPath = "${pinnedNixpkgs.src}/programs.sqlite";.

Note that you can’t use the git tree, you have to use the tarball from https://releases.nixos.org/nixos/unstable/${channelRelease}/nixexprs.tar.xz