diff --git a/hosts/airi/configuration.nix b/hosts/airi/configuration.nix index 8a5e6f8..e4c5e50 100644 --- a/hosts/airi/configuration.nix +++ b/hosts/airi/configuration.nix @@ -14,6 +14,11 @@ alacritty raycast karabiner + wireguard + brave + forkgram + snipaste + nekoray ])) (import (abs "users/teidesu/darwin.nix") {}) ]; diff --git a/lib/darwin/apps/common.nix b/lib/darwin/apps/common.nix index f224736..cba2588 100644 --- a/lib/darwin/apps/common.nix +++ b/lib/darwin/apps/common.nix @@ -14,13 +14,13 @@ rec { withMountedDmg = path: shell: '' _result=$(hdiutil mount ${path} | tail -n1) DMG_DEVICE=$(echo "$_result" | awk '{print $1}') - DMG_MOUNTPOINT=$(echo "$_result" | awk '{print $3}') + DMG_MOUNTPOINT=$(echo "$_result" | perl -lane 'print "@F[2..$#F]"') unset _result function _unmount { hdiutil unmount $DMG_DEVICE > /dev/null } - trap _unmount ERR exit + # trap _unmount ERR exit ${shell} @@ -65,4 +65,36 @@ rec { rm -rf $DOWNLOADED_FILE fi ''; + + downloadAndInstallZipApp = { + url, + filename, + params ? "", + renameTo ? null, + afterInstall ? "" + }: let + conditionFile = if renameTo == null then filename else renameTo; + in '' + if [ ! -d "/Applications/"${lib.escapeShellArg (builtins.baseNameOf conditionFile)} ]; then + ${download { inherit url params; }} + tmpdir=$(mktemp -d) + unzip -q $DOWNLOADED_FILE -d $tmpdir + + if [ ! -d "$tmpdir/"${lib.escapeShellArg filename} ]; then + echo "Error: file not found:" ${lib.escapeShellArg filename} + rm -rf $DOWNLOADED_FILE $tmpdir + exit 1 + fi + + ${if (renameTo != null) then '' + mv "$tmpdir/"${lib.escapeShellArg filename} "$tmpdir/"${lib.escapeShellArg renameTo} + mv "$tmpdir/"${lib.escapeShellArg renameTo} /Applications + '' else '' + mv "$tmpdir/"${lib.escapeShellArg filename} /Applications + ''} + rm -rf $DOWNLOADED_FILE $tmpdir + + ${afterInstall} + fi + ''; } \ No newline at end of file diff --git a/lib/darwin/apps/default.nix b/lib/darwin/apps/default.nix index cdda1f4..6b541be 100644 --- a/lib/darwin/apps/default.nix +++ b/lib/darwin/apps/default.nix @@ -9,7 +9,9 @@ # i'll just handle dmg's myself :D let - repo = pkgs.callPackage ./productivity.nix {}; + repo = + (pkgs.callPackage ./productivity.nix {}) + // (pkgs.callPackage ./system.nix {}); in appsFactory: { system.activationScripts.postUserActivation.text = '' set -eau diff --git a/lib/darwin/apps/productivity.nix b/lib/darwin/apps/productivity.nix index 02bec48..177061b 100644 --- a/lib/darwin/apps/productivity.nix +++ b/lib/darwin/apps/productivity.nix @@ -8,14 +8,25 @@ in with common; { filename = "Raycast.app"; }; + brave = downloadAndInstallDmgApp { + url = "https://referrals.brave.com/latest/BRV010/Brave-Browser.dmg"; + filename = "Brave Browser.app"; + }; + + snipaste = downloadAndInstallDmgApp { + url = "https://dl.snipaste.com/mac-beta"; + filename = "Snipaste.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"; + forkgram = downloadAndInstallZipApp { + url = "https://github.com/forkgram/tdesktop/releases/download/v4.16.10/Forkgram.macOS.no.auto-update_arm64.zip"; + filename = "Telegram.app"; + renameTo = "Forkgram.app"; }; } \ No newline at end of file diff --git a/lib/darwin/apps/system.nix b/lib/darwin/apps/system.nix new file mode 100644 index 0000000..13456f5 --- /dev/null +++ b/lib/darwin/apps/system.nix @@ -0,0 +1,25 @@ +{ callPackage }: + +let + common = callPackage ./common.nix {}; +in with common; { + wireguard = downloadAndInstallZipApp { + url = "https://s3.tei.su/wireguard-mac-1.0.16.zip"; + filename = "WireGuard.app"; + }; + + nekoray = downloadAndInstallZipApp { + url = "https://github.com/abbasnaqdi/nekoray-macos/releases/download/3.26/nekoray_arm64.zip"; + filename = "nekoray_arm64.app"; + renameTo = "nekoray.app"; + # https://github.com/abbasnaqdi/nekoray-macos/issues/64 + afterInstall = '' + plutil -insert LSUIElement -bool YES /Applications/nekoray.app/Contents/Info.plist + ''; + }; + + 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