Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
samuela opened this issue Aug 12, 2020 · 69 comments
Open

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

samuela opened this issue Aug 12, 2020 · 69 comments

Comments

@samuela
Copy link
Contributor

samuela commented Aug 12, 2020

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`
@rycee
Copy link
Member

rycee commented Aug 12, 2020

Could you share the output of

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

?

@samuela
Copy link
Contributor Author

samuela commented Aug 12, 2020

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
Copy link
Contributor Author

samuela commented Aug 12, 2020

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.

@Kha
Copy link
Contributor

Kha commented Aug 13, 2020

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?

@samuela
Copy link
Contributor Author

samuela commented Aug 13, 2020

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
Copy link
Contributor Author

samuela commented Aug 13, 2020

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

@samuela
Copy link
Contributor Author

samuela commented Aug 14, 2020

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.

@Kha
Copy link
Contributor

Kha commented Aug 14, 2020

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.

@samuela
Copy link
Contributor Author

samuela commented Aug 14, 2020

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

@cideM
Copy link

cideM commented Aug 17, 2020

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`

@Kha
Copy link
Contributor

Kha commented Aug 17, 2020

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.

@cideM
Copy link

cideM commented Aug 18, 2020

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

This was referenced Sep 17, 2020
@rajibahmed
Copy link

rajibahmed commented Sep 19, 2020

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
 };

@WolfangAukang
Copy link

WolfangAukang commented Oct 23, 2020

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
Copy link

WolfangAukang commented Dec 15, 2020

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.

@terlar
Copy link
Contributor

terlar commented Dec 16, 2020

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

@WolfangAukang
Copy link

WolfangAukang commented Dec 16, 2020

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.

@rajibahmed
Copy link

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

@terlar
Copy link
Contributor

terlar commented Feb 1, 2021

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.

@berbiche
Copy link
Member

berbiche commented Feb 3, 2021

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

@emanuelserpa
Copy link

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

terlar added a commit to terlar/home-manager that referenced this issue Feb 10, 2021
This should fix the issue where desktops using Wayland did not see the
installed desktop applications and potentially other artifacts stored in
this directory.

Suggested way to set per user environment variables for Wayland:
https://wiki.archlinux.org/index.php/environment_variables#Per_user

Fix nix-community#1439
terlar added a commit to terlar/home-manager that referenced this issue Feb 10, 2021
This should fix the issue where desktops using Wayland did not see the
installed desktop applications and potentially other artifacts stored in
this directory.

Suggested way to set per user environment variables for Wayland:
https://wiki.archlinux.org/index.php/environment_variables#Per_user

Fix nix-community#1439
terlar added a commit to terlar/home-manager that referenced this issue Feb 11, 2021
This should fix the issue where desktops using Wayland did not see the
installed desktop applications and potentially other artifacts stored in
this directory.

Suggested way to set per user environment variables for Wayland:
https://wiki.archlinux.org/index.php/environment_variables#Per_user

Fix nix-community#1439
terlar added a commit to terlar/home-manager that referenced this issue Feb 11, 2021
This should fix the issue where desktops using Wayland did not see the
installed desktop applications and potentially other artifacts stored in
this directory.

Suggested way to set per user environment variables for Wayland:
https://wiki.archlinux.org/index.php/environment_variables#Per_user

Fix nix-community#1439
terlar added a commit to terlar/home-manager that referenced this issue Mar 31, 2021
This should fix the issue where desktops using Wayland did not see the
installed desktop applications and potentially other artifacts stored in
this directory.

Suggested way to set per user environment variables for Wayland:
https://wiki.archlinux.org/index.php/environment_variables#Per_user

Fix nix-community#1439
@Congee
Copy link
Contributor

Congee commented May 1, 2021

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?

@drupol
Copy link
Contributor

drupol commented Apr 20, 2022

Also, when I try to run an app, I get a permission denied and I'm unable to run the app.

@drupol
Copy link
Contributor

drupol commented Apr 20, 2022

@berbiche : I also tried your solution:

$ home-manager switch --flake . -v                                                                                                                                                                                       
warning: Git tree '/home/devlin/.config/nixpkgs' is dirty
warning: Git tree '/home/devlin/.config/nixpkgs' is dirty
error: infinite recursion encountered

       at /nix/store/39fyfqxp75p2qifkrrni32bav3fpngzl-source/modules/misc/xdg.nix:87:9:

           86|         XDG_CONFIG_HOME = cfg.configHome;
           87|         XDG_DATA_HOME = cfg.dataHome;
             |         ^
           88|         XDG_STATE_HOME = cfg.stateHome;
(use '--show-trace' to show detailed location information)
$

@loicreynier
Copy link
Contributor

@drupol you may solve your issue by checking out your permissions on your ~/.local/share/applications folder. Looks like you do not have write permissions.

@drupol
Copy link
Contributor

drupol commented Apr 20, 2022

Actually, I have this, I don't see where the problem is. It looks like I have the permissions, but for some reason, it doesn't work.

 ~  ls -la ~/.local/share/applications                                                                                                                      
lrwxrwxrwx   44 devlin 20 Apr 12:25 home-manager -> /home/devlin/.nix-profile/share/applications
.rw-rw-r--    0 devlin 28 Feb 13:57 mimeapps.list
.rw-rw-r-- 1.0k devlin 25 Mar 09:42 mimeinfo.cache
 ~  ls -la ~/.local/share/                                                                                                                                  
drwxrwxr-x    - devlin 20 Apr 12:25 applications
drwxrwxr-x    - devlin 23 Mar 13:17 ark
drwxrwxr-x    - devlin  1 Oct  2020 backintime
drwxrwxr-x    - devlin 11 Oct  2021 baloo
drwxrwxr-x    - devlin  4 Jun  2021 composer
drwxr-xr-x    - devlin 28 Sep  2020 discover
drwxrwxr-x    - devlin 20 Apr 10:46 dolphin
drwx------    - devlin 20 Apr 12:55 fish
drwxr-xr-x    - devlin 28 Sep  2020 flatpak
drwxrwxr-x    - devlin 28 Sep  2020 fonts
drwx------    - devlin 15 Apr 14:42 gvfs-metadata
drwxrwxr-x    - devlin 14 Jun  2021 gwenview
drwxr-xr-x    - devlin  3 Feb 14:31 home-manager
drwxrwxr-x    - devlin 17 Nov  2020 ibus-table
dr-xr-xr-x    - devlin  8 Feb 15:42 icons
drwxrwxr-x    - devlin  4 Feb 14:25 JetBrains
drwxrwxr-x    - devlin 28 Sep  2020 kactivitymanagerd
drwxrwxr-x    - devlin 22 Feb 09:01 kate
drwxrwxr-x    - devlin 20 Apr 12:50 kcookiejar
drwxrwxr-x    - devlin 29 Sep  2020 kded5
drwx------    - devlin  9 Feb 12:40 keyrings
drwxrwxr-x    - devlin 11 Jun  2021 khelpcenter
drwxrwxr-x    - devlin 20 Apr 14:14 klipper
drwxrwxr-x    - devlin 28 Sep  2020 knewstuff3
drwxrwxr-x    - devlin  8 Feb 15:15 konsole
drwxrwxr-x    - devlin  9 Mar 12:58 krdc
.rw------- 2.2k devlin 20 Apr 11:11 krunnerstaterc
drwxrwxr-x    - devlin 28 Mar 13:07 kscreen
drwxrwxr-x    - devlin  6 Apr 17:15 ksysguard
drwxrwxr-x    - devlin 20 Apr 08:38 kwalletd
drwxrwxr-x    - devlin  3 May  2021 kxmlgui5
drwx------    - devlin 18 Oct  2021 mime
.rw-rw-r--    0 devlin  3 Feb 22:20 mimeapps.list
drwx------    - devlin  3 Feb 17:18 nano
drwxr-xr-x    - devlin  3 Mar 16:45 nix
drwxrwxr-x    - devlin  7 Jun  2021 okular
drwxrwxr-x    - devlin 28 Sep  2020 omf
drwxrwxr-x    - devlin 21 Jun  2021 plasma_notes
drwxrwxr-x    - devlin 20 Apr 13:52 RecentDocuments
.rw------- 9.2k devlin 15 Apr 14:41 recently-used.xbel
drwxr-x---    - devlin  3 Nov  2020 remmina
drwxrwxr-x    - devlin 28 Sep  2020 sddm
drwxrwxr-x    - devlin  3 Nov  2020 teamviewer15
drwx------    - devlin 20 Apr 11:11 TelegramDesktop
drwxrwxr-x    - devlin 20 Apr 12:59 Trash
.rw-rw-r-- 4.8k devlin 18 Oct  2021 user-places.xbel
.rw-rw-r-- 4.8k devlin 18 Oct  2021 user-places.xbel.bak
.rw-rw-r--    0 devlin 18 Oct  2021 user-places.xbel.tbcache
drwxrwxr-x    - devlin  3 Jun  2021 vinagre
 ~  ls -la ~/.local                                                                                                                                         
drwxrwxr-x - devlin 18 Mar 10:24 bin
drwxrwxr-x - devlin 20 Apr 11:11 share
 ~  ls -la ~/.local/share                                                                                                                                   
drwxrwxr-x    - devlin 20 Apr 12:25 applications
drwxrwxr-x    - devlin 23 Mar 13:17 ark
drwxrwxr-x    - devlin  1 Oct  2020 backintime
drwxrwxr-x    - devlin 11 Oct  2021 baloo
drwxrwxr-x    - devlin  4 Jun  2021 composer
drwxr-xr-x    - devlin 28 Sep  2020 discover
drwxrwxr-x    - devlin 20 Apr 10:46 dolphin
drwx------    - devlin 20 Apr 12:55 fish
drwxr-xr-x    - devlin 28 Sep  2020 flatpak
drwxrwxr-x    - devlin 28 Sep  2020 fonts
drwx------    - devlin 15 Apr 14:42 gvfs-metadata
drwxrwxr-x    - devlin 14 Jun  2021 gwenview
drwxr-xr-x    - devlin  3 Feb 14:31 home-manager
drwxrwxr-x    - devlin 17 Nov  2020 ibus-table
dr-xr-xr-x    - devlin  8 Feb 15:42 icons
drwxrwxr-x    - devlin  4 Feb 14:25 JetBrains
drwxrwxr-x    - devlin 28 Sep  2020 kactivitymanagerd
drwxrwxr-x    - devlin 22 Feb 09:01 kate
drwxrwxr-x    - devlin 20 Apr 12:50 kcookiejar
drwxrwxr-x    - devlin 29 Sep  2020 kded5
drwx------    - devlin  9 Feb 12:40 keyrings
drwxrwxr-x    - devlin 11 Jun  2021 khelpcenter
drwxrwxr-x    - devlin 20 Apr 14:14 klipper
drwxrwxr-x    - devlin 28 Sep  2020 knewstuff3
drwxrwxr-x    - devlin  8 Feb 15:15 konsole
drwxrwxr-x    - devlin  9 Mar 12:58 krdc
.rw------- 2.2k devlin 20 Apr 11:11 krunnerstaterc
drwxrwxr-x    - devlin 28 Mar 13:07 kscreen
drwxrwxr-x    - devlin  6 Apr 17:15 ksysguard
drwxrwxr-x    - devlin 20 Apr 08:38 kwalletd
drwxrwxr-x    - devlin  3 May  2021 kxmlgui5
drwx------    - devlin 18 Oct  2021 mime
.rw-rw-r--    0 devlin  3 Feb 22:20 mimeapps.list
drwx------    - devlin  3 Feb 17:18 nano
drwxr-xr-x    - devlin  3 Mar 16:45 nix
drwxrwxr-x    - devlin  7 Jun  2021 okular
drwxrwxr-x    - devlin 28 Sep  2020 omf
drwxrwxr-x    - devlin 21 Jun  2021 plasma_notes
drwxrwxr-x    - devlin 20 Apr 13:52 RecentDocuments
.rw------- 9.2k devlin 15 Apr 14:41 recently-used.xbel
drwxr-x---    - devlin  3 Nov  2020 remmina
drwxrwxr-x    - devlin 28 Sep  2020 sddm
drwxrwxr-x    - devlin  3 Nov  2020 teamviewer15
drwx------    - devlin 20 Apr 11:11 TelegramDesktop
drwxrwxr-x    - devlin 20 Apr 12:59 Trash
.rw-rw-r-- 4.8k devlin 18 Oct  2021 user-places.xbel
.rw-rw-r-- 4.8k devlin 18 Oct  2021 user-places.xbel.bak
.rw-rw-r--    0 devlin 18 Oct  2021 user-places.xbel.tbcache
drwxrwxr-x    - devlin  3 Jun  2021 vinagre
 ~  ls -la ~/.local/share/applications                                                                                                                      
lrwxrwxrwx   44 devlin 20 Apr 12:25 home-manager -> /home/devlin/.nix-profile/share/applications
.rw-rw-r--    0 devlin 28 Feb 13:57 mimeapps.list
.rw-rw-r-- 1.0k devlin 25 Mar 09:42 mimeinfo.cache
 ~  ls -la ~/.nix-profile/                                                                                                                                  
dr-xr-xr-x  - devlin  1 Jan  1970 bin
lrwxrwxrwx 70 devlin  1 Jan  1970 datagrip -> /nix/store/g19v4kd038dv65ndc7sc018pjs9rl927-home-manager-path/datagrip
dr-xr-xr-x  - devlin  1 Jan  1970 etc
lrwxrwxrwx 69 devlin  1 Jan  1970 include -> /nix/store/g19v4kd038dv65ndc7sc018pjs9rl927-home-manager-path/include
dr-xr-xr-x  - devlin  1 Jan  1970 lib
dr-xr-xr-x  - devlin  1 Jan  1970 libexec
lrwxrwxrwx 60 devlin  1 Jan  1970 manifest.nix -> /nix/store/d7aaxkdg7bmm23xjlb7xmh1zafglq0c3-env-manifest.nix
lrwxrwxrwx 65 devlin  1 Jan  1970 opt -> /nix/store/g19v4kd038dv65ndc7sc018pjs9rl927-home-manager-path/opt
lrwxrwxrwx 70 devlin  1 Jan  1970 phpstorm -> /nix/store/g19v4kd038dv65ndc7sc018pjs9rl927-home-manager-path/phpstorm
lrwxrwxrwx 66 devlin  1 Jan  1970 sbin -> /nix/store/g19v4kd038dv65ndc7sc018pjs9rl927-home-manager-path/sbin
dr-xr-xr-x  - devlin  1 Jan  1970 share
$      

@loicreynier
Copy link
Contributor

loicreynier commented Apr 20, 2022

ln raises a permission error if the link is already present. You may need to remove it before trying to recreate it:

  home.activation = {
    linkDesktopApplications = {
       after = [ "writeBoundary" "createXdgUserDirectories" ];
      before = [ ];
      data = ''
+      [ -e ${config.xdg.dataHome}/"applications/home-manager" ] && \
+        rm -f ${config.xdg.dataHome}/"applications/home-manager"
        ln -s ${config.home.homeDirectory}/.nix-profile/share/applications \
          ${config.xdg.dataHome}/"applications/home-manager"
      '';
    };
  };

@SuperSandro2000
Copy link
Member

or simply append -f to ln to always rewrite the link.

@loicreynier
Copy link
Contributor

or simply append -f to ln to always rewrite the link.

Even with -f, ln failed to create the symbolic link due to permissions on my side.

@drupol
Copy link
Contributor

drupol commented Apr 22, 2022

This is fixing the issue:

  home.activation = {
    linkDesktopApplications = {
      after = [ "writeBoundary" "createXdgUserDirectories" ];
      before = [ ];
      data = ''
        rm -rf ${config.xdg.dataHome}/"applications/home-manager"
        mkdir -p ${config.xdg.dataHome}/"applications/home-manager"
        cp -Lr ${config.home.homeDirectory}/.nix-profile/share/applications/* ${config.xdg.dataHome}/"applications/home-manager/"
      '';
    };
  };

Dumb, but working flawlessly.

@annymosse
Copy link

@samuela
I'm facing same issue whenever i'm not using home-manager I just installed nix in kubuntu as single user in a virtual machine and :

$ cat ~/.profile
export XDG_DATA_DIRS="/home/annymosse/.nix-profile/share:$XDG_DATA_DIRS"
$ echo $XDG_DATA_DIRS
/home/nixer/.nix-profile/share:/usr/share/plasma:/.....

is there any idea ?

@drupol
Copy link
Contributor

drupol commented Apr 22, 2022

@annymosse Using Ubuntu here as well, the solution I provided works fine ! I'm happy :)

@annymosse
Copy link

@annymosse Using Ubuntu here as well, the solution I provided works fine ! I'm happy :)

Thanks for your reply, however I'm trying to migrate into nix instead of brew & snap , how can I implement your solution?

@drupol
Copy link
Contributor

drupol commented Apr 22, 2022

Ah, this is a good question.

Maybe someone else will help, I have no idea on how to implements this without using Home manager.

@stale
Copy link

stale bot commented Jul 22, 2022

Thank you for your contribution! I marked this issue as stale due to inactivity. Please be considerate of people watching this issue and receiving notifications before commenting 'I have this issue too'. We welcome additional information that will help resolve this issue. Please read the relevant sections below before commenting.

If you are the original author of the issue

  • If this is resolved, please consider closing it so that the maintainers know not to focus on this.
  • If this might still be an issue, but you are not interested in promoting its resolution, please consider closing it while encouraging others to take over and reopen an issue if they care enough.
  • If you know how to solve the issue, please consider submitting a Pull Request that addresses this issue.

If you are not the original author of the issue

  • If you are also experiencing this issue, please add details of your situation to help with the debugging process.
  • If you know how to solve the issue, please consider submitting a Pull Request that addresses this issue.

Memorandum on closing issues

Don't be afraid to manually close an issue, even if it holds valuable information. Closed issues stay in the system for people to search, read, cross-reference, or even reopen – nothing is lost! Closing obsolete issues is an important way to help maintainers focus their time and effort.

@stale stale bot added the status: stale label Jul 22, 2022
@Doosty
Copy link

Doosty commented Dec 12, 2022

This is fixing the issue:

  home.activation = {
    linkDesktopApplications = {
      after = [ "writeBoundary" "createXdgUserDirectories" ];
      before = [ ];
      data = ''
        rm -rf ${config.xdg.dataHome}/"applications/home-manager"
        mkdir -p ${config.xdg.dataHome}/"applications/home-manager"
        cp -Lr ${config.home.homeDirectory}/.nix-profile/share/applications/* ${config.xdg.dataHome}/"applications/home-manager/"
      '';
    };
  };

Dumb, but working flawlessly.

Tried on NixOS 22.11 in my home manager home.nix. Builds, but does nothing. Help appreciated, i really want my .nix-profile desktop entries to work...

@stale stale bot removed the status: stale label Dec 12, 2022
@aidalgol
Copy link
Contributor

@Doosty

Tried on NixOS 22.11 in my home manager home.nix. Builds, but does nothing. Help appreciated, i really want my .nix-profile desktop entries to work...

This ticket is about using home-manager on Ubuntu. If you're having problems on NixOS, you should open a separate issue, since desktop entries are managed very differently on NixOS.

@chaoky
Copy link

chaoky commented Feb 2, 2023

I'm using a variation of #1439 (comment) to also get icons/fonts/man/etc

{
  programs.bash = {
    enable = true;
    profileExtra = ''
      export XDG_DATA_DIRS=$HOME/.home-manager-share:$XDG_DATA_DIRS
    '';
  };

  home.activation = {
    linkDesktopApplications = {
      after = [ "writeBoundary" "createXdgUserDirectories" ];
      before = [ ];
      data = ''
        rm -rf $HOME/.home-manager-share
        mkdir -p $HOME/.home-manager-share
        cp -Lr --no-preserve=mode,ownership ${config.home.homeDirectory}/.nix-profile/share/* $HOME/.home-manager-share
      '';
    };
  };
}

@chaoky
Copy link

chaoky commented Feb 22, 2023

update: simpler, builtin version, of the above

{
  fonts.fontconfig.enable = true;
  targets.genericLinux.enable = true;
  home.activation = {
    linkDesktopApplications = {
      after = [ "writeBoundary" "createXdgUserDirectories" ];
      before = [ ];
      data = "/usr/bin/update-desktop-database";
    };
  };
}

@josephsellers
Copy link

Thanks, @chaoky, that works for me!

For anyone else trying to get this working, about not having file permissions to do this, but that was resolved by running:
sudo chown -R $USER /usr/share/ /usr/local/

@bayazidbh
Copy link

bayazidbh commented Mar 19, 2023

Tested around on Kubuntu (Nix installed with determinate systems installer), and I think you only need to sudo chmod -R 777 $HOME/.nix-profile/share/applications. What matters is that update-desktop-database $HOME/.nix-profile/share/applications can create and modify the mimeinfo.cache file at ~/.nix-profile/share/applications.

Maybe targets.genericLinux.enable = true; can check if it has write permission for the folder (and request permission if it doesn't) and automaticall include update-desktop-database process.

In any case, for me, it seems like the update-desktop-database process won't succeed unless I ran it with /usr/bin/sudo or make the nix-profile applications folder writeable beforehand or with sudo during the process.

Edit: for me, targets.genericLinux.enable = true; and xdg.mime.enable = true; seems to be enough.

@onsah
Copy link

onsah commented Jun 11, 2023

For Fedora Gnome, it works when you have bash managed by home-manager. So you need programs.bash.enabled = true; with targets.genericLinux.enable = true;

@kindsun
Copy link

kindsun commented Jun 25, 2023

Using: Kubuntu 23.04 w/ Nix Multiuser installation, here's what worked for me:

Added the following to home.nix:

# As already mentioned
targets.genericLinux.enable = true;
xdg.mime.enable = true;

# The critical missing piece for me
xdg.systemDirs.data = [ "${config.home.homeDirectory}/.nix-profile/share/applications" ];

For whatever reason, that directory wasn't explicitly added to $XDG_DATA_DIRS in my setup. Adapting this for other systems should hopefully be easy enough:

  1. Figure out the dir where your nix installed .desktop files are getting saved
  2. echo $XDG_DATA_DIRS and see if that dir is listed there
  3. If it's not, adapt that last line above added to home.nix: xdg.systemDirs.data = [ "${config.home.homeDirectory}/path/to/applications/folder" ];
  4. Newly installed apps show up automatically after restart or after executing sudo update-desktop-database. There's prob room for a more elegant solution here, but it works!

@stale
Copy link

stale bot commented Sep 23, 2023

Thank you for your contribution! I marked this issue as stale due to inactivity. Please be considerate of people watching this issue and receiving notifications before commenting 'I have this issue too'. We welcome additional information that will help resolve this issue. Please read the relevant sections below before commenting.

If you are the original author of the issue

  • If this is resolved, please consider closing it so that the maintainers know not to focus on this.
  • If this might still be an issue, but you are not interested in promoting its resolution, please consider closing it while encouraging others to take over and reopen an issue if they care enough.
  • If you know how to solve the issue, please consider submitting a Pull Request that addresses this issue.

If you are not the original author of the issue

  • If you are also experiencing this issue, please add details of your situation to help with the debugging process.
  • If you know how to solve the issue, please consider submitting a Pull Request that addresses this issue.

Memorandum on closing issues

Don't be afraid to manually close an issue, even if it holds valuable information. Closed issues stay in the system for people to search, read, cross-reference, or even reopen – nothing is lost! Closing obsolete issues is an important way to help maintainers focus their time and effort.

@stale stale bot added the status: stale label Sep 23, 2023
@quinn-dougherty
Copy link

word of warning: I had installed firefox, zulip, a couple others with snap, then uninstalled them when I decided I want to manage them through hm. It turned out that this step became onerous-- I got it to work (by following these steps) for anything I had not previously installed then removed through snap. Still haven't figured out how to back out of a snap install properly for these purposes.

@stale stale bot removed the status: stale label Nov 28, 2023
@slocke716
Copy link

This is fixing the issue:

  home.activation = {
    linkDesktopApplications = {
      after = [ "writeBoundary" "createXdgUserDirectories" ];
      before = [ ];
      data = ''
        rm -rf ${config.xdg.dataHome}/"applications/home-manager"
        mkdir -p ${config.xdg.dataHome}/"applications/home-manager"
        cp -Lr ${config.home.homeDirectory}/.nix-profile/share/applications/* ${config.xdg.dataHome}/"applications/home-manager/"
      '';
    };
  };

Dumb, but working flawlessly.

Building on @drupol solution, my remaining issue was that the non-interactive shell did not seem to have the nix path so I added the nix path directly

home.activation = {
    linkDesktopApplications = {
      after = [ "writeBoundary" "createXdgUserDirectories" ];
      before = [ ];
      data = ''
        rm -rf ${config.home.homeDirectory}/.nix-desktop-files
        rm -rf ${config.home.homeDirectory}/.local/share/applications/home-manager
        rm -rf ${config.home.homeDirectory}/.icons/nix-icons
        mkdir -p ${config.home.homeDirectory}/.nix-desktop-files
        mkdir -p ${config.home.homeDirectory}/.icons
        ln -sf ${config.home.homeDirectory}/.nix-profile/share/icons ${config.home.homeDirectory}/.icons/nix-icons
        /usr/bin/desktop-file-install ${config.home.homeDirectory}/.nix-profile/share/applications/*.desktop --dir ${config.home.homeDirectory}/.local/share/applications/home-manager
        sed -i 's/Exec=/Exec=\/home\/${config.home.username}\/.nix-profile\/bin\//g' ${config.home.homeDirectory}/.local/share/applications/home-manager/*.desktop
        /usr/bin/update-desktop-database ${config.home.homeDirectory}/.local/share/applications
      '';
    };
  };

I'm on gnome 45 on GeckoLinux (derivative of Opensuse Tumbleweed). I was unable to find how to make sure the non-interactive shell had the nix path. I would welcome making this less ugly by just adding the path instead of using sed

@shreyas-a-s
Copy link

shreyas-a-s commented Feb 29, 2024

Hey guys, anybody found a method by which we can use other shells like zsh in this context?

I can add the XDG_DATA_DIRS=... line in ~/.profile and set user shell to bash using chsh -s /usr/bin/bash and after a reboot the applications show up in GNOME menu. But when I set shell to zsh, they disappear from menu.

Any thoughts on what could be the issue here?

I am on Debian 12 btw if that matters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.