summary refs log tree commit diff
path: root/pkgs/build-support/setup-hooks
diff options
context:
space:
mode:
authorMatthew Leach <dev@mattleach.net>2021-07-28 22:31:09 +0100
committerMatthew Leach <dev@mattleach.net>2022-02-10 18:53:53 +0000
commit850fc57f56d9f6732e6eaa5688ce2d6e9f4f2d09 (patch)
tree6a4c719289c6263015d0f1986dd8696340b67113 /pkgs/build-support/setup-hooks
parentc9a82c489334610bde1c3ab8b635298aa2a18c63 (diff)
downloadnixpkgs-850fc57f56d9f6732e6eaa5688ce2d6e9f4f2d09.tar
nixpkgs-850fc57f56d9f6732e6eaa5688ce2d6e9f4f2d09.tar.gz
nixpkgs-850fc57f56d9f6732e6eaa5688ce2d6e9f4f2d09.tar.bz2
nixpkgs-850fc57f56d9f6732e6eaa5688ce2d6e9f4f2d09.tar.lz
nixpkgs-850fc57f56d9f6732e6eaa5688ce2d6e9f4f2d09.tar.xz
nixpkgs-850fc57f56d9f6732e6eaa5688ce2d6e9f4f2d09.tar.zst
nixpkgs-850fc57f56d9f6732e6eaa5688ce2d6e9f4f2d09.zip
build-support: make-darwin-bundle: new
Add a new module that allows darwin-style application bundles to be
created
Diffstat (limited to 'pkgs/build-support/setup-hooks')
-rw-r--r--pkgs/build-support/setup-hooks/desktop-to-darwin-bundle.sh48
1 files changed, 48 insertions, 0 deletions
diff --git a/pkgs/build-support/setup-hooks/desktop-to-darwin-bundle.sh b/pkgs/build-support/setup-hooks/desktop-to-darwin-bundle.sh
new file mode 100644
index 00000000000..d1175d3a5f9
--- /dev/null
+++ b/pkgs/build-support/setup-hooks/desktop-to-darwin-bundle.sh
@@ -0,0 +1,48 @@
+#!/usr/bin/env bash
+fixupOutputHooks+=('convertDesktopFiles $prefix')
+
+# Get a param out of a desktop file. First parameter is the file and the second
+# is a pattern of the key who's value we should fetch.
+getDesktopParam() {
+    local file="$1";
+    local pattern="$2";
+
+    awk -F "=" "/${pattern}/ {print \$2}" "${file}"
+}
+
+# For a given .desktop file, generate a darwin '.app' bundle for it.
+convertDesktopFile() {
+    local -r file="$1"
+    local -r name=$(getDesktopParam "${file}" "^Name")
+    local -r exec=$(getDesktopParam "${file}" "Exec")
+    local -r iconName=$(getDesktopParam "${file}" "Icon")
+    local -r iconFiles=$(find "$out/share/icons/" -name "${iconName}.*" 2>/dev/null);
+    local -r pixMaps=$(find "$out/share/pixmaps/" -name "${iconName}.xpm" 2>/dev/null);
+
+    mkdir -p "$out/Applications/${name}.app/Contents/MacOS"
+    mkdir -p "$out/Applications/${name}.app/Contents/Resources"
+
+    local i=0;
+    for icon in $iconFiles; do
+      ln -s "$icon" "$out/Applications/${name}.app/Contents/Resources/$i-$(basename "$icon")"
+      (( i +=1 ));
+    done
+
+    for pixmap in $pixMaps; do
+      local newIconName="$i-$(basename "$pixmap")";
+      convert "$pixmap" "$out/Applications/${name}.app/Contents/Resources/${newIconName%.xpm}.png"
+      (( i +=1 ));
+    done
+
+    write-darwin-bundle "$out" "$name" "$exec"
+}
+
+convertDesktopFiles() {
+    local dir="$1/share/applications/"
+
+    if [ -d "${dir}" ]; then
+        for desktopFile in $(find "$dir" -iname "*.desktop"); do
+            convertDesktopFile "$desktopFile";
+        done
+    fi
+}