-
Notifications
You must be signed in to change notification settings - Fork 615
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
limactl start assumes that /bin/bash is present on host #2110
Comments
SGTM |
We did something similar for FreeBSD already, it (optionally) has /usr/local/bin/bash but only features /bin/sh I am not sure if EDIT: From PR |
Thanks @afbjorklund! Those pointers helped a lot. Commit 5756e4c doesn't seem to have made it into the main branch, not sure where it ended up, but it looks the same as what I was thinking. I didn't really understand how Lima configured the host VMs, but now I've worked through the problems, I do. NixOS uses systemd, so that will work OK, but I now understand now that Lima creates an ISO file containing userdata: lima/pkg/hostagent/hostagent.go Line 134 in f3dc6ed
And that the ISO containing the userdata https://github.com/lima-vm/lima/blob/master/pkg/cidata/cidata.TEMPLATE.d/user-data gets mounted by running a script. The boot commands set in the user data are then able to use the files that are in the userdata ISO to configure the rest of the VM... and that's why the next command in the hostagent Of course, for NixOS, this won't happen, because NixOS doesn't have cloud-init enabled out of the box, hence why stage 2 just hung for me. To try to work around, I created a custom config for NixOS, and built an ISO from it. In Nix, you create a { config, pkgs, ... }: {
# Enable the OpenSSH server.
services.sshd.enable = true;
# Enable cloud-init, since Lima uses this to configure the instance.
services.cloud-init.enable = true;
users.users = {
adrian = {
isNormalUser = true;
openssh.authorizedKeys.keys = [
# This user comes from /Users/adrian/.lima/_config/user.pub
# This can be acquired progamatically with `limactl info | jq -r ".limaHome"`
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIChdmNxNN+sP9c/i3WYeG8cosR4x3krQYchRIZoEv8Mf [email protected]"
];
};
};
system.activationScripts.binbash = {
deps = [ "binsh" ];
text = ''
ln -s /bin/sh /bin/bash
'';
};
} But... it didn't work, because the CIDATA scripts assume a lot about the environment that they're going to be operating in.
And there's various failures logged about directories not existing:
And it tries to install the guest agent and fails for similar reasons.
Given the complexity of the scripts, I think it would be quite hard to debug them all on NixOS, then test that nothing has broken on all the other operating systems too, mostly because of how long it takes to go through a run/check cycle. I'm not sure if there's automated tests for each of the VM host types etc. To run NixOS in Lima, it probably makes the most sense to make a { config, pkgs, ... }: {
# Enable the OpenSSH server.
services.sshd.enable = true;
# Enable cloud-init, since Lima uses this to configure the instance.
services.cloud-init.enable = true;
# Configure packages required by Lima.
environment.systemPackages = [
pkgs.sshfs
];
environment.etc = {
"fuse.conf" = {
text = ''
user_allow_other
mount_max = 1000
'';
mode = "0777";
};
};
users.users = {
adrian = {
isNormalUser = true;
openssh.authorizedKeys.keys = [
# This user comes from /Users/adrian/.lima/_config/user.pub
# This can be acquired progamatically with `limactl info | jq -r ".limaHome"`
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIChdmNxNN+sP9c/i3WYeG8cosR4x3krQYchRIZoEv8Mf [email protected]"
];
};
};
system.activationScripts.binbash = {
deps = [ "binsh" ];
text = ''
ln -s /bin/sh /bin/bash
'';
};
} So, this issue is totally off track, and I guess I don't really care about |
We can can change from /bin/bash to /usr/bin/env bash for the agents anyway, it shouldn't hurt anything. |
@a-h : if you are making a NixOS template there was some previous discussion: There is a new But your |
@a-h did you check? #430 (comment) |
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:
lima/pkg/hostagent/requirements.go
Lines 97 to 102 in f3dc6ed
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:
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.
The text was updated successfully, but these errors were encountered: