Homebrew apps on linux: Integration into KDE?

TL;DR: How to integrate brew installed apps into the DE ? Manual copy and modification of .desktop into ~/.local/ ? Is brew not intended for gui apps?

Context: The question is to use brew onto an “immutable” system (KDE Linux) for additional apps/tools that flatpak don’t provide. I also tested it on an Arch install.
The question is relatively generic (not specific to KDE) but since it is related to KDE Linux I ask it there in case some people using brew could enlighten me.

So I started to test it but I have problem integrating the tools with my system. For cli tool it is working as expected after adding the necessary line in bashrc/zshrc for path, but the problem is more with the Desktop Environment. For example I installed foot (terminal emulator) and Emacs. For foot I copied the .desktop found in /home/linuxbrew/.linuxbrew/share/applications/ into ~/.local/share/applications/ then I had to modify Exec= to include brew prefix, it now launch. For Emacs it refuse to start (in GUI mode ) and it make me worried if it was compiled witth GUI capabilities.

Anyway does brew only target cli (there are some gui tool like qalculate-qt but not much)? Is there an intended way to integrate .desktop file or we supposed to copy each one and modify them to add prefix? It seems cumbersome.

1 Like

Depending on how the $HOME/.linuxbrew looks like you could consider making it part of the XDG directory search paths.

For example applications are looked for in any directory listed in $XDG_DATA_DIRS which usually defaults to something like /usr/share:/usr/local/share

$XDG_DATA_HOME is only a single directory and defaults to $HOME/.local/share

So something like this might work without you having to copy or link files
export XDG_DATA_DIRS=$HOME/.linuxbrew/share:$XDG_DATA_DIRS

1 Like

Thanks for the response. I didn’t think of XDG indeed I will try.
But one problem is that it wasn’t enough to copy .desktop to ~/.local/share/applications/, I also had to edit it to change the Exec= for example from Exec=foot to Exec=/home/linuxbrew/.linuxbrew/bin/foot
And the questin was a little more broad, to what to expect from brew apps , as KDE-Linux is considering using brew as a complementary package manager. For example emacs on brew seems compiled without gui (--without-x), but then it seems you can past build flags to brew so maybe it is the way people use it when needed.
Or, I miss something (totally possible).

1 Like

That might be solvable at a more systematic level if the Brew directory for binaries were added to the “path” environment variable?

2 Likes

For the Exec path I would have also gone with @johnandmegh’s suggestion and extending $PATH.

I am wondering if brew does not already come with some sort of “environment script”.

Something that can either be sourced by the user or even “globally” added to the profile.

For example here on my system (KDE Neon) both Flatpak and Snap have installed such a script into /etc/profile.d

Since you are on an immutable system I guess the question is if brew is part to that (then its package could have installed this) or if it is also installed local to the user (in which case the user would need to source the script in $HOME/.profile).

Maybe I was not clear but indeed there is a script to setup env vars and there is line added to .bashrc/.zshrc

/home/linuxbrew/.linuxbrew/bin/brew shellenv

And PATH is correctly populated it is why apps works as expected in terminal. At a moment, I thought maybe KDE didn’t the same path (I had the problem in the path were depending on how I was setting it DE didn’t use the same path than shell).

Here the problem is more about integration with DE, apps/tools not appear in menu and krunner(for example to launch foot or emacs). I think the problem is more simple, it is that brew was build for mac and not completetly support linux. In particular, I think brew is more use, on linux, for cli apps and dev tools/libs so brew didn’t bother to include proper .desktop files suitable for linux integration (with prefix and all) like you get with flatpak for example (there is room for improvement even with flatpak too).

I was asking in case some people using brew on linux have more insight. Maybe there is something I don’t see? For example for flatpaks I wanted to add some custom .desktop and I add to dig to find where the proper one with prefix and all are (in order to copy, modify and put mine in ~/.local). Maybe there is a directory wich you can symlink with proper .desktop, not documented on brew.sh?
https://docs.brew.sh/Homebrew-on-Linux

But Maybe I am mistaken. It is true that kde doesn’t seems to have the same path and then it is needed to add the prefix in .desktop file. In this idea I also added the shellenv line to /etc/environment without success. And I tested to add /home/linuxbrew/.linuxbrew/bin to path directly but same.

Edit: OK Sorry my bad, I just retested to copy foot.desktop from linuxbrew to ~/.local and it work without prefix. Maybe I didn’t do it well for shellenv line (I copy and recopy it in .zshrc, in part to have shell completion with brew).
There is still the fact that you have to copy .desktop or symlink the brew applications directory (not ideal for general purpose distro). But it seems to work. I will look to test more app from brew (still not much gui app).

Edit2: by testing further it is indeed that the shellenv line (in .zshrc) was not inough. What makes it work (in kde/krunner, it always launches from the terminal) was that I added the linuxbrew directories to path, “manually”, in .zshenv .

Or you extend the other search path variables.

Ideally this brew shellenv command would do this as well, not just $PATH

well apparently this is where there some improvement for integration. I will look at XDG path later.

1 Like

That would be really useful, thanks! Personally I’m hoping we can ship brew by default in KDE Linux and make it our blessed solution for getting miscellaneous software not on Flathub or the Snap store, so better integration is always welcome.

I did some quick test but so far no good. Having this

export XDG_DATA_DIRS=/home/linuxbrew/.linuxbrew/share:$XDG_DATA_DIRS

in my .zshenv broke kde : it wont start. I supposed because there is a lot in this dir, brew did install a lot, for example installing foot (and nothing else) did pull wayland, xorg and systemd (and many more). I also tried with /home/linuxbrew/.linuxbrew/share/applications but without luck for now (i don’t know if you could just add some subdirs to share/ to XDG_DATA_DIRS).

Having another search dir should not affect startup but as you said brew might be installing things in strange way.

You could try appending the brew path instead of appending it
export XDG_DATA_DIRS=$XDG_DATA_DIRS:/home/linuxbrew/.linuxbrew/share

Btw I would have some suggestions for preinstall apps/tools in base system. I could put it there (with some argument) or where?
It is mainly about input :

  • keyd : it is a keyboard remapper that works at the kernel level, it is light with a simple config file in /etc/keyd bring qmk-like capability to keyboard like layer mod-tap and all (much cheaper than programable keyboard :wink: ), config can be per keyboard, there are other advence features also.
    To why it should be preinstall: it is not in brew (but in Arch) nore flatpak and do to it be close to kernel i wonder if it could work with countainer/flatpak
  • also Maliit-keyboard I have see it seems installed but don’t work right now (at least on my device)

There’s always the question about what to pre-install. And for things not packaged outside of Arch, what to do?

Personally I’m in favof or pre-installing maliit right now as it feels more like a system component than a user-facing app you should be able to remove or swap out.

As for keyd, that feels more borderline. But feel free to send merge requests and we’ll discuss it over at Merge requests · KDE Linux / KDE Linux · GitLab

1 Like

So far it did not change. To be clear kde do not crash but it show startup screen then black screen and mouse (responsive) and hang. By looking at journalctl -f during the process it seems that it start but in loooong time without making it to plasma or kwin (sometime when plasma didn’t work you still could use krunner or you can see kwin but not there) but there are still some components that works for example after some time waiting I have a minimal lock screen that activate. It is guessing but i really wonder if all the stuff in /home/linuxbrew/.linuxbrew/share interfer with system one.

Ok thanks and yes maliit is also an accessibility component. I have seen that someone put a request for flatpak’s Maliit but I have not found it. Is there one (flathub or elsewhere)?

So I did some more test:

  • first the problem that prevent kde/plasma from starting was due to the fact that I put the export in .zshenv (as I generally do) if I put it in .zshrc all start without a fuss and the directory is added to XDG_DATA_DIRS without problem (well see next)
  • no change regarding integration, there is no added entry in menu/krunner like I have if I put them in ~/.local/share/applications . Did kde use XDG_DATA_DIRS to surch for .desktop (well it is were share for flatpak are set so i guess yes…)?
  • to test and because I don’t like to include all data in the default /share directory of brew I create an empty parralel dir /home/linuxbrew/.linuxbrew/local/share that I then add to XDG_DATA_DIRS with a /applications dir in there. I then copied the .desktop files in it → nothing

So I don’t now how to solve that. Does KDE/Plasma use XDG_DATA_DIRS or directly merge the corresponding directories? I will tried to put the export in /etc/environment just in case.

Note: for clarity brew create a directories /home/linuxbrew own by root and /home/linuxbrew/.linuxbrew own by $USER under which it install everything. But it didn’t install anything in $HOME (I think) there is no $HOME/.linuxbrew.

Edit: Success (sort of) so by putting the export in /etc/profile.d/xbrew.sh (the name is for it to be source after the rest, lazy to do the extra test needed) instead of the different files in my $HOME KDE/Plasma did have access to the .desktop and they appear in menu/krunner. Now is it ok to source it globally (/home/linuxbrew/.linuxbrew is own by $USER).

Putting it in .zshrc did not work because that is only sourced by interactive shells.

So the “login” shell that runs your KDE session did not see it.

Yes I forgot on the moment (I look at zsh files some time ago but it is easy to confuse).
On brew site the install guide as commands to put the call to shellenv script into bashrc/zshrc.

test -d /home/linuxbrew/.linuxbrew && eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
echo "eval \"\$($(brew --prefix)/bin/brew shellenv)\"" >> ~/.bashrc

I am looking at what it really set: for what I’ve seen, mainly PATH and some homebrew envvars like HOMEBREW_PREFIX , HOMEBREW_CELLAR and HOMEBREW_REPOSITORY. I wonder if it could be a good idea to call the script from /etc/profile.d/brew.sh

There is something else I am looking: brew install a LOT of stuff as dependancies when installing package for example when installing foot it install wayland, Xorg and systemd , for qalculate-qt brew installs gtk+3, gtk4 and more. I wonder if those could interfer with system ones, it appear that yes.
For example:

● /usr/bin/systemctl --version
systemd 258 (258.devel.r78189.5830d34b400-1-arch-g5830d34^)
+PAM +AUDIT -SELINUX -APPARMOR -IMA +IPE +SMACK +SECCOMP +GCRYPT +GNUTLS +OPENSSL +ACL +BLKID +CURL +ELFUTILS +FIDO2 +IDN2 -IDN +IPTC +KMOD +LIBCRYPTSETUP +LIBCRYPTSETUP_PLUGINS +LIBFDISK +PCRE2 +PWQUALITY +P11KIT +QRENCODE +TPM2 +BZIP2 +LZ4 +XZ +ZLIB +ZSTD +BPF_FRAMEWORK +BTF +XKBCOMMON +UTMP -SYSVINIT +LIBARCHIVE
● systemctl --version
systemd 257 (257.1)
-PAM -AUDIT -SELINUX -APPARMOR +IMA +IPE +SMACK -SECCOMP -GCRYPT -GNUTLS +OPENSSL -ACL +BLKID -CURL -ELFUTILS -FIDO2 -IDN2 -IDN -IPTC -KMOD -LIBCRYPTSETUP -LIBCRYPTSETUP_PLUGINS +LIBFDISK +PCRE2 -PWQUALITY -P11KIT -QRENCODE -TPM2 +BZIP2 +LZ4 +XZ +ZLIB +ZSTD -BPF_FRAMEWORK -BTF -XKBCOMMON +UTMP +SYSVINIT -LIBARCHIVE
● /home/linuxbrew/.linuxbrew/bin/systemctl --version
systemd 257 (257.1)
-PAM -AUDIT -SELINUX -APPARMOR +IMA +IPE +SMACK -SECCOMP -GCRYPT -GNUTLS +OPENSSL -ACL +BLKID -CURL -ELFUTILS -FIDO2 -IDN2 -IDN -IPTC -KMOD -LIBCRYPTSETUP -LIBCRYPTSETUP_PLUGINS +LIBFDISK +PCRE2 -PWQUALITY -P11KIT -QRENCODE -TPM2 +BZIP2 +LZ4 +XZ +ZLIB +ZSTD -BPF_FRAMEWORK -BTF -XKBCOMMON +UTMP +SYSVINIT -LIBARCHIVE
● whereis systemctl
systemctl: /usr/bin/systemctl /home/linuxbrew/.linuxbrew/bin/systemctl

or

● qtplugininfo -v
qplugininfo 6.7.3
● qtplugininfo6 -v
qplugininfo 6.8.1
● /home/linuxbrew/.linuxbrew/bin/qtplugininfo --version
qplugininfo 6.7.3
● /usr/bin/qtplugininfo6  -v
qplugininfo 6.8.1

I think that could pose problem at some point, and it is not great on security level (brew systemd is behind the one provided by KDE-Linux) and maybe could pose compatibility.
Maybe it is a matter of how to set PATH (order of precedence) and envvars. If KDE Linux want to rely on brew, it should provide is own script to set PATH/envvars for interation as for some control over brew.

Edit: I commented everything set in my $HOME and just put homebrew call to shellenv script in /etc/profile.d/xbrew.sh alongside XDG_DATA_DIRS set and I have the same problem of system app/lib being overlayed.

Edit2: By thinking of it, it is a feature of brew so to have more recent version of libs/tools over the system one; it is also that homebrew is first design with mac in mind. When I first tested, I thought it might have some level of containerization/isolation.

1 Like