How to install nix on google colab

cross posted here: How to install nix on google colab - Stack Overflow

I’m trying to install Nix on Google colab because of a Python package that has dependencies outside of pip.

The installation seems to work but commands such as nix-shell or nix-daemon do not work. It seems like there is something about starting a new terminal before using Nix but I do not know how to do that with google colab.


You might just need to source the shell hook. What shell does collab use? If it’s bash, you might just be able to source /etc/bashrc (or whichever rc file nix installed itself to).

(The installer tells you to restart the shell because that’s easier than explaining how to know what to source again, how to deal with rc files that are guarded against double execution, etc.)

Hi thank you @abathur ,

I think it uses bash. I am not sure what sourcing a shell hook means but I asked chatgpt about your comment and it told me that you are suggesting that I use the command

. /etc/bashrc

Is that correct ?

1 Like

Sorry, I was typing on a phone keyboard where formatting is ~hard. Assuming /etc/bashrc exists and you see references to Nix in it, you can run source /etc/bashrc or . /etc/bashrc (they are equivalent).



In a google colab cell (%%shell is used to consider the cell to be a shell command)


source /etc/bashrc

which nix-shell

resulted in /root/.nix-profile/bin/nix-shell so it seems to work but ei got errors trying to install the package that I wanted to use.

The command below mentioned around the end of the installation also seems to work.


source /etc/bashrc
nix-shell -p nix-info --run "nix-info -m"
1 Like

So, what errors are you getting? Could you post the full terminal output?

1 Like