Mac applications installed by Nix are not loaded by Spotlight

My environment is MacOs Big Sur, with nix v2.3.14.
I got a new laptop that I want to setup without Homebrew and I’ve heard about Nix for a long time, this seems to be the perfect opportunity to try it.
I’ve been able to install a few tools already, but I’ve trouble installing GUI Applications, such as Obsidian and iTerm2. iTerm at least seem to be installed in ~/.nix-profile/Applications, while Obsidian is not installed. None of those Applications is found by Spotlight.
I’m newbie to Nix and my understanding is that the applications are installed but Spotlight does not locate them as those applications are just symlinked and there are issues for this both in nix and home-manager repos.

There seem to be a few workarounds mentioned in the issues above, but as I’m a newbie to Nix, I have no clue what to do to fix my situation, i.e how to use those workarounds ?
By the way, thanks to @Atemu for mentioning this Discourse via (Automatically link macOS applications to ~/Applications · Issue #956 · NixOS/nix · GitHub), I’ve tried to fix my situation by following the instructions and I’ve create a local copy of home-manager/darwin.nix at e6d905336181ed8f98d48a1f6c9965b77f18e304 · Atemu/home-manager · GitHub and linked it from my imports in my nix config (~/.nixpkgs/darwin-configuration.nix).

{ config, pkgs, ... }:

{
  imports = [
    darwin.nix # https://github.com/Atemu/home-manager/blob/e6d905336181ed8f98d48a1f6c9965b77f18e304/modules/targets/darwin.nix
  ];
...

But when I try to load this config, I face a few errors that I don’t know how to fix, being a Nix newbie :slight_smile:

morganwattiez@Morgans-MBP> darwin-rebuild switch                                                                                                                                                                                    
building the system configuration...
warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels' does not exist, ignoring
error: undefined variable 'darwin' at /Users/morganwattiez/.nixpkgs/darwin-configuration.nix:6:5
(use '--show-trace' to show detailed location information)

Should I install the home-manager version by @Atemu at GitHub - Atemu/home-manager: Development fork, don't depend on this. fix the issue or just copy home-manager/darwin.nix at e6d905336181ed8f98d48a1f6c9965b77f18e304 · Atemu/home-manager · GitHub and try to add it to imports ? Is there another solution I’m missing maybe ?

Thanks in advance :slight_smile:

What you wrote got interpreted as "attribute nix of the attrset called darwin" which is what Nix also tells you; it has no idea what this darwin variable refers to since no such variable exists.
This is why paths must be either absolute or explicitly relative: darwin.nix./darwin.nix.

You should not use my home-manager fork directly, no. There is no maintenance being done on it.

Vendoring it like you did is fine in this case, though you could also fetch just that module:

builtins.fetchurl {
  url = "https://raw.githubusercontent.com/Atemu/home-manager/e6d905336181ed8f98d48a1f6c9965b77f18e304/modules/targets/darwin.nix";
  sha256 = "0lsa8ncwvv5qzar2sa8mxblhg6wcq5y6h9ny7kgmsby4wzaryz67";
}

so

{ config, pkgs, ... }:

{
  imports = [
    (builtins.fetchurl {
      url = "https://raw.githubusercontent.com/Atemu/home-manager/e6d905336181ed8f98d48a1f6c9965b77f18e304/modules/targets/darwin.nix";
      sha256 = "0lsa8ncwvv5qzar2sa8mxblhg6wcq5y6h9ny7kgmsby4wzaryz67";
    })
  ];
}

Note that all of this might be unnecessary very soon thanks to @wmertens’ suggestion. I’ve got a prototype working but it still has some kinks.

1 Like

Thank you @Atemu :slight_smile: it helped !
I’ve tried with ./darwin.nix, which works better, then I’ve switched to your second code example (using fetchurl) which is even better as at least the dependency is clearly visible.

However darwin.nix contains reference to hm (home-manager I presume) which are not resolved.

morganwattiez@Morgans-MBP> darwin-rebuild switch                                                                                                                                                                                   
building the system configuration...
warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels' does not exist, ignoring
error: undefined variable 'hm' at /nix/store/2jjwq219196qy

Your help means the world to me in my quest to use Nix, and if you can help with that also, thanks a lot !

Cheers,
Morgan

Are you importing it from the right place? I can see that you (also?) use nix-darwin, make sure you import my module in your home-manager config and not inside your nix-darwin one.
Nix-darwin’s lib doesn’t have home-manager’s lib.hm.

Thank you @Atemu , it brings me one step further :grinning_face_with_smiling_eyes:
Now I’m not sure what I’m doing wrong with my Nix / home-manager setup but the install of GUI apps (iTerm, Obsidian, …) is still not working (Spotlight does not find them), while the setup of CLI apps (fortune, htop, ripgrep… ) is perfectly smooth.

obsidian seems at least present on disk:

[130] morganwattiez@Morgans-MBP> ls ~/.nix-profile/share/applications                                                                                                                                                              
htop.desktop  obsidian.desktop

same for iTerm:

[130] morganwattiez@Morgans-MBP> cd ~/.nix-profile                                                                                                                                                                                             
morganwattiez@Morgans-MBP> ls -latr                                                                                                                                                                                                            
total 0
dr-xr-xr-x   13 morganwattiez admin   416 jan  1  1970 share
lrwxr-xr-x    1 morganwattiez admin    66 jan  1  1970 sbin -> /nix/store/p24v453k3pr1kp47zv2gkf0nmwqn8ndh-home-manager-path/sbin
lrwxr-xr-x    1 morganwattiez admin    60 jan  1  1970 manifest.nix -> /nix/store/w1ghs3flr8dlljpzzw4vg31a1irs25a0-env-manifest.nix
dr-xr-xr-x    5 morganwattiez admin   160 jan  1  1970 libexec
dr-xr-xr-x   13 morganwattiez admin   416 jan  1  1970 lib
lrwxr-xr-x    1 morganwattiez admin    62 jan  1  1970 include -> /nix/store/xycnp8n10jksy3myfalqhk1g69j79fqk-nix-2.3.14/include
dr-xr-xr-x    5 morganwattiez admin   160 jan  1  1970 etc
dr-xr-xr-x  139 morganwattiez admin  4448 jan  1  1970 bin
lrwxr-xr-x    1 morganwattiez admin    62 jan  1  1970 Library -> /nix/store/xycnp8n10jksy3myfalqhk1g69j79fqk-nix-2.3.14/Library
lrwxr-xr-x    1 morganwattiez admin    74 jan  1  1970 Applications -> /nix/store/p24v453k3pr1kp47zv2gkf0nmwqn8ndh-home-manager-path/Applications
dr-xr-xr-x   12 morganwattiez admin   384 jan  1  1970 .
drwxr-xr-x 2845 morganwattiez admin 91040 jul 20 12:35 ..

The Applications installation path for Iterm looks a bit misplaced but I’m not knowledgeable enough about Nix to tell what would be a better location.

morganwattiez@Morgans-MBP> ls -latr /nix/store/p24v453k3pr1kp47zv2gkf0nmwqn8ndh-home-manager-path/Applications                                                                                                                                 
lrwxr-xr-x 1 morganwattiez admin 69 jan  1  1970 /nix/store/p24v453k3pr1kp47zv2gkf0nmwqn8ndh-home-manager-path/Applications -> /nix/store/r1hh9k5qfjnsx251mcjgyfbf1c4zfsk2-iterm2-3.3.9/Applications
morganwattiez@Morgans-MBP> ls -latr /nix/store/r1hh9k5qfjnsx251mcjgyfbf1c4zfsk2-iterm2-3.3.9/Applications                                                                                                                                      
total 0
dr-xr-xr-x 3 morganwattiez admin 96 jan  1  1970 iTerm.app
dr-xr-xr-x 3 morganwattiez admin 96 jan  1  1970 ..
dr-xr-xr-x 3 morganwattiez admin 96 jan  1  1970 .

Given the logic in home-manager/darwin.nix at e6d905336181ed8f98d48a1f6c9965b77f18e304 · Atemu/home-manager · GitHub, I was expecting to find the apps installed in ~/Applications/Home Manager Apps/ but it seems this directory does not exist.

Any clue ?
my home.nix config below :

cat /Users/morganwattiez/.config/nixpkgs/home.nix
{ config, pkgs, ... }:

{
  imports = [
     (builtins.fetchurl {
      url = "https://raw.githubusercontent.com/Atemu/home-manager/e6d905336181ed8f98d48a1f6c9965b77f18e304/modules/targets/darwin.nix";
      sha256 = "0lsa8ncwvv5qzar2sa8mxblhg6wcq5y6h9ny7kgmsby4wzaryz67";
    })
  ];

  home.packages = with pkgs; [
    htop
    fortune
    iterm2
    obsidian
  #  pkgs.qbittorrent
  ];

  # Let Home Manager install and manage itself.
  programs.home-manager.enable = true;

  # Golang
  programs.go.enable = true;

  # Home Manager needs a bit of information about you and the
  # paths it should manage.
  home.username = "morganwattiez";
  home.homeDirectory = "/Users/morganwattiez";

  # This value determines the Home Manager release that your
  # configuration is compatible with. This helps avoid breakage
  # when a new Home Manager release introduces backwards
  # incompatible changes.
  #
  # You can update Home Manager without changing this value. See
  # the Home Manager release notes for a list of state version
  # changes in each release.
  home.stateVersion = "21.11";
}

I’m totally lost :slight_smile: and at this point I’m installing a few apps the old way until I can make it work in Nix, because I need to get some work done :grinning_face_with_smiling_eyes: (new job).

Thanks in advance for your help until now, @Atemu !

My module doesn’t enable any of its functionality by default for a few reasons. You need to enable darwin.installApps and darwin.fullCopies.

Thank you @Atemu !
It seems that the permissions might be wrong on the Applications or nix folder, as I get an error such as Permission Denied which looks similar to the one you link from your script : Mac Application launchers not symlinked on darwin · Issue #1341 · nix-community/home-manager · GitHub

[1] morganwattiez@Morgans-MBP> home-manager switch                                                                                                                                                                           
warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels' does not exist, ignoring
warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels' does not exist, ignoring
/nix/store/bmpixa5m5fn1f9cz919z0pqcp4k93gvh-home-manager-generation
Starting home manager activation
Activating checkFilesChanged
Activating checkLinkTargets
Activating writeBoundary
Activating copyFonts
Activating darwinApps
mkdir: cannot create directory ‘/Users/morganwattiez/Applications/Home Manager Apps’: Permission denied

I’ve tried creating the dir manually, also changing permissions (chown) using different combinations, but nothing helped. I guess that I might just accept Nix is not yet the complete tool I’m looking for installing GUI apps and I might switch to Homebrew for those ones, while using Nix for other CLI tools, unless I can solve this problem :grinning_face_with_smiling_eyes:

Thank you again, @Atemu

Hey,

I’m also using home-manager on MacOS and noticed the same thing, and noticed that the created home-manager generation does have Applications/* symlinks, they are just not being installed on my $HOME, so I did the following activation step:

That will link my apps, but they still are not showing up in Spotlight, maybe because they are symlinks ? Also tried to manually create a symlink like ln -s /nix/store/XXXX-SomeApp $HOME/Applications/Some.app but it also does not appear in Spotlight, :confused:

/Users/morganwattiez/Applications/Home Manager Apps might still be a symlink to the profile’s Application dir from your previous attempts.
It needs to either not exist or be a regular writable directory.

@vic read through the issue @MorganGeek linked in their last reply.

except by using sudo, I can’t even create this directory myself.
I’m not sure which are supposed to be the permissions for ~/Applications and ~/Applications/Home Manager Apps, but even when I change ownership to username:staff for the whole ~/Applications and /nix, invoking home-manager switch results in permission denied

morganwattiez@Morgans-MBP> sudo chown -R morganwattiez:staff ~/Applications/Home\ Manager\ Apps                                                                                 
morganwattiez@Morgans-MBP> home-manager switch                                                                                                                                   warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels' does not exist, ignoring
warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels' does not exist, ignoring
/nix/store/bmpixa5m5fn1f9cz919z0pqcp4k93gvh-home-manager-generation
Starting home manager activation
Activating checkFilesChanged
Activating checkLinkTargets
Activating writeBoundary
Activating copyFonts
Activating darwinApps
rm: cannot remove '/Users/morganwattiez/Applications/Home Manager Apps': Permission denied

Maybe I should redo the nix installation :thinking:

You use nix-darwin, right? ~/Applications itself might be a symlink to the Nix store. That’s why my module is disabled by default.

Thanks for your feedback, @Atemu
You’re right, I installed nix-darwin at the very beginning of my exploration of Nix for MacOS, by following the way other had paved before me (I saw a few installation guides and blog posts advising to install nix-darwin, and I followed the instructions naively).
Should I completely remove it in order to try your module then ?

I’ve proceed to uninstall nix-darwin using commands below

nix-build https://github.com/LnL7/nix-darwin/archive/master.tar.gz -A uninstaller
./result/bin/darwin-uninstaller
unlink /Users/morganwattiez/Applications

And now, running home-manager switch does the trick of having iTerm detected by Spotlight, so I’m happy :slight_smile: … next step will be to have other GUI apps running and located by Spotlight, but at least I see the light at the end of the tunnel :smiley:

Thanks for all the help, @Atemu

1 Like

After removing nix-darwin, I start to have the following issue : Problem with the SSL CA cert (path? access rights?)
When I try to nix-channel --update or install new packages. So I guess that’s not the ideal situation neither ;p

If ~/Applications already exists, nix-darwin will create ~/Applications/Nix Apps instead of symlinking it to ~/Applications. Since you (or home-manager created the folder, it should be safe to reinstall nix-darwin.

From what I recall, that certificate error happens when curl can’t find its certificates. Check to see if NIX_SSL_CERT_FILE is set in your environment and if it points to a dangling symlink or non-existent file (probably /etc/ssl/certs/ca-certificates.crt). That’s probably leftover cruft from your nix-darwin installation.

1 Like

I fixed the Certificate issue with something similar :slight_smile:

About the initial problem, I gave up using home-manager to install GUI apps on MacOs, it’s too much of a pain as some apps are not compatible (Obsidian for instance, but many others too). So I’ll just use the homebrew module for nix-darwin, at least for the Mac GUI Apps.

1 Like