Trying to wrap a package but the Plasma entry points to the old one

Getting really weird behavior. I was referencing the VLC package straight from nixpkgs but decided to make a wrapper for it to set QT_SCALE_FACTOR. The wrapper works perfectly, but I only get it if run from shell. When launching from Plasma it oens open unscaled, so I looked at the application entry and it’s pointing to a different path.

I’ve tried:

  • rebooting
  • confirmed I’m not referencing the pkgs.vlc anywhere else.

I can manually change it, but I’d like to know what’s causing this.

The only other thing I can think to try is deleting all old generations, which I can’t do till I finish and test a bunch of other changes I’m in the middle of making

> lsa $(which vlc) 
lrwxrwxrwx 1 root root 55 Dec 31  1969 /run/current-system/sw/bin/vlc -> /nix/store/qm1gh8baz2bxq2zl38ra65ibr7rqixpi-vlc/bin/vlc

The wrapper

  wrap-vlc = config.mynix.desktop.packs.vlc-qt-scale != null;
  vlc-scaled-wrapper = pkgs.symlinkJoin {
    name = "vlc";
    paths = [ pkgs.vlc];
    buildInputs = [ pkgs.makeWrapper ];
    postBuild = ''
      wrapProgram $out/bin/vlc --set QT_SCALE_FACTOR ${builtins.toString config.mynix.desktop.packs.vlc-qt-scale}
    '';
  };

How I’m applying it

      environment.systemPackages = with pkgs; [
          (if wrap-vlc then vlc-scaled-wrapper else vlc)
      ];

It’s because the .desktop file for VLC points to an absolute path. You’re symlinking it in but not editing it to point to the path of your wrapper, or (probably better) unprefixed vlc.

I thought putting the wrapper in systemPackages instead of pkgs.vlc would do that. Is there something I can do in the nix code to set that?

The .desktop file is a part of the package; it’s not generated by NixOS or anything. You could add a command to your postBuild that removes the created link for the .desktop file and replaces it with a version you’ve modified with sed.

Tried the below in postBuild and postFixup and it still ends up with the absolute path for some reason. i tested the regex replace in shell and know it works.

I can’t figure where in the derivation the desktop file would be created, wanted to see if I could just tweak it with an overlay but can’t do it if I don’t know where it happens lol

        (final: prev: {
          vlc = prev.vlc.overrideAttrs
            (old: rec {
              postFixup = old.postFixup or "" + ''
                perl -pe 's/^((Try)?Exec)=\/nix\/store\/.+\/bin\/vlc(.+)*?/$1=vlc$3/' $out/share/applications/vlc.desktop > $out/share/applications/vlc.desktop
              '';
            });
          }
        )

Remove the link first; otherwise you’re trying to write to the link’s target, which is read-only.