Skip to content

fix: preserve Nix Ruby in init wrapper#116

Open
pcasaretto wants to merge 1 commit into
tobi:mainfrom
pcasaretto:fix/nix-init-shebang
Open

fix: preserve Nix Ruby in init wrapper#116
pcasaretto wants to merge 1 commit into
tobi:mainfrom
pcasaretto:fix/nix-init-shebang

Conversation

@pcasaretto
Copy link
Copy Markdown
Contributor

@pcasaretto pcasaretto commented May 17, 2026

Problem

The Nix/Home Manager install path generated a broken shell function from try init.

try needs to install a shell function because a subprocess cannot cd the parent shell. That function captures try exec output and evals it.

Before this change, the generated function invoked the Ruby script explicitly through the ambient Ruby:

out=$(/usr/bin/env ruby '/nix/store/.../bin/.try-wrapped' exec ...)

For Nix builds, wrapProgram installs:

bin/try          # wrapper that sets PATH to include Nix Ruby
bin/.try-wrapped # actual Ruby script

When try init runs under that wrapper, $0 resolves to the internal .try-wrapped script. The emitted shell function therefore bypasses bin/try, which means it also bypasses the Nix-provided Ruby. On macOS this falls back to the system Ruby, which is too old for the current code and fails at runtime.

In short:

works:  bin/try -> Nix Ruby -> Ruby script
breaks: /usr/bin/env ruby -> .try-wrapped

Fix

This removes the wrapper layer from the Nix package and makes the generated shell function call the resolved executable directly.

Changes:

  • try init now emits direct executable calls:

    out=$('/path/to/try' exec ...)

    instead of:

    out=$(/usr/bin/env ruby '/path/to/try' exec ...)
  • The Nix derivation no longer uses wrapProgram.

  • The Nix derivation patches the installed script shebang to the packaged Ruby:

    #!/nix/store/...-ruby-3.3.x/bin/ruby

As a result, the Nix package contains a single public executable script:

bin/try

There is no .try-wrapped, no package-specific logic in the Ruby code, and the shell integration preserves the executable selected by the installer/package manager.

Tests

nix build .
./spec/tests/runner.sh ./result/bin/try

Result:

388/388 passed

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.

1 participant