about summary refs log tree commit diff
path: root/pkgs/applications/networking/mailreaders
diff options
context:
space:
mode:
authorDoron Behar <doron.behar@gmail.com>2020-08-15 11:23:06 +0300
committerJon <jonringer@users.noreply.github.com>2020-08-15 10:17:06 -0700
commit6c3d919edfb208f52c3f0e7f6e3a624f277ee16a (patch)
tree0c5de8068e28b78bd9a47fa8ef9a011b22ea2bdb /pkgs/applications/networking/mailreaders
parentddb962bec4da59d20762a34e235b5df57a77f660 (diff)
mailnag: implement a withPlugins interface
Diffstat (limited to 'pkgs/applications/networking/mailreaders')
-rw-r--r--pkgs/applications/networking/mailreaders/mailnag/default.nix149
1 files changed, 77 insertions, 72 deletions
diff --git a/pkgs/applications/networking/mailreaders/mailnag/default.nix b/pkgs/applications/networking/mailreaders/mailnag/default.nix
index b44d90f1d760a..6d315049d2407 100644
--- a/pkgs/applications/networking/mailreaders/mailnag/default.nix
+++ b/pkgs/applications/networking/mailreaders/mailnag/default.nix
@@ -15,86 +15,91 @@
 , gobject-introspection
 # Available plugins (can be overriden)
 , availablePlugins
-# Plugins to install
-, plugins ? [ "goa" ]
+# Used in the withPlugins interface at passthru, can be overrided directly, or
+# prefarably via e.g: `mailnag.withPlugins(["goa"])`
+, mailnag
+, userPlugins ? [ ]
+, pluginsDeps ? [ ]
 }:
 
-let
-  # Get the list of plugins the user wants
-  userPlugins = lib.attrVals plugins availablePlugins;
-  # goa plugin requires gio's gnome-online-accounts which requires making sure
-  # mailnag runs with GI_TYPELIB_PATH containing the path to Goa-1.0.typelib.
-  # This is handled best by adding the plugins' deps to buildInputs and let
-  # wrapGAppsHook handle that.
-  pluginsDeps = lib.flatten (lib.catAttrs "buildInputs" userPlugins);
-in
-  python3Packages.buildPythonApplication rec {
-    pname = "mailnag";
-    version = "2.0.0";
+python3Packages.buildPythonApplication rec {
+  pname = "mailnag";
+  version = "2.0.0";
 
-    src = fetchFromGitHub {
-      owner = "pulb";
-      repo = "mailnag";
-      rev = "v${version}";
-      sha256 = "0q97v9i96br22z3h6r2mz79i68ib8m8x42yxky78szfrf8j60i30";
-    };
+  src = fetchFromGitHub {
+    owner = "pulb";
+    repo = "mailnag";
+    rev = "v${version}";
+    sha256 = "0q97v9i96br22z3h6r2mz79i68ib8m8x42yxky78szfrf8j60i30";
+  };
 
-    buildInputs = [
-      gtk3
-      gdk-pixbuf
-      glib
-      libnotify
-      gst_all_1.gstreamer
-      gst_all_1.gst-plugins-base
-      gst_all_1.gst-plugins-good
-      gst_all_1.gst-plugins-bad
-      gobject-introspection
-      libsecret
-    ] ++ pluginsDeps;
+  buildInputs = [
+    gtk3
+    gdk-pixbuf
+    glib
+    libnotify
+    gst_all_1.gstreamer
+    gst_all_1.gst-plugins-base
+    gst_all_1.gst-plugins-good
+    gst_all_1.gst-plugins-bad
+    gobject-introspection
+    libsecret
+  ] ++ pluginsDeps;
 
-    nativeBuildInputs = [
-      gettext
-      wrapGAppsHook
-      # To later add plugins to 
-      xorg.lndir
-    ];
+  nativeBuildInputs = [
+    gettext
+    wrapGAppsHook
+    # To later add plugins to 
+    xorg.lndir
+  ];
 
-    propagatedBuildInputs = with python3Packages; [
-      gsettings-desktop-schemas
-      pygobject3
-      dbus-python
-      pyxdg
-    ];
+  propagatedBuildInputs = with python3Packages; [
+    gsettings-desktop-schemas
+    pygobject3
+    dbus-python
+    pyxdg
+  ];
 
-    passthru = {
-      inherit availablePlugins;
-    };
+  passthru = {
+    inherit availablePlugins;
+    withPlugins =
+      plugs:
+      let
+        # goa plugin requires gio's gnome-online-accounts which requires making sure
+        # mailnag runs with GI_TYPELIB_PATH containing the path to Goa-1.0.typelib.
+        # This is handled best by adding the plugins' deps to buildInputs and let
+        # wrapGAppsHook handle that.
+        pluginsDeps = lib.flatten (lib.catAttrs "buildInputs" plugs);
+        self = mailnag;
+      in
+        self.override { userPlugins = plugs; };
+  };
 
-    # See https://nixos.org/nixpkgs/manual/#ssec-gnome-common-issues-double-wrapped
-    dontWrapGApps = true;
+  # See https://nixos.org/nixpkgs/manual/#ssec-gnome-common-issues-double-wrapped
+  dontWrapGApps = true;
 
-    preFixup = ''
-      substituteInPlace $out/${python3Packages.python.sitePackages}/Mailnag/common/dist_cfg.py \
-        --replace "/usr/" $out/
-      for desktop_file in $out/share/applications/*.desktop; do
-        substituteInPlace "$desktop_file" \
-        --replace "/usr/bin" $out/bin
-      done
-      makeWrapperArgs+=("''${gappsWrapperArgs[@]}")
-    '';
+  preFixup = ''
+    substituteInPlace $out/${python3Packages.python.sitePackages}/Mailnag/common/dist_cfg.py \
+      --replace "/usr/" $out/
+    for desktop_file in $out/share/applications/*.desktop; do
+      substituteInPlace "$desktop_file" \
+      --replace "/usr/bin" $out/bin
+    done
+    makeWrapperArgs+=("''${gappsWrapperArgs[@]}")
+  '';
 
-    # Actually install plugins
-    postInstall = ''
-      for plug in ${builtins.toString userPlugins}; do
-        lndir $plug/${python3Packages.python.sitePackages} $out/${python3Packages.python.sitePackages}
-      done
-    '';
+  # Actually install plugins
+  postInstall = ''
+    for plug in ${builtins.toString userPlugins}; do
+      lndir $plug/${python3Packages.python.sitePackages} $out/${python3Packages.python.sitePackages}
+    done
+  '';
 
-    meta = with lib; {
-      description = "An extensible mail notification daemon";
-      homepage = "https://github.com/pulb/mailnag";
-      license = licenses.gpl2;
-      platforms = platforms.linux;
-      maintainers = with maintainers; [ doronbehar ];
-    };
-  }
+  meta = with lib; {
+    description = "An extensible mail notification daemon";
+    homepage = "https://github.com/pulb/mailnag";
+    license = licenses.gpl2;
+    platforms = platforms.linux;
+    maintainers = with maintainers; [ doronbehar ];
+  };
+}