lima-vm / lima-vm/lima

limactl start assumes that /bin/bash is present on host

Open
#2,110 6 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
21.9k
Forks
957
Avg merge
2d 6h
Merged PRs (30d)
53

Description

### Description

I'm creating a NixOS template for Lima. NixOS doesn't follow the Linux FHS, so it doesn't have `bash` available at `/bin/bash`.

This is fine, because you can find find bash at `#!/usr/bin/env bash` instead. That way, you can get the version of bash that's installed in the current environment, rather than assuming bash exists in a specific location.

The issue is down to this: https://github.com/lima-vm/lima/blob/f3dc6ed97aa8f69821ecbe1c2b29988c97e67eb7/pkg/hostagent/requirements.go#L97-L102

At the top of the script is the shebang, which links directly to `/bin/bash`.

When starting a Lima VM, these scripts are executed, which I could see once I enabled verbose logging:

```
INFO[0053] [hostagent] Waiting for the essential requirement 1 of 5: "ssh"
DEBU[0053] [hostagent] executing script "ssh"
DEBU[0053] [hostagent] executing ssh for script "ssh": /usr/bin/ssh [ssh -F /dev/null -o IdentityFile="/Users/adrian/.lima/_config/user" -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o NoHostAuthenticationForLocalhost=yes -o GSSAPIAuthentication=no -o PreferredAuthentications=publickey -o Compression=no -o BatchMode=yes -o IdentitiesOnly=yes -o Ciphers="^aes128-gcm@openssh.com,aes256-gcm@openssh.com" -o User=adrian -o ControlMaster=auto -o ControlPath="/Users/adrian/.lima/nix-node/ssh.sock" -o ControlPersist=yes -p 63145 127.0.0.1 -- /bin/bash]
DEBU[0053] [hostagent] stdout="", stderr="bash: line 1: /bin/bash: No such file or directory\n", err=failed to execute script "ssh": stdout="", stderr="bash: line 1: /bin/bash: No such file or directory\n": exit status 127
```

From the logs, it's clear that it's trying to ssh and run `/bin/bash`, which doesn't exist on my system.

Looking into the reason why, I found that the sshocker package parses the shebang and attempts to use it: https://github.com/lima-vm/sshocker/blob/024e386607793c4d16867fe7c7ccc5fd38346330/pkg/ssh/ssh.go#L92C22-L92C44

I think that updating the shebangs to `#!/usr/bin/env bash` will work more reliably on platforms that don't support FHS.

Any interest in a PR on that?

In the meantime, I'm patching my NixOS system to have a symlink with the following NixOS configuration, which is getting me to stage 2.

```nix
system.activationScripts.binbash = {
deps = [ "binsh" ];
text = ''
ln -s /bin/sh /bin/bash
'';
};
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.