Skip to content

Added support of NixOS core tools in predict_threadable#5440

Merged
gforsyth merged 7 commits into
mainfrom
fix_nix
May 24, 2024
Merged

Added support of NixOS core tools in predict_threadable#5440
gforsyth merged 7 commits into
mainfrom
fix_nix

Conversation

@anki-code

Copy link
Copy Markdown
Member

Motivation

Closes #5003

The case

Core utils in Nix are symlinks to one binary file that contains all utils:

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 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. 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):

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

@anki-code anki-code requested a review from jnoortheen May 24, 2024 12:03
@anki-code anki-code requested a review from gforsyth May 24, 2024 13:03
@gforsyth gforsyth merged commit f582a33 into main May 24, 2024
@gforsyth gforsyth deleted the fix_nix branch May 24, 2024 20:51
anki-code added a commit that referenced this pull request Mar 5, 2026
In #5440 we had coreutils support. But in #6115 we introduced additional
logic for symlink resolving. This breaks `cat` and `yes` predictions (we
have True instead of False). So this PR has additional fixes for logic
and tests.


## For community
⬇️ **Please click the 👍 reaction instead of leaving a `+1` or 👍
comment**

---------

Co-authored-by: Andy Kipp <123@321.123>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
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

Successfully merging this pull request may close these issues.

NixOS: coreutils are not captured because unthredable

2 participants