use-package icon indicating copy to clipboard operation
use-package copied to clipboard

/usr/games/pacman vs /usr/bin/apt

Open barak opened this issue 11 months ago • 5 comments

I run Debian and am a fun-loving bloke so /usr/games is on my path and pacman (the game) is installed. When use-package loads and searches for an appropriate value for system-packages-package-manager it finds /usr/games/pacman so the variable gets set to "pacman" instead of "apt".

Woka woka woka.

👻 👻 👻

barak avatar Aug 04 '23 14:08 barak

I believe this was a bug in system-packages on GNU ELPA. I have pushed a new version 1.0.12 with a fix, which should be available to install from GNU ELPA within 24-48 hours.

Could you please test it and report back whether it works or not?

skangas avatar Aug 05 '23 03:08 skangas

This was actually using the Debian package elpa-use-package version 2.4.4-1.

barak avatar Aug 06 '23 17:08 barak

Does adding this to the very beginning of your Init file, and then restarting Emacs, solve the problem?

(setq system-packages-package-manager
  (let ((managers system-packages-supported-package-managers)
        manager)
    (while managers
      (progn
        (setq manager (pop managers))
        (let ((found (executable-find (symbol-name (car manager)))))
          (if (and found
                   ;; The package manager named "pacman" conflicts
                   ;; with the game binary on non-Arch systems.
                   (not (string-match (rx "games/pacman" eos) found)))
              (setq managers nil)
            (setq manager nil)))))
    (car manager)))

skangas avatar Aug 07 '23 01:08 skangas

That works, on my machine, as of today. But seems to me it's not robust because someone on an Arch system might have both /usr/bin/pacman (the package manager) and /usr/games/pacman (the arcade game clone) and have /usr/games before /usr/sbin on their path.

I'd suggest putting "apt" before "pacman" in the search list, just based on popularity. That's a stop-gap though.

Unfortunately I don't think there's any truly correct solution based on scanning for an executable. Sometimes people have multiple package managers installed: their native one, and also some "alien" ones for various purposes. There's a Debian package rpm that provides /usr/bin/rpm, and there's a Debian package pacman-package-manager that provides /usr/bin/pacman. The only solution I can see is to determine which distribution you're on, and case off that. I think /etc/os-release is standard for this purpose.

barak avatar Aug 08 '23 10:08 barak

I'd suggest putting "apt" before "pacman" in the search list, just based on popularity. That's a stop-gap though.

I've now done this and released version 1.0.13, which should be on GNU ELPA shortly. Thanks.

skangas avatar Sep 08 '23 00:09 skangas