diff --git a/lib/darwin/apps/common.nix b/lib/darwin/apps/common.nix new file mode 100644 index 0000000..851eaca --- /dev/null +++ b/lib/darwin/apps/common.nix @@ -0,0 +1,68 @@ +{ wget, lib, ... }: + +rec { + download = { + url, + params ? "", + var ? "DOWNLOADED_FILE" + }: '' + echo "Downloading" ${lib.escapeShellArg url}"..." + ${var}=$(mktemp) + ${wget}/bin/wget ${lib.escapeShellArg url} ${params} -q --show-progress -O ${"$" + var} + ''; + + withMountedDmg = path: shell: '' + _result=$(hdiutil mount ${path} | tail -n1) + DMG_DEVICE=$(echo "$_result" | awk '{print $1}') + DMG_MOUNTPOINT=$(echo "$_result" | awk '{print $3}') + unset _result + + function _unmount { + hdiutil unmount $DMG_DEVICE > /dev/null + } + trap _unmount ERR exit + + ${shell} + + _unmount + trap - ERR exit + unset DMG_DEVICE + unset DMG_MOUNTPOINT + ''; + + installAppFromDmg = { dmg, filename }: withMountedDmg dmg '' + if [ ! -d "$DMG_MOUNTPOINT/"${lib.escapeShellArg filename} ]; then + echo "Error: file not found:" ${lib.escapeShellArg filename} + exit 1 + fi + + cp -r "$DMG_MOUNTPOINT/"${lib.escapeShellArg filename} /Applications + ''; + + downloadAndInstallDmgApp = { + url, + filename, + params ? "", + }: '' + if [ ! -d "/Applications/"${lib.escapeShellArg (builtins.baseNameOf filename)} ]; then + ${download { inherit url params; }} + ${installAppFromDmg { dmg = "$DOWNLOADED_FILE"; inherit filename; }} + rm -rf $DOWNLOADED_FILE + fi + ''; + + downloadAndInstallDmgPkg = { + url, + filename, + condition, + params ? "", + }: '' + if [ ${condition} ]; then + ${download { inherit url params; }} + ${withMountedDmg "$DOWNLOADED_FILE" '' + installer -pkg "$DMG_MOUNTPOINT/"${lib.escapeShellArg filename} -target / + ''} + rm -rf $DOWNLOADED_FILE + fi + ''; +} \ No newline at end of file diff --git a/lib/darwin/apps/default.nix b/lib/darwin/apps/default.nix new file mode 100644 index 0000000..277dd42 --- /dev/null +++ b/lib/darwin/apps/default.nix @@ -0,0 +1,18 @@ +{ callPackage, ... }: + +# i want to be able to declaratively *provision* gui apps on macos, +# but have them manage themselves later on, not managed by nix-darwin, +# since most of them are auto-updating and managing them entirely through +# nix is a bit of a pain. +# +# homebrew sucks and i don't want to give it *any* recognition, so guess +# i'll just handle dmg's myself :D + +{ + provisionApps = apps: { + home.activation.provisionApps = '' + set -eau + ${builtins.concatStringsSep "\n" apps} + ''; + }; +} // (callPackage ./productivity.nix {}) \ No newline at end of file diff --git a/lib/darwin/apps/productivity.nix b/lib/darwin/apps/productivity.nix new file mode 100644 index 0000000..bff2420 --- /dev/null +++ b/lib/darwin/apps/productivity.nix @@ -0,0 +1,21 @@ +{ callPackage, ... }: + +let + common = callPackage ./common.nix {}; +in with common; { + raycast = downloadAndInstallDmgApp { + url = "https://releases.raycast.com/download"; + filename = "Raycast.app"; + }; + + karabiner = downloadAndInstallDmgPkg { + url = "https://github.com/pqrs-org/Karabiner-Elements/releases/download/v14.13.0/Karabiner-Elements-14.13.0.dmg"; + filename = "Karabiner-Elements.pkg"; + condition = "! -d /Applications/Karabiner-Elements.app"; + }; + + alacritty = downloadAndInstallDmgApp { + url = "https://github.com/alacritty/alacritty/releases/download/v0.13.2/Alacritty-v0.13.2.dmg"; + filename = "Alacritty.app"; + }; +} \ No newline at end of file