Skip to content

Instantly share code, notes, and snippets.

@elliottminns
Created October 7, 2024 14:27
Show Gist options
  • Save elliottminns/211ef645ebd484eb9a5228570bb60ec3 to your computer and use it in GitHub Desktop.
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 src; do
app_name=$(basename "$src")
echo "copying $src" >&2
${pkgs.mkalias}/bin/mkalias "$src" "/Applications/Nix Apps/$app_name"
done
'';
@shaoyanji
Copy link

line 14 needs to be revised to read -r for the latest nix flake update command per: https://www.shellcheck.net/wiki/SC2162

was weird to debug this and happened to recall the syntax of this script since it was more shell than nixlang.

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

@elliottminns
Copy link
Author

line 14 needs to be revised to read -r for the latest nix flake update command per: https://www.shellcheck.net/wiki/SC2162

was weird to debug this and happened to recall the syntax of this script since it was more shell than nixlang.

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

Thank you! Will update the video amendments as well.

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