feat(darwin): provisioning apps

This commit is contained in:
alina 🌸 2024-05-01 06:01:46 +03:00
parent a0cf3f1a3c
commit 9fd48b2ca9
Signed by: teidesu
SSH key fingerprint: SHA256:uNeCpw6aTSU4aIObXLvHfLkDa82HWH9EiOj9AXOIRpI
3 changed files with 107 additions and 0 deletions

View file

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

View file

@ -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 {})

View file

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