Nixpkgs: Package request, ueberzug support in ranger

Created on 19 Apr 2019  路  15Comments  路  Source: NixOS/nixpkgs

So there is a python package called ueberzug that can be used to display images in ranger, it is kinda similar to w3m except it works better and most importantly it works in termite in bspwm which w3m dosen't

I found out how to install ueberzug but it dosen't work in ranger for some reason ^

Most helpful comment

Oh and it works fantastically in ranger :)

All 15 comments

How did you install it? Can you share your derivation please?

Well i'm not the author of that derivation, someone made it for me

{ python3Packages, fetchFromGitHub, libX11, libXext }:

with python3Packages;

let
pillow-simd = pillow.overrideAttrs (_: rec {
    pname = "Pillow-SIMD";
    version = "5.4.1";

    src = fetchFromGitHub {
    owner = "uploadcare";
    repo = "pillow-simd";
    rev = version;
    sha256 = "07c4pkyfg641mb0xfqw349p5s11n4f241v3mkvba2z58w112kgmf";
    };
    });
in
buildPythonPackage rec {
    pname = "ueberzug";
    version = "18.1.3";

    src = fetchPypi {
    inherit pname version;
    sha256 = "1galc64vbi8d1nbq7d8387my87jq4kqmv30jhlcwrl8g7yph00kg";
    };

    postPatch = ''
    substituteInPlace setup.py --replace "pillow-simd" "pillow"
    '';

    buildInputs = [ libX11 libXext ];

    propagatedBuildInputs = [
    xlib
        pillow-simd
        psutil
        docopt
        attrs
    ];
}

Ranger has merged ueberzug support but hasn't published a release since then. Therefore the current version in nixpkgs of ranger doesn't support ueberzug yet.
See: https://github.com/ranger/ranger/pull/1284

I tried it out with their current master and it does indeed work with your derivation for ueberzug. (Notice that version 5.4.1 of pillow-simd isn't actually the simd variant, so it's slower)

Here's my ranger derivation:

{ fetchFromGitHub, ranger }:
ranger.overrideAttrs(_old: {
  src = fetchFromGitHub {
    owner = "ranger";
    repo = "ranger";
    rev = "d21f60f2a3c4a15e5b0346d28667409fd920417e";
    sha256= "02gdcs75x2w39j7glm2qd43jm4cidk3jnqrqh3jl5024cql617vd";
  };
})

So I guess we'll have to wait for them to make another release to merge it into nixpkgs, or patch it ourselves.

Oh ok thank you, i was surprised because ranger --version outputed the same but maybe the dev branch didn't updated it well thanks, i guess you can close it as any ranger update will fix it ^

Do you want to package ueberzug and make a PR to nixpkgs?

Well i could do it, i'm just not the author of that derivation so i'm not much a fan of taking credits for things i didn't do

Who's the author? Do they want to make the commits?
Otherwise I'd do it - there are some changes that I would want to make anyways.

@tadeokondrak is the author
Ok ^

Yeah, I would submit it to nixpkgs but I wasn't exactly sure how Pillow-SIMD should work (the main Pillow derivation is pretty complicated), so I haven't, feel free to do that.

I renamed the default.nix of pillow to pillow.nix and replaced it with:

{ stdenv, lib, fetchFromGitHub, fetchPypi, callPackage, simd ? false, ... }:
let pillow = callPackage ./pillow.nix {};
in
  if simd
  then (pillow.overrideAttrs (old: rec {
    pname = "pillow-simd";
    version = "5.3.0.post1";
    src = fetchFromGitHub {
        owner = "uploadcare";
        repo = "pillow-simd";
        rev = "v${version}";
        sha256 = "1xy92vvrf2ljzcp1f9mq3xipfm89sfrargv15fg8qf567z80rs5c";
      };
    meta.platforms = lib.platforms.x86_64;  # Needs x86 SIMD instructions
  }))
  else pillow

Then in pkgs/top-level/python-packages.nix I changed:

   pillow = callPackage ../development/python-modules/pillow {          
-    inherit (pkgs) freetype libjpeg zlib libtiff libwebp tcl lcms2 tk; 
+    inherit (pkgs.xorg) libX11;                                        
+  };                                                                   
+                                                                       
+  pillow-simd = callPackage ../development/python-modules/pillow {     
+    simd = true;                                                       
     inherit (pkgs.xorg) libX11;                                        
   };                                                                   

For ueberzeug you don't need the substitute, should check for the python version and can choose between the pillow versions:

{ stdenv, buildPythonPackage, fetchFromGitHub, fetchPypi, pythonAtLeast
, libX11, libXext
, xlib, psutil, docopt, attrs, pillow-simd ? null, pillow }:
buildPythonPackage rec {
  pname = "ueberzug";
  version = "18.1.3";

  src = fetchPypi {
    inherit pname version;
    sha256 = "1galc64vbi8d1nbq7d8387my87jq4kqmv30jhlcwrl8g7yph00kg";
  };

 buildInputs = [ libX11 libXext ];

 propagatedBuildInputs = [
   xlib
   psutil
   docopt
   attrs
   (if pillow-simd == null || (!stdenv.hostPlatform.isx86_64) then pillow else pillow-simd)
 ];

 disabled = !(pythonAtLeast "3.5");

  meta = with stdenv.lib; {
    description = "Command line utility which allows to display images in combination with X11";
    homepage = https://github.com/seebye/ueberzug;
    license = licenses.gpl3;
    maintainer = with maintainers; [ tadeokondrak ];
  };
}

Also don't forget to add it to pkgs/top-level/python-packages.nix.

While we're at it, we might as well patch ranger because we're too impatient to wait for the next release :P

-{ stdenv, lib, fetchFromGitHub, python3Packages, file, less, highlight
-, imagePreviewSupport ? true, w3m ? null}:
+{ stdenv, lib, fetchFromGitHub, fetchpatch, python3Packages, file, less, highlight
+, imagePreviewSupport ? true }:

 with stdenv.lib;

-assert imagePreviewSupport -> w3m != null;
-
 python3Packages.buildPythonApplication rec {
   name = "ranger-${version}";
   version = "1.9.2";
@@ -16,11 +14,16 @@ python3Packages.buildPythonApplication rec {
     sha256= "1ws6g8z1m1hfp8bv4msvbaa9f7948p687jmc8h69yib4jkv3qyax";
   };

+  patches = [(fetchpatch {
+    url = "https://patch-diff.githubusercontent.com/raw/ranger/ranger/pull/1284.diff";
+    sha256 = "1hf7wp5d94g2qhdar03h861lwfl71405a3az55lrhwd7z5bsbpx1";
+  })];
+
   LC_ALL = "en_US.UTF-8";

   checkInputs = with python3Packages; [ pytest ];
   propagatedBuildInputs = [ file ]
-    ++ lib.optional (imagePreviewSupport) [ python3Packages.pillow ];
+     ++ (lib.optional imagePreviewSupport (with python3Packages; [ ueberzug ]));

   checkPhase = ''
     py.test tests
@@ -46,12 +49,11 @@ python3Packages.buildPythonApplication rec {
     substituteInPlace ranger/config/rc.conf \
       --replace "#set preview_script ~/.config/ranger/scope.sh" "set preview_script $out/share/doc/ranger/config/scope.sh"                                                                                                                   
   '' + optionalString imagePreviewSupport ''
-    substituteInPlace ranger/ext/img_display.py \
-      --replace /usr/lib/w3m ${w3m}/libexec/w3m
-
-    # give image previews out of the box when building with w3m
+    # give image previews out of the box when building with
     substituteInPlace ranger/config/rc.conf \
       --replace "set preview_images false" "set preview_images true"
+    substituteInPlace ranger/config/rc.conf \
+      --replace "set preview_images_method w3m" "set preview_images_method ueberzug"
   '';

   meta =  with lib; {

Oh and it works fantastically in ranger :)

Ranger has published a new release with ueberzug support.
I'll make a PR with my proposed changes, if nobody else wants to do it. cc @Alkeryn

@JohnAZoidberg Thanks !

Thank you for your contributions.

This has been automatically marked as stale because it has had no activity for 180 days.

If this is still important to you, we ask that you leave a comment below. Your comment can be as simple as "still important to me". This lets people see that at least one person still cares about this. Someone will have to do this at most twice a year if there is no other activity.

Here are suggestions that might help resolve this more quickly:

  1. Search for maintainers and people that previously touched the related code and @ mention them in a comment.
  2. Ask on the NixOS Discourse.
  3. Ask on the #nixos channel on irc.freenode.net.

The pull request that added support for this in ranger was released with 1.9.3. We do have ranger 1.9.3 in nixpkgs. I think we can close this issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

langston-barrett picture langston-barrett  路  3Comments

chris-martin picture chris-martin  路  3Comments

ob7 picture ob7  路  3Comments

domenkozar picture domenkozar  路  3Comments

spacekitteh picture spacekitteh  路  3Comments