Skip to content
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

libvirt hooks run without bash context #98448

Open
adamlwgriffiths opened this issue Sep 22, 2020 · 7 comments
Open

libvirt hooks run without bash context #98448

adamlwgriffiths opened this issue Sep 22, 2020 · 7 comments
Labels
0.kind: bug 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md

Comments

@adamlwgriffiths
Copy link
Contributor

adamlwgriffiths commented Sep 22, 2020

Describe the bug
This bug is partially related to #51152, in that a declarative method of adding the hooks would solve this.

Hooks (eg /var/lib/libvirt/hooks/qemu) normally start with #!/usr/bin/env bash.
It seems this isn't valid within the libvirt context and causes the hook execution - and therefore the vm - to fail.

Instead I have had to work around this by using #!/run/current-system/sw/bin/bash.

To Reproduce
Steps to reproduce the behavior:

  1. Copy hook script from here https://github.com/PassthroughPOST/VFIO-Tools/blob/master/libvirt_hooks/qemu to /var/lib/libvirt/hooks/qemu
  2. sudo systemctl restart libvirtd.service
  3. Run a VM
  4. VM fails with an error

Expected behavior
VM starts without error

Screenshots
image

Additional context

  • Using #!/usr/bin/env bash does not fix the issue
  • Using #!/run/current-system/sw/bin/bash does fix the issue.

This also applies to all hook scripts that are in turn executed by the hook itself.
Eg. qemu.d/<vm>/prepare/begin/start.sh.

Notify maintainers
@fpletz

Metadata
$ nix-shell -p nix-info --run "nix-info -m"

  • system: "x86_64-linux"
  • host os: Linux 5.4.62, NixOS, 20.03.2913.4bd1938e03e (Markhor)
  • multi-user?: yes
  • sandbox: yes
  • version: nix-env (Nix) 2.3.6
  • channels(root): "home-manager-20.03, nixos-20.03.2913.4bd1938e03e"
  • nixpkgs: /nix/var/nix/profiles/per-user/root/channels/nixos

Maintainer information:

# a list of nixpkgs attributes affected by the problem
attribute: libvirt
# a list of nixos modules affected by the problem
module:
@cole-h
Copy link
Member

cole-h commented Sep 25, 2020

FWIW, I work around this by simply excluding the shebang(s):

https://github.com/cole-h/nixos-config/blob/69c1a768b210c3b8e29075a8c53ce741f475c0b9/hosts/scadrial/modules/libvirt/default.nix#L4

Not really a solution, but a(nother) workaround for the time being.

@stale
Copy link

stale bot commented Mar 26, 2021

I marked this as stale due to inactivity. → More info

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Mar 26, 2021
@adamlwgriffiths
Copy link
Contributor Author

Still important to me

@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Mar 29, 2021
@tgharib
Copy link
Contributor

tgharib commented Aug 14, 2021

I just came across the same issue. Thank you cole-h for the reference nix configuration.

@cole-h
Copy link
Member

cole-h commented Aug 14, 2021

FWIW, I've slightly changed how I do this: https://github.com/cole-h/nixos-config/blob/61d17a3355288872e4b765ddce1700654a9accc8/hosts/scadrial/modules/libvirt/default.nix#L5-L16

@adamlwgriffiths
Copy link
Contributor Author

Thanks @cole-h, I didn't realise modprobe would also be unavailable to my hooks.
I've now gotten them working with the following mod from your linked nix files.
Super awesome, since I've been trying to get this working for over a year.

  systemd.services.libvirtd = {
    path = let
      env = pkgs.buildEnv {
        name = "qemu-hook-env";
        paths = with pkgs; [
          bash
          libvirt
          kmod
          systemd
        ];
      };
    in [ env ];
  };

@stale
Copy link

stale bot commented Apr 19, 2022

I marked this as stale due to inactivity. → More info

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Apr 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0.kind: bug 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md
Projects
None yet
Development

No branches or pull requests

3 participants