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

Runtime selecting nixGL driver #132

Open
cfhammill opened this issue Apr 6, 2023 · 0 comments
Open

Runtime selecting nixGL driver #132

cfhammill opened this issue Apr 6, 2023 · 0 comments

Comments

@cfhammill
Copy link

I am currently using nixGL in a context where I will be provisioning docker containers that run machine learning code that may run on a variety of host systems. To accommodate this code I use to provision the container generates nixGLNvidia-<version> for a selection of different driver versions. I like the convenience of using nixGL instead of the full wrapper path, but becomes unwieldy if we don't know in advance which driver nixGL should point to. To work around it I have the following nix expression

{ pkgs }:

pkgs.writeTextFile rec {
  name = "nixGL";
  text = ''#!${pkgs.runtimeShell}

  vers=$(${pkgs.gnugrep}/bin/grep "Module" /proc/driver/nvidia/version |\
        ${pkgs.gnused}/bin/sed -E "s/.*Module  ([0-9.]+)  .*/\1/")
  if [ -z "$vers" ]; then
    echo "Failed to find your driver version"
    exit 1
  fi

  exec nixGLNvidia-"$vers" "$@"
  '';
  executable = true;
  destination = "/bin/${name}";
  checkPhase = ''
        ${pkgs.shellcheck}/bin/shellcheck "$out/bin/${name}"

        # Check that all the files listed in the output binary exists
        for i in $(${pkgs.pcre}/bin/pcregrep  -o0 '/nix/store/.*?/[^ ":]+' $out/bin/${name})
        do
          ls $i > /dev/null || (echo "File $i, referenced in $out/bin/${name} does not exists."; exit -1)
        done
      '';
}

which is essentially writeExecutable from nixGL with the text hard-coded to parse the module version and exec the correct nixGLNvidia wrapper.

Is there any interest in me contributing something like this to nixGL, if so any recommendations on how you would like it added?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant