From 9b166f0db22a1cecabc88013c66dd6e0691e9a06 Mon Sep 17 00:00:00 2001 From: "Alexander V. Nikolaev" Date: Tue, 1 Dec 2015 13:45:06 +0200 Subject: [PATCH 1/2] Use absolute path to load libxcb.so --- pkgs/top-level/python-packages.nix | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pkgs/top-level/python-packages.nix b/pkgs/top-level/python-packages.nix index 537decb24ca0..5505ab0b1cb1 100644 --- a/pkgs/top-level/python-packages.nix +++ b/pkgs/top-level/python-packages.nix @@ -21967,6 +21967,11 @@ in modules // { md5 = "fa13f3fee67c83016a1242982a7c8bda"; }; + patchPhase = '' + # Hardcode cairo library path + sed -e 's,ffi\.dlopen(,&"${pkgs.xorg.libxcb}/lib/" + ,' -i xcffib/__init__.py + ''; + propagatedBuildInputs = [ self.cffi self.six ]; meta = { From 28c44a15c76bb92d56a69e621e83b377ad9d3688 Mon Sep 17 00:00:00 2001 From: "Alexander V. Nikolaev" Date: Tue, 1 Dec 2015 13:46:18 +0200 Subject: [PATCH 2/2] qtile: rework package * Use absolute paths to load gobject, pango and cairo. * Add xcb-cursor support (also with absolute path) * Avoid tainting child processes environment: Save PATH and PYTHONPATH in wrapper, and restore them in python code. * Alter restart process, using $0 saved in wrapper, which allow user to restart qtile after system rebuild to upgrade it. --- ...Substitution-vars-for-absolute-paths.patch | 43 ++++++++++++ .../0002-Restore-PATH-and-PYTHONPATH.patch | 67 +++++++++++++++++++ .../qtile/0003-Restart-executable.patch | 25 +++++++ .../window-managers/qtile/default.nix | 30 +++++---- .../qtile/restart_executable.patch | 12 ---- 5 files changed, 152 insertions(+), 25 deletions(-) create mode 100644 pkgs/applications/window-managers/qtile/0001-Substitution-vars-for-absolute-paths.patch create mode 100644 pkgs/applications/window-managers/qtile/0002-Restore-PATH-and-PYTHONPATH.patch create mode 100644 pkgs/applications/window-managers/qtile/0003-Restart-executable.patch delete mode 100644 pkgs/applications/window-managers/qtile/restart_executable.patch diff --git a/pkgs/applications/window-managers/qtile/0001-Substitution-vars-for-absolute-paths.patch b/pkgs/applications/window-managers/qtile/0001-Substitution-vars-for-absolute-paths.patch new file mode 100644 index 000000000000..e3c88a5fa551 --- /dev/null +++ b/pkgs/applications/window-managers/qtile/0001-Substitution-vars-for-absolute-paths.patch @@ -0,0 +1,43 @@ +From 00c5af939567429d40877845dc52b54fde2d8a50 Mon Sep 17 00:00:00 2001 +From: "Alexander V. Nikolaev" +Date: Thu, 26 Nov 2015 10:53:12 +0200 +Subject: [PATCH 1/3] Substitution vars for absolute paths + +--- + libqtile/pangocffi.py | 6 +++--- + libqtile/xcursors.py | 2 +- + 2 files changed, 4 insertions(+), 4 deletions(-) + +diff --git a/libqtile/pangocffi.py b/libqtile/pangocffi.py +index 27691d1..25f690d 100644 +--- a/libqtile/pangocffi.py ++++ b/libqtile/pangocffi.py +@@ -58,9 +58,9 @@ except ImportError: + else: + raise ImportError("No module named libqtile._ffi_pango, be sure to run `python ./libqtile/ffi_build.py`") + +-gobject = ffi.dlopen('libgobject-2.0.so.0') +-pango = ffi.dlopen('libpango-1.0.so.0') +-pangocairo = ffi.dlopen('libpangocairo-1.0.so.0') ++gobject = ffi.dlopen('@glib@/lib/libgobject-2.0.so.0') ++pango = ffi.dlopen('@pango@/lib/libpango-1.0.so.0') ++pangocairo = ffi.dlopen('@pango@/lib/libpangocairo-1.0.so.0') + + + def CairoContext(cairo_t): +diff --git a/libqtile/xcursors.py b/libqtile/xcursors.py +index e0e55e1..59b6428 100644 +--- a/libqtile/xcursors.py ++++ b/libqtile/xcursors.py +@@ -114,7 +114,7 @@ class Cursors(dict): + + def _setup_xcursor_binding(self): + try: +- xcursor = ffi.dlopen('libxcb-cursor.so') ++ xcursor = ffi.dlopen('@xcb-cursor@/lib/libxcb-cursor.so') + except OSError: + self.log.warning("xcb-cursor not found, fallback to font pointer") + return False +-- +2.6.3 + diff --git a/pkgs/applications/window-managers/qtile/0002-Restore-PATH-and-PYTHONPATH.patch b/pkgs/applications/window-managers/qtile/0002-Restore-PATH-and-PYTHONPATH.patch new file mode 100644 index 000000000000..ba408b1f05bb --- /dev/null +++ b/pkgs/applications/window-managers/qtile/0002-Restore-PATH-and-PYTHONPATH.patch @@ -0,0 +1,67 @@ +From f299a0aa0eefcf16bb4990f00ac3946727f43ef3 Mon Sep 17 00:00:00 2001 +From: "Alexander V. Nikolaev" +Date: Fri, 27 Nov 2015 10:49:48 +0200 +Subject: [PATCH 2/3] Restore PATH and PYTHONPATH + +--- + bin/qtile | 1 + + bin/qtile-run | 1 + + bin/qtile-session | 2 ++ + libqtile/utils.py | 7 +++++++ + 4 files changed, 11 insertions(+) + +diff --git a/bin/qtile b/bin/qtile +index 66034fe..ce3fcd1 100755 +--- a/bin/qtile ++++ b/bin/qtile +@@ -131,6 +131,7 @@ def make_qtile(): + + + if __name__ == "__main__": ++ __import__("importlib").import_module("libqtile.utils").restore_os_environment() + rename_process() + q = make_qtile() + try: +diff --git a/bin/qtile-run b/bin/qtile-run +index ccedb96..646a476 100755 +--- a/bin/qtile-run ++++ b/bin/qtile-run +@@ -50,6 +50,7 @@ def main(): + proc.wait() + + if __name__ == "__main__": ++ __import__("importlib").import_module("libqtile.utils").restore_os_environment() + try: + main() + except KeyboardInterrupt: +diff --git a/bin/qtile-session b/bin/qtile-session +index 84f6a2d..da31b12 100755 +--- a/bin/qtile-session ++++ b/bin/qtile-session +@@ -25,6 +25,8 @@ + Qtile session manager. + """ + ++__import__("importlib").import_module("libqtile.utils").restore_os_environment() ++ + from libqtile.log_utils import init_log + import logging + import os +diff --git a/libqtile/utils.py b/libqtile/utils.py +index d5f975b..0fdb080 100644 +--- a/libqtile/utils.py ++++ b/libqtile/utils.py +@@ -208,3 +208,10 @@ def get_cache_dir(): + if not os.path.exists(cache_directory): + os.makedirs(cache_directory) + return cache_directory ++ ++def restore_os_environment(): ++ pythonpath = os.environ.pop("QTILE_SAVED_PYTHONPATH", "") ++ os.environ["PYTHONPATH"] = pythonpath ++ path = os.environ.pop("QTILE_SAVED_PATH", None) ++ if path: ++ os.environ["PATH"] = path +-- +2.6.3 + diff --git a/pkgs/applications/window-managers/qtile/0003-Restart-executable.patch b/pkgs/applications/window-managers/qtile/0003-Restart-executable.patch new file mode 100644 index 000000000000..d9377897fc69 --- /dev/null +++ b/pkgs/applications/window-managers/qtile/0003-Restart-executable.patch @@ -0,0 +1,25 @@ +From b560c11078fecc35df2c62f34beda06c4e80a10d Mon Sep 17 00:00:00 2001 +From: "Alexander V. Nikolaev" +Date: Fri, 27 Nov 2015 10:54:35 +0200 +Subject: [PATCH 3/3] Restart executable + +--- + libqtile/manager.py | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/libqtile/manager.py b/libqtile/manager.py +index b1a38e2..110f7d8 100644 +--- a/libqtile/manager.py ++++ b/libqtile/manager.py +@@ -1339,7 +1339,7 @@ class Qtile(command.CommandObject): + argv = [s for s in argv if not s.startswith('--with-state')] + argv.append('--with-state=' + buf.getvalue().decode()) + +- self.cmd_execute(sys.executable, argv) ++ self.cmd_execute(os.environ.get("QTILE_WRAPPER", "@out@/bin/qtile"), argv[1:]) + + def cmd_spawn(self, cmd): + """ +-- +2.6.3 + diff --git a/pkgs/applications/window-managers/qtile/default.nix b/pkgs/applications/window-managers/qtile/default.nix index 743530e3998b..cd353c7c215c 100644 --- a/pkgs/applications/window-managers/qtile/default.nix +++ b/pkgs/applications/window-managers/qtile/default.nix @@ -1,5 +1,10 @@ { stdenv, fetchFromGitHub, buildPythonPackage, python27Packages, pkgs }: +let cairocffi-xcffib = python27Packages.cairocffi.override { + pythonPath = [ python27Packages.xcffib ]; + }; +in + buildPythonPackage rec { name = "qtile-${version}"; version = "0.10.2"; @@ -11,29 +16,28 @@ buildPythonPackage rec { sha256 = "0dhdwjr4pdlzli68fa8glrnsjzxp6agdab9cnmpsqlwiwh97x9a6"; }; - patches = [ ./restart_executable.patch ]; + patches = [ + ./0001-Substitution-vars-for-absolute-paths.patch + ./0002-Restore-PATH-and-PYTHONPATH.patch + ./0003-Restart-executable.patch + ]; postPatch = '' substituteInPlace libqtile/manager.py --subst-var-by out $out + substituteInPlace libqtile/pangocffi.py --subst-var-by glib ${pkgs.glib} + substituteInPlace libqtile/pangocffi.py --subst-var-by pango ${pkgs.pango} + substituteInPlace libqtile/xcursors.py --subst-var-by xcb-cursor ${pkgs.xorg.xcbutilcursor} ''; buildInputs = [ pkgs.pkgconfig pkgs.glib pkgs.xorg.libxcb pkgs.cairo pkgs.pango python27Packages.xcffib ]; - cairocffi-xcffib = python27Packages.cairocffi.override { - LD_LIBRARY_PATH = "${pkgs.xorg.libxcb}/lib:${pkgs.cairo}/lib"; - pythonPath = [ python27Packages.xcffib ]; - }; - - pythonPath = with python27Packages; [ xcffib cairocffi-xcffib trollius readline ]; - - LD_LIBRARY_PATH = "${pkgs.xorg.libxcb}/lib:${pkgs.cairo}/lib"; + pythonPath = with python27Packages; [ xcffib cairocffi-xcffib trollius readline]; postInstall = '' wrapProgram $out/bin/qtile \ - --prefix LD_LIBRARY_PATH : ${pkgs.xorg.libxcb}/lib \ - --prefix LD_LIBRARY_PATH : ${pkgs.glib}/lib \ - --prefix LD_LIBRARY_PATH : ${pkgs.cairo}/lib \ - --prefix LD_LIBRARY_PATH : ${pkgs.pango}/lib + --set QTILE_WRAPPER '"$0"' \ + --set QTILE_SAVED_PYTHONPATH '"$PYTHONPATH"' \ + --set QTILE_SAVED_PATH '"$PATH"' ''; meta = with stdenv.lib; { diff --git a/pkgs/applications/window-managers/qtile/restart_executable.patch b/pkgs/applications/window-managers/qtile/restart_executable.patch deleted file mode 100644 index a1e74a575d9e..000000000000 --- a/pkgs/applications/window-managers/qtile/restart_executable.patch +++ /dev/null @@ -1,12 +0,0 @@ -diff -ruP a/libqtile/manager.py b/libqtile/manager.py ---- a/libqtile/manager.py 2015-07-26 21:26:16.947976520 +0200 -+++ b/libqtile/manager.py 2015-07-26 21:37:45.581316712 +0200 -@@ -1262,7 +1262,7 @@ - argv = [s for s in argv if not s.startswith('--with-state')] - argv.append('--with-state=' + buf.getvalue().decode()) - -- self.cmd_execute(sys.executable, argv) -+ self.cmd_execute("@out@/bin/qtile", argv[1:]) - - def cmd_spawn(self, cmd): - """