Skip to content

Instantly share code, notes, and snippets.

@elliottminns
Last active December 26, 2025 20:51
Show Gist options
  • Select an option

  • Save elliottminns/211ef645ebd484eb9a5228570bb60ec3 to your computer and use it in GitHub Desktop.

Select an option

Save elliottminns/211ef645ebd484eb9a5228570bb60ec3 to your computer and use it in GitHub Desktop.
system.activationScripts.applications.text = let
env = pkgs.buildEnv {
name = "system-applications";
paths = config.environment.systemPackages;
pathsToLink = "/Applications";
};
in
pkgs.lib.mkForce ''
# Set up applications.
echo "setting up /Applications..." >&2
rm -rf /Applications/Nix\ Apps
mkdir -p /Applications/Nix\ Apps
find ${env}/Applications -maxdepth 1 -type l -exec readlink '{}' + |
while read -r src; do
app_name=$(basename "$src")
echo "copying $src" >&2
${pkgs.mkalias}/bin/mkalias "$src" "/Applications/Nix Apps/$app_name"
done
'';
@shaoyanji

Copy link
Copy Markdown

for nix-unstable and your future viewers of your channel 25.05 and later will deprecated this line:

(pkgs.nerdfonts.override { fonts = [ "JetBrainsMono" ]; })

and it will go with this:

pkgs.nerd-fonts.jetbrains-mono

one the the downsides of nix is that reproducibility comes at the price if you want to get the benefits of better and cleaner nix language and have nix flake update command work.

@Djang0

Djang0 commented Dec 9, 2024

Copy link
Copy Markdown

I used the activation script in my config, but alacritty is still not visible in spotlight :/

@shaoyanji

Copy link
Copy Markdown

I used the activation script in my config, but alacritty is still not visible in spotlight :/

it does have to be an environment system package for it to be read.

this script works for kitty for example, but doesn't for wezterm because i have it as a home manager module. the creature comfort with spotlight isn't great because aliases are a little lower than a websearch. i use raycast as a spotlight replacement through homebrew.

but what is great about this script is that it gives you an opening to adapt it to add home manager aliases, just replace /Applications/Nix\ Apps to ~/Applications/Home\ Manager (i'm not a fan of bash).

@ricardogaspar2

Copy link
Copy Markdown

Just a suggestion, I've used this utility on my flake.nix and it worked like a charm. No need to define an activation script
https://github.com/hraban/mac-app-util
Credits to the developer @hraban

Thanks for the video tutorial, it really helped.

@waseemhnyc

Copy link
Copy Markdown

+1 ☝️ to using @hraban https://github.com/hraban/mac-app-util

Worked like a charm

@frarredondo

Copy link
Copy Markdown

++1 ☝🏽using https://github.com/hraban/mac-app-util

Worked perfectly and was super easy to add to my config file.

@tylercritchlow

Copy link
Copy Markdown

++1 ☝🏽using https://github.com/hraban/mac-app-util

Worked perfectly and was super easy to add to my config file.

Do you mind sharing your flake.nix with mac-app-util? I tried it, and it doesn't work for me.

@frarredondo

Copy link
Copy Markdown

@tylercritchlow Sure! I've uploaded a copy here: https://gist.github.com/frarredondo/192930a454c992f306143bfc4eefc948

I will say that after posting my comment above i very quickly learned that very few packages were actually available for aarch64-darwin and found that i needed to install everything via homebrew so i didn't see the point in using nix at least on apple silicon atm and uninstalled it and went back to using homebrew for package management.

@snajahi

snajahi commented May 30, 2025

Copy link
Copy Markdown

@ricardogaspar2 Great suggestion, works like a charm 🤝

@Kapi2910

Copy link
Copy Markdown

@frarredondo Thanks for the snippet.

when I try to run the flake, I get this warning:

warning: /Applications/Nix Apps is not owned by nix-darwin, skipping App linking...

Any idea how to fix this?

@frarredondo

Copy link
Copy Markdown

@Kapi2910 - You could try to remove (or rename) the old directory, then re-run your rebuild so nix-darwin can create its symlink.

@mikewebbtech

Copy link
Copy Markdown

mac-app-util ... This is the way. I had to delete my existing /Applications/Nix Apps and re-run my darwin-rebuild command for the magic to happen.

@Kapi2910

Copy link
Copy Markdown

@mikewebbtech That worked. Thank you so much.

@x44annie

x44annie commented Jul 28, 2025

Copy link
Copy Markdown

{
description = "Example nix-darwin system flake";

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
nix-darwin.url = "github:nix-darwin/nix-darwin/master";
nix-darwin.inputs.nixpkgs.follows = "nixpkgs";
};

outputs = inputs@{ self, nixpkgs, nix-darwin, ... }:
let
system = "aarch64-darwin";

  configuration = { config, pkgs, ... }:

    let
      env = pkgs.buildEnv {
        name = "system-applications";
        paths = config.environment.systemPackages;
        pathsToLink = "/Applications";
      };
    in {
      environment.systemPackages = with pkgs; [
        neovim
      ];

      system.activationScripts.applications.text = pkgs.lib.mkForce ''
        echo "setting up /Applications..." >&2
        rm -rf /Applications/Nix\ Apps
        mkdir -p /Applications/Nix\ Apps
        find ${env}/Applications -maxdepth 1 -type l -exec readlink '{}' + |
        while read -r src; do
          app_name=$(basename "$src")
          echo "copying $src" >&2
          ${pkgs.mkalias}/bin/mkalias "$src" "/Applications/Nix Apps/$app_name"
        done
      '';

      nix.settings.experimental-features = "nix-command flakes";

      system.configurationRevision = self.rev or self.dirtyRev or null;
      system.stateVersion = 6;
      nixpkgs.hostPlatform = system;
    };
in {
  darwinConfigurations."mini" = nix-darwin.lib.darwinSystem {
    inherit system;
    modules = [ configuration ];
  };
};

}

This is how I fixed it :)

@seriouspoop

Copy link
Copy Markdown

for the latest nix version the function pkgs.buildEnv expects pathsToLink to be a list (like ["/A"]).

pathsToLink = ["/Applications"];

@LoudiliMed

LoudiliMed commented Dec 26, 2025

Copy link
Copy Markdown

For the latest nix version you should wrap "/Applications" with [ ] in order to work and I think you should add system.applications.enable = true;. after system.activationScripts.applications.text = let , so Nix-darwin can manage macOS applications correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment