pkgxdev / homebrew-made

brew install pkgxdev/made/pkgx
Apache License 2.0
29 stars 6 forks source link

Brew install pkgx errors with "please install unzip" (because of deno) #4

Closed fredrikaverpil closed 6 months ago

fredrikaverpil commented 6 months ago

Problem description

I just noticed, that while on WSL (Ubuntu) and using linuxbrew, running brew install pkgx yields the following error, so I figured I'd report it here:

❯ brew install pkgx
==> Auto-updating Homebrew...
Adjust how often this is run with HOMEBREW_AUTO_UPDATE_SECS or disable with
HOMEBREW_NO_AUTO_UPDATE. Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
==> Fetching pkgxdev/made/pkgx
==> Downloading https://github.com/pkgxdev/pkgx/releases/download/v1.1.6/pkgx-1.1.6.tar.xz
Already downloaded: /home/fredrik/.cache/Homebrew/downloads/c8b2441dfddcbd6b0ef34fb1621836e46340e44576acd184a9e0bca2a45121cd--pkgx-1.1.6.tar.xz
==> Installing pkgx from pkgxdev/made
==> deno task compile
Last 15 lines from /home/fredrik/.cache/Homebrew/Logs/pkgx/01.deno:
Download https://deno.land/std@0.196.0/yaml/_type/regexp.ts
Download https://deno.land/std@0.196.0/yaml/_type/seq.ts
Download https://deno.land/std@0.196.0/yaml/_type/set.ts
Download https://deno.land/std@0.196.0/yaml/_type/str.ts
Download https://deno.land/std@0.196.0/yaml/_type/timestamp.ts
Download https://deno.land/std@0.196.0/yaml/_type/undefined.ts
Download https://registry.npmjs.org/@faker-js/faker/-/faker-8.1.0.tgz
Download https://registry.npmjs.org/@types/node/-/node-18.16.19.tgz
Check file:///tmp/pkgx-20240407-4211-1mb6el/pkgx-1.1.6/entrypoint.ts
Compile file:///tmp/pkgx-20240407-4211-1mb6el/pkgx-1.1.6/entrypoint.ts to /tmp/pkgx-20240407-4211-1mb6el/pkgx-1.1.6/pkgx
Download https://dl.deno.land/release/v1.42.1/denort-x86_64-unknown-linux-gnu.zip
error: Writing /tmp/pkgx-20240407-4211-1mb6el/pkgx-1.1.6/pkgx

Caused by:
    `unzip` was not found in your PATH, please install `unzip`

If reporting this issue please do so at (not Homebrew/brew or Homebrew/homebrew-core):
  https://github.com/pkgxdev/homebrew-made/issues

However, I have unzip installed:

❯ which unzip
/home/linuxbrew/.linuxbrew/bin/unzip

❯ unzip
UnZip 6.00 of 20 April 2009, by Debian. Original by Info-ZIP.

Usage: unzip [-Z] [-opts[modifiers]] file[.zip] [list] [-x xlist] [-d exdir]
  Default action is to extract files in list, except those in xlist, to exdir;
  file[.zip] may be a wildcard.  -Z => ZipInfo mode ("unzip -Z" for usage).

  -p  extract files to pipe, no messages     -l  list files (short format)
  -f  freshen existing files, create none    -t  test compressed archive data
  -u  update files, create if necessary      -z  display archive comment only
  -v  list verbosely/show version info       -T  timestamp archive to latest
  -x  exclude files that follow (in xlist)   -d  extract files into exdir
modifiers:
  -n  never overwrite existing files         -q  quiet mode (-qq => quieter)
  -o  overwrite files WITHOUT prompting      -a  auto-convert any text files
  -j  junk paths (do not make directories)   -aa treat ALL files as text
  -U  use escapes for all non-ASCII Unicode  -UU ignore any Unicode fields
  -C  match filenames case-insensitively     -L  make (some) names lowercase
  -X  restore UID/GID info                   -V  retain VMS version numbers
  -K  keep setuid/setgid/tacky permissions   -M  pipe through "more" pager
  -O CHARSET  specify a character encoding for DOS, Windows and OS/2 archives
  -I CHARSET  specify a character encoding for UNIX and other archives

See "unzip -hh" or unzip.txt for more help.  Examples:
  unzip data1 -x joe   => extract all files except joe from zipfile data1.zip
  unzip -p foo | more  => send contents of foo.zip via pipe into program more
  unzip -fo foo ReadMe => quietly replace existing ReadMe if archive file newer

Solution / workaround

A sudo apt install unzip solved it, but I think maybe this should've worked since unzip was already on $PATH.

Feel free to close this issue anytime, as I just wanted to bring attention to this - along with the workaround.

dosubot[bot] commented 6 months ago

Based on the information you've provided, it seems like the issue might be related to how the environment variables, including PATH, are managed and passed around within the pkgx tool or how linuxbrew configures its environment. However, without more specific details on how pkgx interacts with system utilities or how it's supposed to handle dependencies like unzip, it's challenging to pinpoint the exact cause of the failure.

pkgx does have specific configurations for the PATH. It mentions installing and uninstalling stubs to PATH in the modes section:

The pkgx codebase handles the installation process on different platforms, including WSL (Ubuntu) using Linuxbrew, by employing a series of GitHub Actions workflows that compile the code, prepare the environment, and test the installation and functionality of pkgx across different shell environments (bash, zsh, POSIX). The workflows are defined in the .github/workflows/ci.shellcode.yml file.

pkgx handles system utilities like unzip during the installation process by resolving the command or utility name to a package requirement and then executing the command with the resolved environment. This process involves several steps, as outlined in the provided code from src/modes/x.ts:

  1. Resolving the Command or Utility Name: The function find_arg0 is used to resolve the initial argument (arg0) to a package if possible. This involves checking if the argument matches a known package or utility and then preparing it for execution. If the argument ends with @latest, it indicates that the latest version of the package should be used, and this is handled accordingly.

  2. Handling System Utilities Directly: The code includes a specific check for the open command on Darwin (macOS) platforms, directly resolving it to /usr/bin/open followed by the remaining arguments. This indicates that for certain well-known system utilities, pkgx can bypass the package resolution process and directly execute the utility.

  3. Execution Environment Construction: Once the package requirements are resolved, pkgx constructs the execution environment using construct_env. This involves setting up the environment variables and paths required for the execution of the package or utility.

  4. Executing the Command: Finally, the resolved command or utility is executed using the exec function from _internals, which is an alias for execve. This function takes the command to execute and the constructed environment, performing the actual execution of the utility or package command.

You can find more details in the src/modes/x.ts file.

Without access to this additional information or specific error handling related to unzip within the pkgx codebase, it's not possible to provide a definitive answer based on the provided context. Could you provide more details about your environment setup and the exact steps you took before encountering the error? This would help in identifying the root cause of the issue.

Sources

#### About Dosu This response is meant to be useful and save you time. It is **not meant to be a precise solution**, but rather a starting point for your own research. Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant. If you want to continue the conversation, start your reply with @dosu-bot.
jhheider commented 6 months ago

Hm. Within pkgx, this is handled by

runtime:
  env:
    DENO_NO_UPDATE_CHECK: 'true'
    DENORT_BIN: '{{prefix}}/bin/denort'

It's a peculiar consequence of the deno compiled runtime changes made in 1.39.1. I definitely agree that it should have detected your existing unzip install, which would make depending on unzip in homebrew one solution. I'll play around with it, and see if I can't inject the correct environment variable in the Homebrew formula.

jhheider commented 6 months ago

@fredrikaverpil , I can confirm https://github.com/pkgxdev/homebrew-made/commit/1733eb9363f748d470752924ee0ed4e94c9d0bac lets me install in a clean debian:buster-slim docker image without unzip installed explicitly.

$ apt-get update && apt-get install -y curl git psutils
...
$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
...
$ (echo; echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"') >> /root/.bashrc
$ eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
$ brew install pkgxdev/made/pkgx
...
==> Installing pkgxdev/made/pkgx
==> deno task compile
==> Caveats
try it out:

    pkgx node@18 --eval 'console.log("pkgx: run anything")'

shell integration:

    pkgx integrate --dry-run
    # ^^ https://docs.pkgx.sh/shell-integration
==> Summary
🍺  /home/linuxbrew/.linuxbrew/Cellar/pkgx/1.1.6: 5 files, 89.1MB, built in 9 seconds
==> Running `brew cleanup pkgx`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
==> Caveats
==> pkgx
try it out:

    pkgx node@18 --eval 'console.log("pkgx: run anything")'

shell integration:

    pkgx integrate --dry-run
    # ^^ https://docs.pkgx.sh/shell-integration

are you able to confirm the install works (you might need to brew update, or brew untap pkgxdev/made/pkgx to get it to refresh), without unzip from the OS package manager?

fredrikaverpil commented 6 months ago

Very nice, I can confirm that you fixed this. 🎉

❯ brew uninstall pkgx
Uninstalling /home/linuxbrew/.linuxbrew/Cellar/pkgx/1.1.6... (5 files, 89.1MB)

❯ brew untap pkgxdev/made
Untapping pkgxdev/made...
Untapped 1 formula (48 files, 256KB).

❯ sudo apt-get remove unzip
[sudo] password for fredrik:
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following package was automatically installed and is no longer required:
  libntfs-3g89
Use 'sudo apt autoremove' to remove it.
The following packages will be REMOVED:
  unzip
0 upgraded, 0 newly installed, 1 to remove and 33 not upgraded.
After this operation, 385 kB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 78723 files and directories currently installed.)
Removing unzip (6.0-26ubuntu3.1) ...
Processing triggers for man-db (2.10.2-1) ...

❯ brew tap pkgxdev/made
==> Auto-updating Homebrew...
Adjust how often this is run with HOMEBREW_AUTO_UPDATE_SECS or disable with
HOMEBREW_NO_AUTO_UPDATE. Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
==> Auto-updated Homebrew!
Updated 5 taps (go-task/tap, homebrew/bundle, homebrew/linux-fonts, homebrew/core and homebrew/cask).
==> New Formulae
liblc3                                     msieve                                     rage                                       rustcat
==> New Casks
ente-auth                                  outfox                                     toneprint                                  viable

You have 3 outdated formulae installed.

==> Tapping pkgxdev/made
Cloning into '/home/linuxbrew/.linuxbrew/Homebrew/Library/Taps/pkgxdev/homebrew-made'...
remote: Enumerating objects: 366, done.
remote: Counting objects: 100% (185/185), done.

remote: Compressing objects: 100% (81/81), done.
remote: Total 366 (delta 106), reused 169 (delta 93), pack-reused 181
Receiving objects: 100% (366/366), 61.82 KiB | 1.31 MiB/s, done.
Resolving deltas: 100% (207/207), done.
Tapped 1 formula (19 files, 179KB).

❯ brew install pkgx
==> Auto-updating Homebrew...
Adjust how often this is run with HOMEBREW_AUTO_UPDATE_SECS or disable with
HOMEBREW_NO_AUTO_UPDATE. Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
==> Fetching pkgxdev/made/pkgx
==> Downloading https://github.com/pkgxdev/pkgx/releases/download/v1.1.6/pkgx-1.1.6.tar.xz
Already downloaded: /home/fredrik/.cache/Homebrew/downloads/c8b2441dfddcbd6b0ef34fb1621836e46340e44576acd184a9e0bca2a45121cd--pkgx-1.1.6.tar.xz
==> Installing pkgx from pkgxdev/made
==> deno task compile
==> Caveats
try it out:

    pkgx node@18 --eval 'console.log("pkgx: run anything")'

shell integration:

    pkgx integrate --dry-run
    # ^^ https://docs.pkgx.sh/shell-integration
==> Summary
🍺  /home/linuxbrew/.linuxbrew/Cellar/pkgx/1.1.6: 5 files, 89.1MB, built in 14 seconds
==> Running `brew cleanup pkgx`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).