Closed knedlsepp closed 7 years ago
You could replace /home/vagrant/.bashrc
with something like:
if [[ -z $PS1 ]]; then return; fi # for scp and friends
if [[ -z $IN_NIX_SHELL ]]; then exec nix-shell /vagrant; fi
# the usual stuff here
When the user runs vagrant ssh
it will log him into bash and automatically start nix-shell, which loads bash again but this time skips the second branch.
Thank you for the great solution!
Here is the finished Vagrantfile. I did use .profile
, because .bashrc
was not being used.
Vagrant.configure("2") do |config|
config.vm.box = "nixos/nixos-16.09-x86_64"
config.vm.provider "virtualbox" do |v|
v.memory = 4096
v.cpus = 2
end
config.vm.provision "shell", inline: <<-SHELL
mkdir ~vagrant/.nixpkgs
echo '{ allowUnfree = true; }' > ~vagrant/.nixpkgs/config.nix
echo 'if [[ -z $PS1 ]]; then return; fi # for scp and friends' >> ~vagrant/.profile
echo 'if [[ -z $IN_NIX_SHELL ]]; then exec nix-shell /vagrant/shell.nix; fi' >> ~vagrant/.profile
echo 'Done provisioning.'
SHELL
end
I'm in the situation that I have defined a "shell.nix" file inside one of my projects. I would like to be able to set up a
Vagrantfile
, which uses your nixbox and automatically drops you in anix-shell
for the specified file onvagrant up; vagrant ssh
. Is this use case possible using your nixbox?