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

:use-package-ensure-system-packages — Support for multiple platforms

Open OldhamMade opened this issue 4 years ago • 2 comments

It would be great if one could specify the name of the package per OS.

For example, given the following config:

     (use-package counsel                                                                                                                                            
       :delight                                                                                                                                                      
       :ensure-system-package                                                                                                                                        
         ((fzf . fzf)                                                                                                                                                
          (fd . fd)                                                                                                                                                  
          (rg . ripgrep))                                                                                                                                            
       :bind                                                                                                                                                         
         ((:map counsel-describe-map ("M-." . counsel-find-symbol))                                                                                                  
          ("C-x C-f" . counsel-find-file)                                                                                                                            
          ("C-M-f" . counsel-rg))
       :init                                                                                                                                                         
         (counsel-mode)                                                                                                                                              
       :config                                                                                                                                                       
         (setq counsel-fzf-cmd "fd -H | fzf -f \"%s\""))

Here fzf and ripgrep are installed fine on both macOS (via brew) and Ubuntu (via apt), but fd fails to be installed on Ubuntu because it is named fd-find.

Maybe something like the following would work?

     (use-package counsel                                                                                                                                            
       :delight                                                                                                                                                      
       :ensure-system-package
       (:darwin
         ((fzf . fzf)                                                                                                                                                
          (fd . fd)
          (rg . ripgrep))
        :gnu/linux
         ((fzf . fzf)                                                                                                                                                
          (fd . fd-find)                                                                                                                                                  
          (rg . ripgrep)))

OldhamMade avatar Nov 27 '19 19:11 OldhamMade

@OldhamMade you may probably have found a way around this already, but for reference this works for me:

(let ((system-package
       (if (eq system-type 'darwin)
           '(wn . "brew install wordnet")
         '(wn . "sudo apt-get install wordnet"))))
  (eval `(use-package helm-wordnut
                :ensure-system-package ,system-package)))

ag91 avatar Jul 28 '21 16:07 ag91

This would be a really nice feature to have. I'm currently running into similar issues with yapf (called yapf on macOS but yapf3 on Ubuntu).

I'm not sure about the approach of using :darwin or :gnu/linux to distinguish between operating systems, as that means we'll need to define keyword symbols for every platform/package repo (i.e. Ubuntu and Arch Linux are both Linux, but have different package repos). It would be more flexible to just be able to embed something like :if inside :ensure-system-package, but I'm not familiar enough with elisp to know if that's possible.

Another thought is that instead of using :if to figure out the OS, we could just have a way to specify which package manager each binary/package list applies to. Then the code could check that against the system-packages-package-manager variable and use the correct list for that package manager. This would be simpler and more flexible, in that it would be easier to add to use-package (just an extra if-statement check) and it will work for all the package managers that system-packages supports without needed to special case these in use-package code. The one problem here is that it won't work if the same package manager is used on two different distros, those distros use the same package manager but different repositories, and the packages have different names on those repositories for the same binary, but I think this case wil likely be rare.

gsingh93 avatar Aug 13 '22 20:08 gsingh93