From 17d7060f5d3cf847a7452149c9627887f58dfb84 Mon Sep 17 00:00:00 2001
From: WORLDofPEACE <worldofpeace@protonmail.ch>
Date: Sun, 20 Sep 2020 23:00:45 -0400
Subject: [PATCH 1/4] pantheon.elementary-session-settings: 2020-06-11 ->
 2020-07-06

Because gnome-session now uses 'enabled' systemd session we have
to make this use --builtin [0]

[0]: https://github.com/elementary/session-settings/commit/fa15cbd83fba0ba30e9a302db880350bff5ace52
---
 .../elementary-session-settings/default.nix   | 25 ++++++++++++-------
 1 file changed, 16 insertions(+), 9 deletions(-)

diff --git a/pkgs/desktops/pantheon/desktop/elementary-session-settings/default.nix b/pkgs/desktops/pantheon/desktop/elementary-session-settings/default.nix
index dba3c889508..30547d48706 100644
--- a/pkgs/desktops/pantheon/desktop/elementary-session-settings/default.nix
+++ b/pkgs/desktops/pantheon/desktop/elementary-session-settings/default.nix
@@ -64,22 +64,33 @@ let
   executable = writeScript "pantheon" ''
     export XDG_CONFIG_DIRS=${elementary-settings-daemon}/etc/xdg:${elementary-default-settings}/etc:$XDG_CONFIG_DIRS
     export XDG_DATA_DIRS=@out@/share:$XDG_DATA_DIRS
-    exec ${gnome-session}/bin/gnome-session --session=pantheon "$@"
+    exec ${gnome-session}/bin/gnome-session --builtin --session=pantheon "$@"
+  '';
+
+  xsession = writeText "pantheon.desktop" ''
+    [Desktop Entry]
+    Name=Pantheon
+    Comment=This session provides elementary experience
+    Exec=@out@/libexec/pantheon
+    TryExec=${wingpanel}/bin/wingpanel
+    Icon=
+    DesktopNames=Pantheon
+    Type=Application
   '';
 
 in
 
 stdenv.mkDerivation rec {
   pname = "elementary-session-settings-unstable";
-  version = "2020-06-11";
+  version = "2020-07-06";
 
   repoName = "session-settings";
 
   src = fetchFromGitHub {
     owner = "elementary";
     repo = repoName;
-    rev = "130c9ae221913032ed18bcf6d21e3dcdba3c4209";
-    sha256 = "0bzg9vbq0ssnxgcb2vxpx6x9zv8ngkm9r3ki5q83m9al9919n0pr";
+    rev = "fa15cbd83fba0ba30e9a302db880350bff5ace52";
+    hash = "sha256-26H791c7OAjFYtjVChIatICSocMt0uTej1TKBOvw+6w=";
   };
 
   nativeBuildInputs = [
@@ -112,12 +123,8 @@ stdenv.mkDerivation rec {
     mkdir -p $out/libexec
     substitute ${executable} $out/libexec/pantheon --subst-var out
     chmod +x $out/libexec/pantheon
-  '';
 
-  postFixup = ''
-    substituteInPlace $out/share/xsessions/pantheon.desktop \
-      --replace "gnome-session --session=pantheon" "$out/libexec/pantheon" \
-      --replace "wingpanel" "${wingpanel}/bin/wingpanel"
+    substitute ${xsession} $out/share/xsessions/pantheon.desktop --subst-var out
   '';
 
   passthru = {

From a4572eb18ebf4de6d99f217b5837e39693ac8826 Mon Sep 17 00:00:00 2001
From: WORLDofPEACE <worldofpeace@protonmail.ch>
Date: Fri, 25 Sep 2020 23:16:10 -0400
Subject: [PATCH 2/4] pantheon.elementary-settings-daemon: don't patch
 autostarts

These are now generated to be patched as a part of the elementary-session-settings
build.
---
 .../services/elementary-settings-daemon/default.nix    | 10 ----------
 1 file changed, 10 deletions(-)

diff --git a/pkgs/desktops/pantheon/services/elementary-settings-daemon/default.nix b/pkgs/desktops/pantheon/services/elementary-settings-daemon/default.nix
index e5aa31ca0fb..724a07d25bf 100644
--- a/pkgs/desktops/pantheon/services/elementary-settings-daemon/default.nix
+++ b/pkgs/desktops/pantheon/services/elementary-settings-daemon/default.nix
@@ -131,16 +131,6 @@ stdenv.mkDerivation rec {
   '';
 
   postFixup = ''
-    for autostart in $(grep -rl "OnlyShowIn=GNOME;" $out/etc/xdg/autostart)
-    do
-      echo "Patching OnlyShowIn to Pantheon in: $autostart"
-      sed -i "s,OnlyShowIn=GNOME;,OnlyShowIn=Pantheon;," $autostart
-    done
-
-    # This breaks lightlocker https://github.com/elementary/session-settings/commit/b0e7a2867608c3a3916f9e4e21a68264a20e44f8
-    # TODO: shouldn't be neeed for the 5.1 greeter (awaiting release)
-    rm $out/etc/xdg/autostart/org.gnome.SettingsDaemon.ScreensaverProxy.desktop
-
     # So the polkit policy can reference /run/current-system/sw/bin/elementary-settings-daemon/gsd-backlight-helper
     mkdir -p $out/bin/elementary-settings-daemon
     ln -s $out/libexec/gsd-backlight-helper $out/bin/elementary-settings-daemon/gsd-backlight-helper

From a48be6a7f270cdc44f5d1cb036403d468612dae1 Mon Sep 17 00:00:00 2001
From: WORLDofPEACE <worldofpeace@protonmail.ch>
Date: Fri, 25 Sep 2020 23:18:37 -0400
Subject: [PATCH 3/4] pantheon.elementary-session-settings: cleanup

---
 .../elementary-session-settings/default.nix    | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/pkgs/desktops/pantheon/desktop/elementary-session-settings/default.nix b/pkgs/desktops/pantheon/desktop/elementary-session-settings/default.nix
index 30547d48706..63e9fe3f6fa 100644
--- a/pkgs/desktops/pantheon/desktop/elementary-session-settings/default.nix
+++ b/pkgs/desktops/pantheon/desktop/elementary-session-settings/default.nix
@@ -62,11 +62,21 @@ let
   '';
 
   executable = writeScript "pantheon" ''
-    export XDG_CONFIG_DIRS=${elementary-settings-daemon}/etc/xdg:${elementary-default-settings}/etc:$XDG_CONFIG_DIRS
+    # gnome-session can find RequiredComponents for `pantheon` session (notably pantheon's patched g-s-d autostarts)
+    export XDG_CONFIG_DIRS=@out@/etc/xdg:$XDG_CONFIG_DIRS
+
+    # Make sure we use our gtk-3.0/settings.ini
+    export XDG_CONFIG_DIRS=${elementary-default-settings}/etc:$XDG_CONFIG_DIRS
+
+    # * gnome-session can find the `pantheon' session
+    # * use pantheon-mimeapps.list
     export XDG_DATA_DIRS=@out@/share:$XDG_DATA_DIRS
+
+    # Start pantheon session. Keep in sync with upstream
     exec ${gnome-session}/bin/gnome-session --builtin --session=pantheon "$@"
   '';
 
+  # Absolute path patched version of the upstream xsession
   xsession = writeText "pantheon.desktop" ''
     [Desktop Entry]
     Name=Pantheon
@@ -115,15 +125,21 @@ stdenv.mkDerivation rec {
   ];
 
   postInstall = ''
+    # our mimeapps patched from upstream to exclude:
+    # * pantheon-mail -> geary
+    # * evince.desktop -> org.gnome.Evince.desktop
     mkdir -p $out/share/applications
     cp -av ${./pantheon-mimeapps.list} $out/share/applications/pantheon-mimeapps.list
 
+    # instantiates pantheon's dockitems
     cp "${dockitemAutostart}" $out/etc/xdg/autostart/default-elementary-dockitems.desktop
 
+    # script `Exec` to start pantheon
     mkdir -p $out/libexec
     substitute ${executable} $out/libexec/pantheon --subst-var out
     chmod +x $out/libexec/pantheon
 
+    # absolute path patched xsession
     substitute ${xsession} $out/share/xsessions/pantheon.desktop --subst-var out
   '';
 

From b808ad4294be311ad1e7075d5995e06f3b3dce46 Mon Sep 17 00:00:00 2001
From: WORLDofPEACE <worldofpeace@protonmail.ch>
Date: Mon, 12 Oct 2020 18:11:46 -0400
Subject: [PATCH 4/4] pantheon.wingpanel-applications-menu: add
 switchboard-with-plugs deps

Fixes https://github.com/NixOS/nixpkgs/issues/100209
---
 .../applications-menu/default.nix                  | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/pkgs/desktops/pantheon/desktop/wingpanel-indicators/applications-menu/default.nix b/pkgs/desktops/pantheon/desktop/wingpanel-indicators/applications-menu/default.nix
index 3e58a2a101a..94d91329e3d 100644
--- a/pkgs/desktops/pantheon/desktop/wingpanel-indicators/applications-menu/default.nix
+++ b/pkgs/desktops/pantheon/desktop/wingpanel-indicators/applications-menu/default.nix
@@ -17,7 +17,7 @@
 , json-glib
 , elementary-dock
 , bamf
-, switchboard
+, switchboard-with-plugs
 , libunity
 , libsoup
 , wingpanel
@@ -53,7 +53,7 @@ stdenv.mkDerivation rec {
     pkgconfig
     python3
     vala
-   ];
+  ];
 
   buildInputs = [
     bamf
@@ -66,10 +66,16 @@ stdenv.mkDerivation rec {
     libhandy
     libsoup
     libunity
-    switchboard
+    switchboard-with-plugs
     wingpanel
     zeitgeist
-   ];
+  ] ++
+  # applications-menu has a plugin to search switchboard plugins
+  # see https://github.com/NixOS/nixpkgs/issues/100209
+  # wingpanel's wrapper will need to pick up the fact that
+  # applications-menu needs a version of switchboard with all
+  # its plugins for search.
+  switchboard-with-plugs.buildInputs;
 
   mesonFlags = [
     "--sysconfdir=${placeholder "out"}/etc"