From d7956c52e1f56a7c180d2c290fa7b92d0e99f15a Mon Sep 17 00:00:00 2001 From: Romanos Skiadas Date: Tue, 28 Jun 2022 06:26:19 +0300 Subject: [PATCH] autorandr: WIP Fix distutils import warning Because autorandr still imports distutils, it produces a bunch of deprecation warnings. we need to add packaging to propagatedBuildInputs, but because this wasn't wrapped, the wrapper hook did not take care of adjusting the system path. The easiest way I could find to fix this was to actually wrap autorandr. Then I also had to add a patch to disable autorandr using sys.executable to fork itself in --batch mode. Otherwise it tries to use python to run the bash wrapper, which doesn't work. This should be fine in a nixpkgs environment, since nixpkgs sets the shebang explicitly. --- .../0001-don-t-use-sys.executable.patch | 33 +++++++++++++++++++ pkgs/tools/misc/autorandr/default.nix | 11 ++++--- 2 files changed, 39 insertions(+), 5 deletions(-) create mode 100644 pkgs/tools/misc/autorandr/0001-don-t-use-sys.executable.patch diff --git a/pkgs/tools/misc/autorandr/0001-don-t-use-sys.executable.patch b/pkgs/tools/misc/autorandr/0001-don-t-use-sys.executable.patch new file mode 100644 index 00000000000..81879a8f834 --- /dev/null +++ b/pkgs/tools/misc/autorandr/0001-don-t-use-sys.executable.patch @@ -0,0 +1,33 @@ +From fdcc2f01441ec25104456022e6f8d3120709cede Mon Sep 17 00:00:00 2001 +From: Romanos Skiadas +Date: Tue, 28 Jun 2022 06:16:10 +0300 +Subject: [PATCH] don't use sys.executable + +This is required for forking self in a nixpkgs environment, +where arandr might be wrapped. In that case, the actual arandr command +will be a bash script, not python. +There is no real reason to keep this around, nixpkgs properly sets the +interpreter in the shebang anyway. +--- + autorandr.py | 5 +---- + 1 file changed, 1 insertion(+), 4 deletions(-) + +diff --git autorandr.py autorandr.py +index 35c15f6..1e84a2f 100755 +--- a/autorandr.py ++++ b/autorandr.py +@@ -1192,10 +1192,7 @@ def dispatch_call_to_sessions(argv): + os.chdir(pwent.pw_dir) + os.environ.clear() + os.environ.update(process_environ) +- if sys.executable != "" and sys.executable != None: +- os.execl(sys.executable, sys.executable, autorandr_binary, *argv[1:]) +- else: +- os.execl(autorandr_binary, autorandr_binary, *argv[1:]) ++ os.execl(autorandr_binary, autorandr_binary, *argv[1:]) + sys.exit(1) + os.waitpid(child_pid, 0) + +-- +2.36.1 + diff --git a/pkgs/tools/misc/autorandr/default.nix b/pkgs/tools/misc/autorandr/default.nix index bf54d6a445e..7a9a30756ff 100644 --- a/pkgs/tools/misc/autorandr/default.nix +++ b/pkgs/tools/misc/autorandr/default.nix @@ -1,25 +1,26 @@ -{ lib, stdenv +{ lib +, python3 , python3Packages , fetchFromGitHub , systemd , xrandr , installShellFiles }: -stdenv.mkDerivation rec { +python3.pkgs.buildPythonApplication rec { pname = "autorandr"; version = "1.12.1"; - buildInputs = [ python3Packages.python ]; - nativeBuildInputs = [ installShellFiles ]; + propagatedBuildInputs = [ python3Packages.packaging ]; - # no wrapper, as autorandr --batch does os.environ.clear() buildPhase = '' substituteInPlace autorandr.py \ --replace 'os.popen("xrandr' 'os.popen("${xrandr}/bin/xrandr' \ --replace '["xrandr"]' '["${xrandr}/bin/xrandr"]' ''; + patches = [ ./0001-don-t-use-sys.executable.patch ]; + outputs = [ "out" "man" ]; installPhase = ''