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

nixos/test-driver: Specify /bin/sh shell when running a bourne shell script as the user #87414

Conversation

chkno
Copy link
Member

@chkno chkno commented May 9, 2020

Motivation for this change

The test harness provides the commands it wishes to run in Bourne syntax. This fails if the user uses a different shell. For example, with fish:

machine.wait_for_unit("graphical-session.target", "alice")

results in

machine # fish: Unsupported use of '='. To run '-u`' with a modified environment, please use 'env XDG_RUNTIME_DIR=/run/user/`id -u`…'
machine # XDG_RUNTIME_DIR=/run/user/`id -u` systemctl --user --no-pager show "graphical-session.target"
machine # ^
machine # [   16.329957] su[1077]: pam_unix(su:session): session closed for user alice
error: retrieving systemctl info for unit "graphical-session.target" under user "alice" failed with exit code 127
Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.

@tfc

…script as the user

The test harness provides the commands it wishes to run in Bourne
syntax.  This fails if the user uses a different shell.  For example,
with fish:

  machine.wait_for_unit("graphical-session.target", "alice")

machine # fish: Unsupported use of '='. To run '-u`' with a modified environment, please use 'env XDG_RUNTIME_DIR=/run/user/`id -u`…'
machine # XDG_RUNTIME_DIR=/run/user/`id -u` systemctl --user --no-pager show "graphical-session.target"
machine # ^
machine # [   16.329957] su[1077]: pam_unix(su:session): session closed for user alice
error: retrieving systemctl info for unit "graphical-session.target" under user "alice" failed with exit code 127
@tfc
Copy link
Contributor

tfc commented May 10, 2020

Defining the shell makes a lot of sense, but i would prefer explicitly pointing to a specific shell instead of assuming /bin/sh. Can you make it like --shell ${shellpackage-that-is-used-everywhere-already}/bin/sh?

@tfc tfc requested a review from flokli May 10, 2020 11:37
@flokli
Copy link
Contributor

flokli commented May 10, 2020

We can assume /bin/sh to be around, and as we don't explicitly use any bashisms, this seems to be the right way to do this.

@7c6f434c
Copy link
Member

Is this expected to be runnable interactively? If yes, #1424 might probably apply if the terminal emulator is used inside a graphical session with OpenGL.

@flokli
Copy link
Contributor

flokli commented May 10, 2020

@7c6f434c this /bin/sh is only used as a shell for su, to then execute systemctl --user in a non-interactive fashion.

@7c6f434c
Copy link
Member

7c6f434c commented May 10, 2020 via email

@flokli
Copy link
Contributor

flokli commented May 11, 2020

I'm still not sure if I understand the question correctly, sorry.

So far, the Machine.execute method (which is used under the hood) isn't able to be used interactively, also when using the interactive ptpython REPL.

@7c6f434c
Copy link
Member

7c6f434c commented May 11, 2020 via email

@flokli
Copy link
Contributor

flokli commented May 11, 2020

@7c6f434c so you now agree with the changes proposed here?

@7c6f434c
Copy link
Member

7c6f434c commented May 11, 2020 via email

@flokli flokli merged commit b12c08c into NixOS:master May 11, 2020
@flokli
Copy link
Contributor

flokli commented May 11, 2020

Thanks!

@jonringer jonringer added the 8.has: port to stable A PR already has a backport to the stable release. label Jul 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants