-
-
Notifications
You must be signed in to change notification settings - Fork 631
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: coreutils are not captured because unthredable #5003
Comments
Might be that something in https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/programs/xonsh.nix (maybe in everything that gets |
Actually, the xonshrc defined in this module is not loaded by default without NixOS/nixpkgs#204252, which was merged a few hours ago and is not yet in nixos-unstable (though will be landed very soon). I can reproduce the same behavior no matter whether /etc/xonshrc is loaded, so I don't think this issue is related to the NixOS module. |
Thanks @SamLukeYes -- that at least rules out a bunch of things that would be very annoying to check. The only thing left that I can think of is that we're getting some behavior from |
This issue is specific to the
I get the expected output. I think the cause of this issue is that xonsh thinks Lines 747 to 761 in bcf2592
I can also reproduce this issue on Fedora by running
The |
Is it right that |
I'm not sure if I'm doing it right, but I observe this on my NixOS: $ import xonsh
$ xonsh.commands_cache.CommandsCache($(env)).predict_threadable('cat')
True
$ xonsh --version
xonsh/0.15.1
The default |
@SamLukeYes thank you for the answer! I'm not the NixOS user but I can help to investigate the difference because past time I spent to improving threading in xonsh. Could you please give me the list of commands that install xonsh from the main branch in nix docker i.e. docker run --rm -it nixos/nix:2.3.16 /bin/sh
# install python and vim
# run `pip install git+https://github.com/xonsh/xonsh`
xonsh After this I can understand what is the difference. |
I'm not familiar with podman/docker and have trouble accessing the internet inside the container, probably because of my proxy setting. Anyway, I managed to reproduce this issue in a conda environment on NixOS, with the latest xonsh. $ nix-shell -p conda vim --run conda-shell
$ conda-install # may be needed before using conda for the first time
$ conda create -n test 'python<3.12'
$ conda activate test
$ pip install git+https://github.com/xonsh/xonsh
$ xonsh --version
xonsh/0.16.0.dev111
$ xonsh
$ !(echo hi) == 'hi\n'
hi
False |
Thank you for instructions! I tried to install conda in docker but have fail without any instructions in the net of how to do it right. Sorry. docker run --rm -it nixos/nix bash
nix-shell -p conda vim --run conda-shell
# building '/nix/store/253kppj13kr016xfdyg2iw0xwiriml2h-conda-shell.drv'...
# bwrap: Creating new namespace failed: Operation not permitted But after this I found that docker run --rm -it nixos/nix bash
nix-shell -p micromamba
export MAMBA_ROOT_PREFIX=/myenv
# export MAMBA_SSL_NO_REVOKE=true
micromamba create -n myenv python=3.11 -c conda-forge
# error libmamba No CA certificates found on system |
It's interesting because I'm using gnu coreutils on mac and have no issues. We need to investigate the NixOS case. Side thought: is it possible to you to install coreutils from brew on NixOS and test it with xonsh? (optionally) To be honest it's my first time of working with NixOS. |
If using nix what does running the nixpklgs version do e.g. Unfortunately my nix is rather deeply embedded so can't give a simple case. These are just observations. I don't understand docker either - although I would note anything using docker is running linux even if running from a mac. I have xonsh installed via a nix flake on a mac mini apple silicon and I get (and also via nix run
I would note that - the docker line I think is an old nix version
xonsh question - Why don't I get hi printed out However as I ran xonsh (but xonsh --no-rc works) from an existing shell I get
I would note that I have a possibly related issue with a third party program which behave differently if xonsh is the login shell or is run from another shell - in this case the latter is the bit that works) |
@SamLukeYes -- we've started stripping newlines from the end of single-line commands, what's the output of !(echo hi) == "hi" ? |
$ !(echo hi) == 'hi'
hi
False Still the same 😕 |
@SamLukeYes can you help me with this - #5003 (comment)? |
The issue was because I use a local http proxy. Passing Also, I found venv works inside the container: $ nix-shell -p python3
$ python3 -m venv venv
$ source venv/bin/activate And then you can use pip :)
AFAIK, the docker image |
I can reproduce this! Many thanks @SamLukeYes! docker run --rm -it nixos/nix bash
nix-shell -p python3
python3 -m venv venv
source venv/bin/activate
pip install git+https://github.com/xonsh/xonsh
xonsh
$XONSH_TRACE_SUBPROC=2
!(echo 1)
# Trace run_subproc({'cmds': (['echo', '1'],), 'captured': 'object'})
# 0: {'cmd': ['echo', '1'], 'cls': 'subprocess.Popen', 'bin': '/nix/store/k6h0vjh342kqlkq69sxjj8i5y50l6jfr-coreutils-9.3/bin/echo', 'thread': False, 'bg': False}
# 1
# CommandPipeline(
# returncode=0,
# pid=233,
# args=['echo', '1'],
# executed_cmd=['echo', '1'],
# timestamps=[1716484360.5753396, 1716484360.5851793],
# input='',
# output=''
# )
__xonsh__.commands_cache.predict_threadable(['echo'])
# False And |
@SamLukeYes please take a look: docker run --rm -it nixos/nix bash
nix-shell -p python3
python3 -m venv venv
source venv/bin/activate
pip install git+https://github.com/xonsh/xonsh@fix_nix # @fix_nix
xonsh
!(echo Nix is nice)
# CommandPipeline(
# returncode=0,
# pid=148,
# args=['echo', 'Nix', 'is', 'nice'],
# executed_cmd=['echo', 'Nix', 'is', 'nice'],
# timestamps=[1716552319.09322, 1716552319.1041143],
# input='',
# output='Nix is nice'
# ) The full case described in PR #5440. |
I can confirm this works in a venv on NixOS. However, in a conda-shell environment, the output is still like this:
I noticed that |
Oh, I missed an important point. In fact, coreutils is directly added to $ which echo
/run/current-system/sw/bin/echo
$ nix-shell -p --run 'which echo'
/nix/store/php4qidg2bxzmm79vpri025bqi0fa889-coreutils-9.5/bin/echo When I start a nix-shell before running xonsh in the conda environment, the expected output can be seen.
|
Thanks! But you highlighted the issue with symlink chain. I'm working on adding resolving symlink chains. |
@SamLukeYes please test this case with symlink chain again. I've updated branch |
### Motivation Closes #5003 ### The case Core utils in Nix are symlinks to one binary file that contains all utils: ```xsh docker run --rm -it nixos/nix bash which echo # /nix/store/k6h0vjh342kqlkq69sxjj8i5y50l6jfr-coreutils-9.3/bin/echo ls -la /nix/store/k6h0vjh342kqlkq69sxjj8i5y50l6jfr-coreutils-9.3/bin/ # b2sum -> coreutils # base32 -> coreutils # ... # All tools are symlinks to one binary file - `coreutils`. ``` When [`default_predictor_readbin`](https://github.com/xonsh/xonsh/blob/61bda708c992a300eab212f877718cf0050a5e3a/xonsh/commands_cache.py#L392) read `coreutils` it catches `(b'isatty', b'tcgetattr', b'tcsetattr')` and return `threadable=False` forever. The list of Nix coreutils tools are exactly the same as in [brew coreutils](https://formulae.brew.sh/formula/coreutils). So I can check the real predicts on distinct binaries and see that only 2 tools among 106 are unthreadable and they already covered by `default_threadable_predictors` (If it's wrong please add unthreadable tools to the [default_threadable_predictors](https://github.com/xonsh/xonsh/blob/61bda708c992a300eab212f877718cf0050a5e3a/xonsh/commands_cache.py#L518)): ```xsh brew install coreutils ls /opt/homebrew/opt/coreutils/libexec/gnubin/ | wc -l # 106 for t in p`/opt/homebrew/opt/coreutils/libexec/gnubin/.*`: if not (th := __xonsh__.commands_cache.predict_threadable([t.name])): print($(which @(t.name)), th) # /opt/homebrew/opt/coreutils/libexec/gnubin/cat False # /opt/homebrew/opt/coreutils/libexec/gnubin/yes False defaults = __import__('xonsh').commands_cache.default_threadable_predictors().keys() defaults['cat'] # <function xonsh.commands_cache.predict_false> defaults['yes'] # <function xonsh.commands_cache.predict_false> ``` So the rest of we need is to check the symlink and apply default prediction if the tools is the symlink to coreutils. This implements this PR. Test included. ## For community ⬇️ **Please click the 👍 reaction instead of leaving a `+1` or 👍 comment** --------- Co-authored-by: a <1@1.1> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
### Motivation * We have no recommended way to force subprocess command be (un)threadable * #4214 * #2119 * #5003 * It's interesting opportunity to have a way to modify specs and CP using `SpecModifierAlias`. ### Before ```xsh !(ssh host -T "echo 1") # output='' # EXPECTED: 1 __xonsh__.commands_cache.threadable_predictors['ssh'] = lambda *a, **kw: True !(ssh host -T "echo 1") ``` ### After ```xsh xthread # Mark command as threadable. !(xthread ssh host -T "echo 1") # output='1' ``` Closes: * Closes #4214 * Closes #2119 * Partially closes #5003 Implementation of `SpecModifierAlias` will help in: * #2618 JFYI #5413 ## For community ⬇️ **Please click the 👍 reaction instead of leaving a `+1` or 👍 comment** --------- Co-authored-by: a <1@1.1> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Gil Forsyth <gforsyth@users.noreply.github.com>
Originally posted by @amacfie in #4214 (comment):
On Debian/Arch:
But on NixOS:
For community
⬇️ Please click the 👍 reaction instead of leaving a
+1
or 👍 commentThe text was updated successfully, but these errors were encountered: