nix-gl-host
nix-gl-host copied to clipboard
cannot pass ARGS to NIX_BINARY if args starts with dash
Describe the bug
nixglhost -h the CLI help says
positional arguments:
NIX_BINARY Nix-built binary you'd like to wrap.
ARGS The args passed to the wrapped binary.
I take it that ARGS is passed to NIX_BINARY, but this is not the case:
[nix-shell:~/work/nix-expression-test]$ date
Mon Aug 12 10:24:48 CST 2024
[nix-shell:~/work/nix-expression-test]$ date -u
Mon Aug 12 02:24:52 UTC 2024
[nix-shell:~/work/nix-expression-test]$ nixglhost date
Mon Aug 12 10:24:56 CST 2024
[nix-shell:~/work/nix-expression-test]$ nixglhost date -u
usage: nixglhost [-h] [-d DRIVER_DIRECTORY] [-p | --print-ld-library-path | --no-print-ld-library-path] [NIX_BINARY] [ARGS ...]
nixglhost: error: unrecognized arguments: -u
[nix-shell:~/work/nix-expression-test]$ nixglhost echo hello world
hello world
To Reproduce
use this shell.nix file (also pasted verbatim below)
{ pkgs ? import <nixpkgs> {
config = {
allowUnfree = true;
cudaSupport = true;
};
} }:
let
nixglhost-sources = pkgs.fetchFromGitHub {
owner = "numtide";
repo = "nix-gl-host";
rev = "main";
# Replace this with the hash Nix will complain about, TOFU style.
hash = "sha256-IDDkwDetQ/a5U2WzlGbLD6i/K++9moKQdpIJP3QEg4I=";
};
nixglhost = pkgs.callPackage "${nixglhost-sources}/default.nix" { };
in pkgs.mkShell {
nativeBuildInputs = with pkgs.buildPackages; [
nixglhost
python3 # pin: python311
cudaPackages.cudatoolkit # pin: cudaPackages_12.cudatoolkit
python3Packages.pytorch-bin # pin: python311Packages.pytorch-bin
python3Packages.pip # pin: python311Packages.pip
];
shellHook = ''
export CUDA_PATH=${pkgs.cudatoolkit}
# nixglhost discourages `nixglhost -p`, though as of this writing,
# its support for passing arguments in CLI is not working as expected
export LD_LIBRARY_PATH=$(nixglhost -p):${pkgs.stdenv.cc.cc.lib}/lib''${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}
alias run-sanity-test='python -c "import torch; print(torch.cuda.is_available())"'
'';
}
Expected behavior
dash arguments should get passed as-is
System information
$ nix-shell -p nix-info --run 'nix-info -m'
- system: `"x86_64-linux"`
- host os: `Linux 6.5.0-44-generic, Ubuntu, 22.04.3 LTS (Jammy Jellyfish), nobuild`
- multi-user?: `yes`
- sandbox: `yes`
- version: `nix-env (Nix) 2.17.0`
- channels(root): `"nixpkgs"`
- nixpkgs: `/home/tutankalex/.nix-defexpr/channels/nixpkgs`
Additional context
ok, checked the nixglhost source before submitting, and realize this is due to
parser.add_argument(
"ARGS",
type=str,
nargs="*",
help="The args passed to the wrapped binary.",
default=None,
)
as a result, it is possible to send in arguments via
$ nixglhost -- date -u
Mon Aug 12 02:36:10 UTC 2024
but apparently if you change that block to
parser.add_argument(
"ARGS",
nargs=argparse.REMAINDER,
help="The args passed to the wrapped binary.",
default=None,
)
it appears to work "as expected"
$ nixglhost date -u
Mon Aug 12 02:36:43 UTC 2024
this syntax is breaking behavior, but is consistent with the help message as well as nixGL.