about summary refs log tree commit diff
path: root/nixpkgs/pkgs/applications/networking/instant-messengers/mikutter/default.nix
diff options
context:
space:
mode:
Diffstat (limited to 'nixpkgs/pkgs/applications/networking/instant-messengers/mikutter/default.nix')
-rw-r--r--nixpkgs/pkgs/applications/networking/instant-messengers/mikutter/default.nix194
1 files changed, 136 insertions, 58 deletions
diff --git a/nixpkgs/pkgs/applications/networking/instant-messengers/mikutter/default.nix b/nixpkgs/pkgs/applications/networking/instant-messengers/mikutter/default.nix
index be84342787d2..111a3ed091e1 100644
--- a/nixpkgs/pkgs/applications/networking/instant-messengers/mikutter/default.nix
+++ b/nixpkgs/pkgs/applications/networking/instant-messengers/mikutter/default.nix
@@ -1,82 +1,160 @@
-{ lib, stdenv, fetchurl
-, bundlerEnv, ruby
-, alsaUtils, libnotify, which, wrapGAppsHook, gtk2, atk, gobject-introspection
+{ lib
+, stdenv
+, fetchurl
+, bundlerEnv
+, alsaUtils
+, atk
+, copyDesktopItems
+, gobject-introspection
+, gtk2
+, ruby
+, libicns
+, libnotify
+, makeDesktopItem
+, which
+, wrapGAppsHook
+, writeText
 }:
 
-# how to update:
-# find latest version at: http://mikutter.hachune.net/download#download
-# run these commands:
-#
-# wget http://mikutter.hachune.net/bin/mikutter.4.0.0.tar.gz
-# mkdir mikutter
-# cd mikutter
-# tar xvf ../mikutter.4.0.0.tar.gz
-# find . -not -name Gemfile -exec rm {} \;
-# find . -type d -exec rmdir -p --ignore-fail-on-non-empty {} \;
-# cd ..
-# mv mikutter/* .
-# rm mikutter.4.0.0.tar.gz
-# rm gemset.nix Gemfile.lock; nix-shell -p bundler bundix --run 'bundle lock && bundix'
-
-stdenv.mkDerivation rec {
+let
+  # NOTE: $out may have different values depending on context
+  mikutterPaths = rec {
+    optPrefixDir = "$out/opt/mikutter";
+    appPrefixDir = "$out/Applications/mikutter.app/Contents";
+    appBinDir = "${appPrefixDir}/MacOS";
+    appResourceDir = "${appPrefixDir}/Resources";
+    iconPath = "${optPrefixDir}/core/skin/data/icon.png";
+  };
+
+  gems = bundlerEnv {
+    name = "mikutter-gems"; # leave the version out to enable package reuse
+    gemdir = ./deps;
+    groups = [ "default" "plugin" ];
+    inherit ruby;
+
+    # Avoid the following error:
+    # > `<module:Moneta>': uninitialized constant Moneta::Builder (NameError)
+    #
+    # Related:
+    # https://github.com/NixOS/nixpkgs/pull/76510
+    # https://github.com/NixOS/nixpkgs/pull/76765
+    # https://github.com/NixOS/nixpkgs/issues/83442
+    # https://github.com/NixOS/nixpkgs/issues/106545
+    copyGemFiles = true;
+  };
+
+  mkDesktopItem = { description }:
+    makeDesktopItem {
+      name = "mikutter";
+      desktopName = "mikutter";
+      exec = "mikutter";
+      icon = "mikutter";
+      categories = "Network;";
+      comment = description;
+      extraDesktopEntries.Keywords = "Mastodon;";
+    };
+
+  mkInfoPlist = { version }:
+    writeText "Info.plist" (lib.generators.toPlist { } {
+      CFBundleName = "mikutter";
+      CFBundleDisplayName = "mikutter";
+      CFBundleExecutable = "mikutter";
+      CFBundleIconFile = "mikutter";
+      CFBundleIdentifier = "net.hachune.mikutter";
+      CFBundleInfoDictionaryVersion = "6.0";
+      CFBundlePackageType = "APPL";
+      CFBundleVersion = version;
+      CFBundleShortVersionString = version;
+    });
+
+  inherit (gems) wrappedRuby;
+in
+with mikutterPaths; stdenv.mkDerivation rec {
   pname = "mikutter";
-  version = "4.0.0";
+  version = "4.1.4";
 
   src = fetchurl {
-    url = "https://mikutter.hachune.net/bin/mikutter.${version}.tar.gz";
-    sha256 = "0nx14vlp7p69m2vw0s6kbiyymsfq0r2jd4nm0v5c4xb9avkpgc8g";
+    url = "https://mikutter.hachune.net/bin/mikutter-${version}.tar.gz";
+    sha256 = "05253nz4i1lmnq6czj48qdab2ny4vx2mznj6nsn2l1m2z6zqkwk3";
   };
 
-  buildInputs = [ alsaUtils libnotify which gtk2 ruby atk gobject-introspection ];
-  nativeBuildInputs = [ wrapGAppsHook ];
+  nativeBuildInputs = [ copyDesktopItems wrapGAppsHook ]
+    ++ lib.optionals stdenv.isDarwin [ libicns ];
+  buildInputs = [
+    atk
+    gtk2
+    gobject-introspection
+    libnotify
+    which # some plugins use it at runtime
+    wrappedRuby
+  ] ++ lib.optionals stdenv.isLinux [ alsaUtils ];
+
+  scriptPath = lib.makeBinPath (
+    [ wrappedRuby libnotify which ]
+    ++ lib.optionals stdenv.isLinux [ alsaUtils ]
+  );
 
-  unpackPhase = ''
-    mkdir source
-    cd source
-    unpackFile $src
+  postUnpack = ''
     rm -rf vendor
   '';
 
-  installPhase = let
-    env = bundlerEnv {
-      name = "mikutter-${version}-gems";
-      gemdir = ./.;
+  installPhase = ''
+    runHook preInstall
 
-      inherit ruby;
-    };
-  in ''
-    install -v -D -m644 README $out/share/doc/mikutter/README
-    install -v -D -m644 LICENSE $out/share/doc/mikutter/LICENSE
-    rm -v README LICENSE
-
-    cp -rv . $out
-    mkdir $out/bin/
-    # hack wrapGAppsHook wants a file not a symlink
-    mv $out/mikutter.rb $out/bin/mikutter
-
-    gappsWrapperArgs+=(
-      --prefix PATH : "${ruby}/bin:${alsaUtils}/bin:${libnotify}/bin"
-      --prefix GEM_HOME : "${env}/${env.ruby.gemPath}"
+    mkdir -p $out/bin ${optPrefixDir}
+
+    install -Dm644 README $out/share/doc/mikutter/README
+    install -Dm644 LICENSE $out/share/doc/mikutter/LICENSE
+    rm -r README LICENSE deployment
+
+    cp -r . ${optPrefixDir}
+
+    gappsWrapperArgsHook # FIXME: currently runs at preFixup
+    wrapGApp ${optPrefixDir}/mikutter.rb \
+      --prefix PATH : "${scriptPath}" \
       --set DISABLE_BUNDLER_SETUP 1
-    )
-      # --prefix GIO_EXTRA_MODULES : "$prefix/lib/gio/modules"
+    mv ${optPrefixDir}/mikutter.rb $out/bin/mikutter
+
+    install -Dm644 ${iconPath} $out/share/icons/hicolor/256x256/apps/mikutter.png
 
-    mkdir -p $out/share/mikutter $out/share/applications
-    ln -sv $out/core/skin $out/share/mikutter/skin
-    substituteAll ${./mikutter.desktop} $out/share/applications/mikutter.desktop
+    runHook postInstall
   '';
 
-  postFixup = ''
-    mv $out/bin/.mikutter-wrapped $out/mikutter.rb
-    substituteInPlace $out/bin/mikutter \
-      --replace "$out/bin/.mikutter-wrapped" "$out/mikutter.rb"
+  postInstall =
+    let
+      infoPlist = mkInfoPlist { inherit version; };
+    in
+    lib.optionalString stdenv.isDarwin ''
+      mkdir -p ${appBinDir} ${appResourceDir}
+      install -Dm644 ${infoPlist} ${appPrefixDir}/Info.plist
+      ln -s $out/bin/mikutter ${appBinDir}/mikutter
+      png2icns ${appResourceDir}/mikutter.icns ${iconPath}
+    '';
+
+  installCheckPhase = ''
+    runHook preInstallCheck
+
+    testDir="$(mktemp -d)"
+    install -Dm644 ${./test_plugin.rb} "$testDir/plugin/test_plugin/test_plugin.rb"
+
+    $out/bin/mikutter --confroot="$testDir" --plugin=test_plugin --debug
+
+    runHook postInstallCheck
   '';
 
+  desktopItems = [
+    (mkDesktopItem { inherit (meta) description; })
+  ];
+
+  doInstallCheck = true;
+  dontWrapGApps = true; # the target is placed outside of bin/
+
+  passthru.updateScript = [ ./update.sh version (toString ./.) ];
+
   meta = with lib; {
-    description = "An extensible Twitter client";
+    description = "An extensible Mastodon client";
     homepage = "https://mikutter.hachune.net";
     platforms = ruby.meta.platforms;
     license = licenses.mit;
-    broken = true;
   };
 }