"vboxmanage": executable file not found in $PATH

Hello

I’m trying to use nixos as a gitlab-runner with the virtualbox executor.

gitlab-runner seems to have “vboxmanage” hardcoded, however the name is “VBoxManage”, note the capitalization.

Is there a way to alias these, such that gitlab-runner can find “vboxmanage”?

I did try environment.shellAlias, but that didn’t work (I assume this is due to Golang’s os.exec not inheriting my aliases).

environment.systemPackages = [ (pkgs.writeScriptBin "vboxmanage" ''
  ${pkgs.virtualbox}/bin/VBoxManage "$@"
'')];

Hmm… while this does indeed add vboxmanage and i can use it from bash

$ which vboxmanage 
/run/current-system/sw/bin/vboxmanage
$ cat /run/current-system/sw/bin/vboxmanage
/nix/store/0lm00qy23ma2y91q8gj9w488jdjz0ygw-virtualbox-6.0.14/bin/VBoxManage "$@"

i can not use it from Go. Snippet below

package main

import "os/exec"
import . "fmt"

func main() {
    app := "vboxmanage"
    cmd := exec.Command(app)
    stdout, err := cmd.Output()
    if err != nil {
        Println(err.Error())
        return
    }
    Print(string(stdout))
}

returns fork/exec /run/current-system/sw/bin/vboxmanage: exec format error

while snippet below

package main

import "os/exec"
import . "fmt"

func main() {
    app := "VBoxManage"
    cmd := exec.Command(app)
    stdout, err := cmd.Output()
    if err != nil {
        Println(err.Error())
        return
    }
    Print(string(stdout))
}

returns expected output of Oracle VM VirtualBox Command Line Management Interface Version 6.0.14 [snip]

try changing writeScriptBin to writers.writeDashBin

With writers.writeDashBin it works :slight_smile: thank you!

Are these different wrappers docuemented somewhere that is not nix source code?

sadly not yet, I still haven’t managed to setup the documentation to write it :sweat_smile:

@lassulus, it turns out that while vboxmanage is available for my test program, it is not available to gitlab-runner.

I suspect this is due to systemctl show gitlab-runner.service | grep Environment | awk '{print $3}' not containing /run/current-system/sw/bin (possibly for security reasons?).

Either way i was thinking it would be more elegant to add vboxmanage=${pkgs.virtualbox} to the environment of gitlab-runner.service.

I played around with the solution to Override options of modules (documentation wanted) · Issue #16884 · NixOS/nixpkgs · GitHub but could not grasp it.

{lib, ...}:
{
  config = {
    systemd.services.gitlab-runner = {...}: {
      environment = /*something goes here*/ {
        apply = /*something else goes here*/
      };
    };
  };
}

EDIT: Another solution that comes to mind is a patch similar to https://github.com/NixOS/nixpkgs/blob/3e50e26e7d4c269bbbb33ce7f8b298b4b5477bca/pkgs/development/tools/continuous-integration/gitlab-runner/fix-shell-path.patch which would replace “vboxmanage” with “VBoxManage”. However, I do not know how to do this in Nix either.

Thoughts?

Solved with

    gitlab-runner = {
      enable = true;
      configFile = /etc/gitlab-runner/config.toml;
      packages = [ 
        pkgs.bash
        pkgs.docker-machine
        (pkgs.writers.writeDashBin "vboxmanage" ''
          ${pkgs.virtualbox}/bin/VBoxManage "$@"
        '')
        ];
    };