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

cannot pass in spaces with --add-flags with makeBinaryWrapper #330471

Open
MrQubo opened this issue Jul 27, 2024 · 7 comments
Open

cannot pass in spaces with --add-flags with makeBinaryWrapper #330471

MrQubo opened this issue Jul 27, 2024 · 7 comments
Labels
0.kind: bug Something is broken

Comments

@MrQubo
Copy link
Contributor

MrQubo commented Jul 27, 2024

Describe the bug

It seems it's impossible to pass argument that contains space with makeBinaryWrapper. With makeShellWrapper it's possible with --add-flags '"a b"'. But makeBinaryWrapper splits it as two arguments "a and b".

User @gerg-l:matrix.org on matrix proposed to add --add-flag to bypass split by space on --add-flags.
I'm guessing it might be @Gerg-L?

Steps To Reproduce

I've made a derivation for testing:

default.nix
{ stdenv, writeTextFile, makeBinaryWrapper  }:

stdenv.mkDerivation {
  name = "example";

  src = writeTextFile {
    name = "example.c";
    text = ''
      #include <stdio.h>

      int main(int argc, const char const * argv[])
      {
        for (int i = 0; i < argc; i += 1) {
          puts(argv[i]);
        }
      }
    '';
  };
  dontUnpack = true;

  nativeBuildInputs = [ makeBinaryWrapper ];

  buildPhase = ''
    gcc $src -o example
  '';

  installPhase = ''
    install -D example -t $out/bin/
    wrapProgram $out/bin/example --add-flags '"a b"'
  '';

}
shell.nix
with import <nixpkgs> {};

let
  example = pkgs.callPackage ./default.nix {};

in
pkgs.mkShell {
  packages = [ example ];
}

Run with nix-shell --run example.

Expected behaviour

It should be possible to add/append spaces as arguments to wrapped program.

Notify maintainers


Add a 👍 reaction to issues you find important.

@MrQubo MrQubo added the 0.kind: bug Something is broken label Jul 27, 2024
@Gerg-L
Copy link
Contributor

Gerg-L commented Jul 27, 2024

Yup it was me

@eclairevoyant
Copy link
Contributor

Basically this is a limitation when we don't use __structuredAttrs.
See #114044 for a similar issue.

@MrQubo
Copy link
Contributor Author

MrQubo commented Jul 27, 2024

Hmm, we could add --add-flag as a workaround for now, but maybe it's better to wait for #318614.

@eclairevoyant
Copy link
Contributor

Can you give an example of why this would be useful?

@MrQubo
Copy link
Contributor Author

MrQubo commented Jul 27, 2024

Whenever you need to overwrite some cli arguments and those arguments contain spaces.
E.g. of arguments that could contain spaces are space-delimited lists or shell commands.

@Gerg-L
Copy link
Contributor

Gerg-L commented Jul 27, 2024

Basically this is a limitation when we don't use __structuredAttrs

i don't understand how __structuredAttrs would matter at all here
maybe when using wrapGAppsHook or similar, but not when using raw wrapProgram in the postInstall

@MrQubo
Copy link
Contributor Author

MrQubo commented Jul 27, 2024

You're right, it doesn't matter for the current implementation. Though, with structuredAttrs we could implement makeWrapper differently, using derivation arguments. E.g.

stdenv.mkDerivation {
...
wrapPrograms = [
  {
    path = "bin/example";
    addFlags = [ "--cmd" "foo bar" ];
  }
];
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0.kind: bug Something is broken
Projects
None yet
Development

No branches or pull requests

3 participants