Tried to “install” gh
(the GitHub CLI tool) with nix-shell
as I usually do with other commands but all my attempts failed. I tried these at first:
$ gh
The program ‘gh’ is currently not installed. You can install it by typing:
nix-env -iA nixos.gitAndTools.gh
$ nix-shell -p nixos.gitAndTools.gh
error: value is a function while a set was expected, at (string):1:94
(use '--show-trace' to show detailed location information)
$ nix-shell -p gh
error: undefined variable 'gh' at (string):1:94
(use '--show-trace' to show detailed location information)
$ nix-shell --show-trace -p gh
error: while evaluating the attribute 'buildInputs' of the derivation 'shell' at /nix/store/rvpdr9qywd7fsz624a5c255b5w5frpyd-nixos-20.09.3346.4d0ee90c6e2/nixos/pkgs/build-support/trivial-builders.nix:7:7:
while evaluating 'chooseDevOutputs' at /nix/store/rvpdr9qywd7fsz624a5c255b5w5frpyd-nixos-20.09.3346.4d0ee90c6e2/nixos/lib/attrsets.nix:475:22, called from undefined position:
undefined variable 'gh' at (string):1:94
The nix-env
command would install it without a hitch but I don’t like imperative Nix. I was able to get this to work simply by re-using an example from man nix-shell
nix-shell -E 'with import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/4d46cb67ad21c068b28618dfa0ffa6fa1aa8b057.tar.gz") { }; runCommand "dummy" { buildInputs = [ gitAndTools.gh ]; } ""'
but I wonder why the above nix-shell
commands failed?