home-manager icon indicating copy to clipboard operation
home-manager copied to clipboard

installed apps don’t show up in Ubuntu's "Show Applications"

Open samuela opened this issue 5 years ago • 72 comments

Issue description

Apps installed via home-manager don't show up in the Ubuntu "Show Applications" thingy.

See https://discourse.nixos.org/t/home-manager-installed-apps-dont-show-up-in-applications-launcher/8523 for context. https://github.com/rycee/home-manager/blob/master/modules/misc/xdg-mime.nix suggests that home-manager should be adding these applications to the desktop manager database automatically, but for some reason it's not working. Note that running update-desktop-database manually on a copy of the relevant stuff in the nix store does work, as discussed in the Discourse thread.

I have targets.genericLinux.enable = true and verified that $XDG_DATA_DIRS is being set appropriately:

❯ echo $XDG_DATA_DIRS
/nix/var/nix/profiles/default/share:/home/skainswo/.nix-profile/share:/home/skainswo/deleteme:/home/skainswo/.nix-profile/share/applications:/home/skainswo/.nix-profile/share/applications:/home/skainswo/.nix-profile/share/applications:/usr/share/ubuntu:/usr/local/share/:/usr/share/:/var/lib/snapd/desktop

Here's the entirety of my home.nix: https://gist.github.com/samuela/b507cb3a3effde6117b32700add2f448. I'm running Ubuntu 20.04.

Meta

Maintainer CC

@rycee @Kha

Technical details

❯ nix-shell -p nix-info --run "nix-info -m"
 - system: `"x86_64-linux"`
 - host os: `Linux 5.4.0-42-generic, Ubuntu, 20.04.1 LTS (Focal Fossa)`
 - multi-user?: `no`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.3.7`
 - channels(skainswo): `"home-manager, nixpkgs-20.09pre237891.f9eba87bf03"`
 - nixpkgs: `/home/skainswo/.nix-defexpr/channels/nixpkgs`

samuela avatar Aug 12 '20 20:08 samuela

Could you share the output of

$ ls ~/.nix-profile/share/applications

?

rycee avatar Aug 12 '20 21:08 rycee

Sure!

❯ ls ~/.nix-profile/share/applications  
code-url-handler.desktop  htop.desktop    transmission-gtk.desktop
code.desktop              mimeinfo.cache  virt-manager.desktop
emacs.desktop             slack.desktop   vlc.desktop

samuela avatar Aug 12 '20 22:08 samuela

No idea if this is related but when I run a home-manager switch I get this message:

Activating reloadSystemD
The user systemd session is degraded:
  UNIT                           LOAD   ACTIVE SUB    DESCRIPTION                               
● xdg-desktop-portal-gtk.service loaded failed failed Portal service (GTK+/GNOME implementation)

LOAD   = Reflects whether the unit definition was properly loaded.
ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
SUB    = The low-level unit activation state, values depend on unit type.

samuela avatar Aug 12 '20 22:08 samuela

I'm not using Gnome unfortunately. But you said that the launcher works if you call update-desktop-database yourself in a separate directory? Do you see any relevant difference between the cached generated by that and ~/.nix-profile/share/applications/mimeinfo.cache?

Kha avatar Aug 13 '20 08:08 Kha

Ok, I did the following:

$ cd
$ mkdir -p deleteme/applications

Then added export XDG_DATA_DIRS="/home/skainswo/deleteme:$XDG_DATA_DIRS" to the end of my ~/.profile.

$ echo $XDG_DATA_DIRS                               
/nix/var/nix/profiles/default/share:/home/skainswo/.nix-profile/share:/home/skainswo/deleteme:/usr/share/ubuntu:/usr/local/share/:/usr/share/:/var/lib/snapd/desktop
$ cp ~/.nix-profile/share/applications/* ~/deleteme/applications
$ update-desktop-database -v ~/deleteme/applications
Search path is now: [/home/skainswo/deleteme/applications]
File "/home/skainswo/deleteme/applications/htop.desktop" lacks MimeType key
File "/home/skainswo/deleteme/applications/virt-manager.desktop" lacks MimeType key
$ diff deleteme/applications/mimeinfo.cache ~/.nix-profile/share/applications/mimeinfo.cache
$ 

Then logging in and logging out I can see that I have all the apps in "Show Applications". So they actually have the same mimeinfo.cache. Here's its contents: https://gist.github.com/samuela/4ed9677cf522f26d806408f34caaeb35.

samuela avatar Aug 13 '20 23:08 samuela

Update: it seems that in order to get rid of shortcuts after editing .profile a logout isn't sufficient, but a restart works.

samuela avatar Aug 13 '20 23:08 samuela

Update 2: Adding

export XDG_DATA_DIRS="/home/skainswo/.nix-profile/share:$XDG_DATA_DIRS"

to my ~/.profile and restarting does work! So my guess is that home-manager is inserting its stuff into $XDG_DATA_DIRS too late for them to get picked up properly by Unity/GNOME/whatever.

samuela avatar Aug 14 '20 00:08 samuela

I see, you only have programs.zsh.enable set, not programs.bash.enable. The latter would update your .profile appropriately. I'm actually using the same settings, but since I start my window manager from a zsh login shell, the environment variables are still loaded.

Kha avatar Aug 14 '20 07:08 Kha

Mm, I see. So I guess home-manager should still be adding some things to .profile even when programs.bash.enable = false then?

samuela avatar Aug 14 '20 08:08 samuela

So I tried looking into this as well because for me home manager installed icons only work on NixOS but not on Arch.

As you can see, I have the spotify icon in my nix-profile folder, and XDG_DATA_DIRS includes that folder. So as far as I can tell, it should see the icons folder because XDG_DATA_DIRS includes the root path containing that icons folder. But since some folks in this thread mentioned this update-desktop-database which doesn't work because immutable I guess that that's the problem?

For me restarts don't help.

cloud $ echo $XDG_DATA_DIRS | string split ":"
/nix/var/nix/profiles/default/share
/home/cloud/.nix-profile/share
/home/cloud/.nix-profile/share
/home/cloud/.local/share/flatpak/exports/share
/var/lib/flatpak/exports/share
/usr/local/share
/usr/share
cloud $ fd . -t l ~/.nix-profile/share/icons/ | rg spotify
/home/cloud/.nix-profile/share/icons/hicolor/128x128/apps/spotify-client.png
/home/cloud/.nix-profile/share/icons/hicolor/16x16/apps/spotify-client.png
/home/cloud/.nix-profile/share/icons/hicolor/256x256/apps/spotify-client.png
/home/cloud/.nix-profile/share/icons/hicolor/32x32/apps/spotify-client.png
/home/cloud/.nix-profile/share/icons/hicolor/48x48/apps/spotify-client.png
/home/cloud/.nix-profile/share/icons/hicolor/512x512/apps/spotify-client.png
/home/cloud/.nix-profile/share/icons/hicolor/64x64/apps/spotify-client.png
 - system: `"x86_64-linux"`
 - host os: `Linux 5.8.1-arch1-1, Arch Linux, noversion`
 - multi-user?: `no`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.3.7`
 - channels(cloud): `"home-manager, nixpkgs-20.09pre235385.ca4e665f8c3, nixos-20.03-20.03.2611.bb8f0cc2279"`
 - nixpkgs: `/home/cloud/.nix-defexpr/channels/nixpkgs`

cideM avatar Aug 17 '20 18:08 cideM

As you can see, I have the spotify icon in my nix-profile folder, and XDG_DATA_DIRS includes that folder.

This doesn't guarantee that your DE uses the same values. You could look in /proc/$pid/environ where $pid is the process ID of the launcher to make sure.

But since some folks in this thread mentioned this update-desktop-database which doesn't work because immutable I guess that that's the problem?

Home manager calls update-desktop-database during build for you, then links the resulting store path, which as usual is immutable, into your home. You are not supposed to call it yourself, but you can inspect the files produced by Home manager to make sure they are correct. But again, I don't know what data exactly Gnome or other DEs expect there. I only cared about xdg-open in the shell working.

Kha avatar Aug 17 '20 20:08 Kha

This doesn't guarantee that your DE uses the same values. You could look in /proc/$pid/environ where $pid is the process ID of the launcher to make sure.

That's a great tip, I didn't know about this. I took the parent process for /usr/bin/gnome-shell which spawns a couple of other gnome-shell threads and then checked its environ:

XDG_DATA_DIRS=/home/cloud/.local/share/flatpak/exports/share:/var/lib/flatpak/exports/share:usr/local/share:/usr/share

Indeed, the Home Manager file paths are missing here. I did some more specific googling and came upon a very interesting Gnome issue filed by a Guix user. On another tracker the issue has a solution and some more instructions specifically for distros like Arch which have this issue can be found here

Unfortunately I couldn't make it work so far. I tried adding export XDG_DATA_DIRS to /etc/profile but that didn't help. .profile and .config/systemd/ also didn't help. I'll ask around in some Arch Linux/GNOME circles as to how I can set XDG_DATA_DIRS for the first /usr/bin/gnome-shell process that's started

cideM avatar Aug 18 '20 10:08 cideM

Me and @terlar was working with this issue for popOS (ubuntu based). the solution so far we found . setting home.nix like this. When the homeSession variables are passed to pamSession then the *.desktop files are found.

Still couldn't fix the pop-shell launcher, desktop apps are not searchable by super + /

xdg = {
   enable = true;
 };
 home.sessionVariables = {
   EDITOR="nvim";
   BROWSER = "firefox";
   TERMINAL = "alacritty";
 };

 pam.sessionVariables = config.home.sessionVariables // {
      LANGUAGE	="en_US:en";
      LANG	="en_US.UTF-8";
     //copy your pam session stuff here  from ~/.pam_environment
 };

rajibahmed avatar Sep 19 '20 01:09 rajibahmed

Ok, I was able to reproduce what @samuela has done with Pop!_OS (@rajibahmed might be of your interest, as you are using the same OS).

I did the following steps after a clean install: 1- Set up Nix (confirm that $HOME/etc/profile.d/nix.sh is being loaded at .profile, restart your user session and echo any of the variables to check) 2- Set up home-manager 3- Build and switch a home.nix that contains:

xdg.enable=true;
xdg.mime.enable=true;
targets.genericLinux.enable=true;
  1. Add to .profile the line:
export XDG_DATA_DIRS="/home/your_user/.nix-profile/share:$XDG_DATA_DIRS"
  1. Restart

I will try this on Fedora in a few weeks to confirm this is being reproduced as expected or if the same issue as @cideM happens (different behavior per distro)

WolfangAukang avatar Oct 23 '20 00:10 WolfangAukang

I tried the same steps on Fedora and it didn't work. I even tried to modify the ~/.local/environment.d/ file (that supposedly would help in making the gnome-shell process recognize the variable on Wayland) and it had an almost catastrophic result.

So yes, this seems to change according to the distro being used, unfortunately.

WolfangAukang avatar Dec 15 '20 21:12 WolfangAukang

Did you try the pam.sessionVariables hack? I would be surprised if that is not working. Both .pam_environment and XDG_DATA_DIRS is a standard, so if that doesn’t work then that means the dist doesn’t respect these

terlar avatar Dec 16 '20 07:12 terlar

Hey @terlar, just to confirm, it is adding XDG_DATA_DIRS to the pam.sessionVariables, is that correct? If that's so, then it didn't work.

My suspicion is the distro, or Wayland, because my current setup of pop!_OS uses Gnome on Xorg and with the tweak provided by @samuela, it worked without any issues. But on Fedora I am not able to get that. Had to use alacarte to create the shortcuts.

WolfangAukang avatar Dec 16 '20 23:12 WolfangAukang

I am now running manjaro with wayland. PAM solution doesn't work with wayland I believe.

rajibahmed avatar Dec 28 '20 13:12 rajibahmed

I just had another look at this and got it to work with the following (for Ubuntu):

{
  targets.genericLinux = {
    enable = true;
    extraXdgDataDirs = [
      "/usr/share/ubuntu"
      "/usr/local/share/"
      "/usr/share/"
      "/var/lib/snapd/desktop"
    ];
  };
}

Together with this addition to targets/generic-linux.nix:

    systemd.user.sessionVariables = let
      profiles =
        [ "\${NIX_STATE_DIR:-/nix/var/nix}/profiles/default" profileDirectory ];
      dataDirs = concatStringsSep ":"
        (map (profile: "${profile}/share") profiles
          ++ config.targets.genericLinux.extraXdgDataDirs);
    in { XDG_DATA_DIRS = "${dataDirs}\${XDG_DATA_DIRS:+:}$XDG_DATA_DIRS"; };

Caution! If you don't add the extraXdgDataDirs with the one that was already set in $XDG_DATA_DIRS it could cause the desktop to be "unbootable", that happened to me. So then I had to remove the generated ~/.config/environment.d/10-home-manager.conf and reboot.

terlar avatar Feb 01 '21 14:02 terlar

@terlar would you like to make a PR with all your recent target.genericLinux findings? :smiley:

berbiche avatar Feb 03 '21 04:02 berbiche

I'm testing NixOS and I'm having a similar problem using GNOME. Apps won't appear in the Shell until I reset GNOME.

emanuelserpa avatar Feb 10 '21 03:02 emanuelserpa

I'm testing NixOS and I'm having a similar problem using GNOME. Apps won't appear in the Shell until I reset GNOME.

May I know how to reset GNOME?

Congee avatar May 01 '21 01:05 Congee

"Show Applications" work after I logged out and logged into gnome

Congee avatar May 01 '21 01:05 Congee

This still seems to be an issue for me on Ubuntu 21.04 Wayland, post the xdg modules fix:

 - system: `"x86_64-linux"`
 - host os: `Linux 5.11.0-17-generic, Ubuntu, 21.04 (Hirsute Hippo)`
 - multi-user?: `no`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.3.10`
 - channels(jethro): `"home-manager, nixpkgs-21.05pre290422.3528c4151ee"`
 - nixpkgs: `/home/jethro/.nix-defexpr/channels/nixpkgs`

jethrokuan avatar May 18 '21 12:05 jethrokuan

Does anyone have a fix for this on the standard NixOS on GNOME?

BentonEdmondson avatar Jun 07 '21 22:06 BentonEdmondson

FWIW things were working for me on PopOS until recently when the icons were all missing again. I played around with it a bit and found that I needed to put them in a folder nested under ~/Desktop which I could then run update-desktop-database on. I wrote a small bin script to copy them and update the desktop database:

# shortened config
{ config, pkgs, nixpkgs, ... }:
let
    update-icons = pkgs.writeScriptBin "update-icons" ''
    #!${pkgs.bash}/bin/bash
    set -euo pipefail
    shopt -s inherit_errexit

    ICON_DIR="$HOME/Desktop/.icons"
    mkdir -p "$ICON_DIR"
    cp ~/.nix-profile/share/applications/*.desktop "$ICON_DIR"
    update-desktop-database --verbose "$ICON_DIR"
  '';
in {
    home.packages = [update-icons];
}

I'm not sure where the Desktop folder is ok'd to access desktop icons, but I was not able to get ~/.icons/ to work or a randomly generated /tmp/ folder.

jonknapp avatar Sep 01 '21 20:09 jonknapp

Will give it a shot again. And see how it works now with @terlar updates in a non-nixos gnome setup.

rajibahmed avatar Sep 02 '21 08:09 rajibahmed

FWIW things were working for me on PopOS until recently when the icons were all missing again. I played around with it a bit and found that I needed to put them in a folder nested under ~/Desktop which I could then run update-desktop-database on. I wrote a small bin script to copy them and update the desktop database:

# shortened config
{ config, pkgs, nixpkgs, ... }:
let
    update-icons = pkgs.writeScriptBin "update-icons" ''
    #!${pkgs.bash}/bin/bash
    set -euo pipefail
    shopt -s inherit_errexit

    ICON_DIR="$HOME/Desktop/.icons"
    mkdir -p "$ICON_DIR"
    cp ~/.nix-profile/share/applications/*.desktop "$ICON_DIR"
    update-desktop-database --verbose "$ICON_DIR"
  '';
in {
    home.packages = [update-icons];
}

I'm not sure where the Desktop folder is ok'd to access desktop icons, but I was not able to get ~/.icons/ to work or a randomly generated /tmp/ folder.

@jonknapp version is the one that worked for me.

delaneyj avatar Sep 04 '21 17:09 delaneyj

Glad it worked @delaneyj. As a heads up, you may want to tweak the script a bit since it doesn't automatically prune applications that you remove from your nix config. Clearing the ICON_DIR before populating it should work fine.

jonknapp avatar Sep 05 '21 12:09 jonknapp

I spoke to soon @jonknapp , they 100% show up but don't actual work. For example blender.desktop

[Desktop Entry]
Name=Blender
GenericName=3D modeler
GenericName[ar]=3D المنمذج ثلاثي الأبعاد
GenericName[ca]=Modelador 3D
GenericName[cs]=3D modelování
GenericName[da]=3D-modellering
GenericName[de]=3D-Modellierer
GenericName[el]=Μοντελοποιητής 3D
GenericName[es]=Modelador 3D
GenericName[et]=3D modelleerija
GenericName[fi]=3D-mallintaja
GenericName[fr]=Modeleur 3D
GenericName[gl]=Modelador 3D
GenericName[hu]=3D modellező
GenericName[it]=Modellatore 3D
GenericName[ja]=3D モデラー
GenericName[lt]=3D modeliavimas
GenericName[nb]=3D-modellering
GenericName[nl]=3D-modeller
GenericName[pl]=Modelowanie 3D
GenericName[pt_BR]=Modelador 3D
GenericName[ro]=Arhitect 3D
GenericName[ru]=Редактор 3D-моделей
GenericName[tr]=3D modelleyici
GenericName[uk]=Редактор 3D-моделей
GenericName[wa]=Modeleu 3D
GenericName[zh_CN]=3D 建模
GenericName[zh_TW]=3D 模型
Comment=3D modeling, animation, rendering and post-production
Comment[ar]=3D النمذجة، الرسوم المتحركة، والتجسيد، وما بعد الإنتاج
Comment[ast]=Modeláu 3D, animación, renderizáu y postproducción
Comment[eu]=3D modelatzea, animazioa, errendatzea eta post-produkzioa
Comment[be]=Праграма прасторавага мадэлявання, анімацыі, апрацоўкі відэа і давядзення відэапрадукцыі
Comment[bn]=ত্রিমাত্রিক মডেল, অ্যানিমেশন, রেন্ডারিং এবং পোস্ট-উৎপাদন
Comment[bs]=3D modeliranje, animacija, obrada i postprodukcija
Comment[bg]=3D моделиране, анимиране, рендиране и пост-продукция
Comment[ca]=Modelat 3D, animació, renderització i post-producció
Comment[ca@valencia]=Modelat 3D, animació, renderització i post-producció
Comment[crh]=3B modelleme, animasyon, işleme ve son üretim
Comment[cs]=3D modelování, animace, rederování a postprodukce
Comment[da]=3D-modellering, animation, rendering og efterbehandling
Comment[de]=3D-Modellierung, Animation, Rendering und Nachbearbeitung
Comment[nl]=3d-modelleren, animeren, renderen en post-productie
Comment[el]=Μοντελοποίηση 3D, κινούμενα σχέδια, αποτύπωση και οργάνωση διαδικασίας μετά-την-παραγωγή
Comment[eo]=3D-modelado, animacio, renderado kaj postproduktado
Comment[es]=Modelado 3D, animación, renderizado y post-producción
Comment[et]=Kolmemõõtmeline modelleerimine, animeerimine, esitlemine ja järeltöötlemine
Comment[fi]=3D-mallinnus, -animaatiot, -renderöinti ja -tuotanto
Comment[fr]=Modélisation 3D, animation, rendu et post-production
Comment[fr_CA]=Modélisation 3D, animation, rendu et post-production
Comment[gl]=Modelado 3D, animación, renderizado e postprodución
Comment[hu]=3D modellek és animációk létrehozása és szerkesztése
Comment[is]=Þrívíddarmódel, hreyfimyndir, myndgerð og frágangur myndskeiða
Comment[it]=Modellazione 3D, animazione, rendering e post-produzione
Comment[ja]=3Dモデリング、アニメーション、レンダリング、ポストプロダクションのツール
Comment[ko]=3D 모델링, 애니메이션, 렌더링과 포스트 프로덕션
Comment[lt]=3D modeliavimas, animacijų kūrimas, atvaizdavimas ir tobulinimas
Comment[lv]=3D modelēšana, animācija, renderēšana un pēcapstrāde
Comment[ms]=Pemodelan, animasi, penerapan dan post-produksi 3D
Comment[nb]=3D-modellering, animasjon, rendering og postproduksjon
Comment[oc]=Modelizacion 3D, animacion, rendut e post-produccion
Comment[pl]=Modelowanie 3D, animacja, renderowanie i postprodukcja
Comment[pt]=Modelação 3D, animação, renderização e pós-produção
Comment[pt_BR]=Modelagem 3D, animação, renderização e pós-produção
Comment[ro]=Modelare, animare, afișare și post-producție 3D
Comment[ru]=3D-моделирование, анимация, рендеринг и компоновка
Comment[sl]=3D modeliranje, animacija, izrisovanje in nadaljnje obdelovanje
Comment[sq]=Animacion i modeleve 3D, rregullim dhe më pas prodhim
Comment[sr]=3Д моделовање, анимација, исцртавање и постпродукција
Comment[sv]=3d-modellering, animering, rendering och efterbehandling
Comment[ta]=முப்பரிமாண ஒப்புருவாக்கம், அசைவூட்டம், காட்சியாக்கம் மற்றும் உருவாக்கத்துக்கு பிந்தைய செயல்பாடுகள்
Comment[tg]=Моделсозии 3D, аниматсия, пешниҳод ва истеҳсоли баъдӣ
Comment[tr]=3B modelleme, animasyon, işleme ve son üretim
Comment[uk]=Програма просторового моделювання, анімації, обробки відео та доведення відеопродуктів
Comment[vi]=Tạo hình mẫu 3D, hoạt họa, dựng hình và các công việc hậu kỳ
Comment[wa]=Modelaedje 3D, animåcion, rindou eyet après-produccion
Comment[zh_HK]=3D 模型、動畫、算圖和後製
Comment[zh_CN]=3D 建模、动画、渲染和后期制作
Comment[zh_TW]=3D 模型、動畫、算圖和後製
Keywords=3d;cg;modeling;animation;painting;sculpting;texturing;video editing;video tracking;rendering;render engine;cycles;game engine;python;
Exec=blender %f
Icon=blender
Terminal=false
Type=Application
Categories=Graphics;3DGraphics;
MimeType=application/x-blender;

doesn't execute

blender &` in a shell gives ` intern/ghost/intern/GHOST_WindowX11.cpp:206: X11 glXChooseVisual() failed, verify working openGL system!
initial window could not find the GLX extension
Writing: /tmp/blender.crash.txt

[1]  + 339308 segmentation fault (core dumped)  blender

but nixGL blender & in a terminal works fine. Maybe its because my $SHELL is zsh install via nix?

delaneyj avatar Sep 10 '21 14:09 delaneyj