Error with terminfo when running bash with nix run on NixOS

I’m trying to run bash with nix run on NixOS.

I’m using a command like this:

$ nix run nixpkgs.bash

I end up with a mostly-working bash, but some things are not working, like ansi-escape sequences and keyboard arrow keys.

In my normal bash login shell, I have a bash prompt that looks like the following:

me@my-hostname /some/path $

However, when I am the shell from nix run nixpkgs.bash, the ansi escape sequences don’t look like they are quite working. Here is what it looks like:

\[\]me\[\]@\[\]my-hostname \[\]/some/path \[\]$ \[\]

Also, when I am in the shell from nix run nixpkgs.bash, pressing an arrow key produces an escape on the screen like ^[[C, ^[[B, ^[[D, or ^[[A.


I assume this is a problem with terminfo, but I can’t figure out what could be going on. In both my normal shell, and my shell under nix run, I have the two environment variables set:

TERM=xterm-256color
TERMINFO_DIRS=/home/me/.nix-profile/share/terminfo:/etc/profiles/per-user/me/share/terminfo:/nix/var/nix/profiles/default/share/terminfo:/run/current-system/sw/share/terminfo

I’ve found the following thread talking about problems with terminfo stuff, but none of the solutions seemed to do anything for me (which makes sense, since it is about zsh…):

https://github.com/NixOS/nixpkgs/issues/19785


I should add that I don’t see this problem with nix-shell -p bash (although this is somewhat expected, since nix run and nix-shell are pretty different).

Also, here is my ~/.bashrc file, although I don’t think it is particularly related:

edit: Oh, and this is all on nixos-19.09:

  • system: "x86_64-linux"
  • host os: Linux 4.19.84, NixOS, 19.09.1300.08e503bac6d (Loris)
  • multi-user?: yes
  • sandbox: yes
  • version: nix-env (Nix) 2.3
  • channels(root): "nixos-19.09.1300.08e503bac6d"
  • channels(illabout): "unstable-20.03pre202088.e89b21504f3"
  • nixpkgs: /nix/var/nix/profiles/per-user/root/channels/nixos

remember there’s a difference between bash and bashInteractive package.

Ah, that makes sense :slight_smile: Thanks!

This worked as expected:

$ nix run nixpkgs.bashInteractive

In case anyone finds this and is interested in what is going on, bash and bashInteractive are defined similarly in all-packages.nix:

https://github.com/NixOS/nixpkgs/blob/b3729ae77f5bd3f011bd8e9784b21b5824d8d91c/pkgs/top-level/all-packages.nix#L7649

https://github.com/NixOS/nixpkgs/blob/b3729ae77f5bd3f011bd8e9784b21b5824d8d91c/pkgs/top-level/all-packages.nix#L7656-L7660

If the bash derivation gets passed the interactive flag, it gets compiled with readline support: