nixpkgs icon indicating copy to clipboard operation
nixpkgs copied to clipboard

libqalculate: add wayland support with dependent gnuplot

Open chopper2000uk opened this issue 1 year ago • 5 comments

Nixpkgs version

  • Unstable (25.11)

Describe the bug

Currently libqalc, which is used by both qalculate-qt and qalculate-gtk, uses the gnuplot package for plotting, but this doesn't support wayland which is becoming the default. Can, or should the version of gnuplot used by libqalc now be changed to use gnuplot_qt to support wayland ?

Steps to reproduce

On wayland:

nix-shell -p libqalculate
qalc
> plot(x^2)

Results in nothing displayed as the gnuplot version doesn't support the qt terminal type and is detected as unknown.

Expected behaviour

For gnuplot to detect and use the qt terminal type to open a window and display the plot.

Screenshots

No response

Relevant log output


Additional context

No response

System metadata

  • system: "x86_64-linux"
  • host os: Linux 6.12.29, NixOS, 25.11 (Xantusia), 25.11.20250520.2795c50
  • multi-user?: yes
  • sandbox: yes
  • version: nix-env (Nix) 2.28.3
  • nixpkgs: /nix/store/p893dkrzm5rxvhnqh092prgi1a7dzmcy-source

Notify maintainers

@doronbehar @alyaeanyx


Note for maintainers: Please tag this issue in your pull request description. (i.e. Resolves #ISSUE.)

I assert that this issue is relevant for Nixpkgs

Is this issue important to you?

Add a :+1: reaction to issues you find important.

chopper2000uk avatar May 28 '25 16:05 chopper2000uk

Nice issue! You are correct to notice that:

https://github.com/NixOS/nixpkgs/blob/458f45cef08031ee48bbe358137b45e0e7478695/pkgs/by-name/li/libqalculate/package.nix#L66-L68

I noticed also that gnuplot has lot's of with switches which TBH I didn't understand the logic of them fully. Particularly, this is incorrect (at least nowadays):

https://github.com/NixOS/nixpkgs/blob/458f45cef08031ee48bbe358137b45e0e7478695/pkgs/tools/graphics/gnuplot/default.nix#L37-L41

I personally don't experience the issue you describe where plot doesn't work, because I use GNOME and it retains support X as of nowadays.

The question here is actually more general - should the gnuplot derivation by default provide a gnuplot binary that uses Wayland via Qt (should we push modernity beyond upstream's intentions?), and binary in a path like gnuplot-x perhaps should behave as the gnuplot Nixpkgs binary?

I'm not sure what would be the proper solution.

Also, I was thinking, maybe the libqalculate/Calculator-plot.cc substitution quoted above simply shouldn't be forced on everyone else? We might be able to think of a slightly more imperative setup that would allow everyone to be happy, without making users like you build all of the dependency chain from gnuplot to qalculate-{qt,gtk}.

doronbehar avatar May 29 '25 14:05 doronbehar

Admittedly it maybe be bit early to try and jump ship from X, and I do use xwayland-satellite as a stop gap.

That is a much bigger question, as far as when nix should be maybe more Wayland first focused with its packages, something I'm sure is probably a long way of.

Admittedly relativity new to nix so probably a bit ignorant. I appreciate that gnuplot is a dependency of libqalculate, if you want to use plotting, and the nix way is to tightly couple them with absolute store paths to contain all the dependencies within its closure. But then it is an optional dependency that calls out to gnuplot, and it looks like the function canPlot checks for the existence of gnuplot within search paths at runtime. Obviously the implication on removing that dependency and the substitution would be that it breaks that functionality on existing systems, without having explicitly installed gnuplot.

I don't know what or if there is a best practice, as I say I'm learning, and I've not really thought this through. But like you are suggesting, would a libqalculate-unwrapped with no optional dependencies and substitutions, and a wrapped libqalculate with a gnuplot input added to the search path work? The same again for qalculate-{qt,gtk}-unwrapped with a dependency on libqalculate-unwrapped, and a wrapped qalculate-{qt,gtk} with a gnuplot input added to the search path. This would have cached builds of the unwrapped packages and only require rebuilds of the lightweight wrappers when overriding gnuplot to gnuplot-qt, or just install qalculate-{qt,gtk}-unwrapped with an explicit gnuplot-qt, and it wouldn't break existing systems.

chopper2000uk avatar May 29 '25 17:05 chopper2000uk

Admittedly it maybe be bit early to try and jump ship from X, and I do use xwayland-satellite as a stop gap.

I read the README of this project and TBH I didn't understand fully what it does, but I guess it means you are capable of running X dependent programs in principal.

I tried to build a libqalculate derivation without the substitution linked above, and I noticed in the qalc shell, that indeed without a gnuplot in $PATH, the plot command acts weird:

(ins)> plot(x^2)

  warning: To avoid division by zero, the following must be true: x ≠ 0.
  picoliter·byte·tonne × x² = x² μg·B·L

I wonder whether upstream would have liked this UX to be a bit better. I personally think the ideal experience would be that a message would be written, saying something like "gnuplot is not available, residing to parsing the expression". Not only that, it would have been ideal if it would have searched in $PATH not only gnuplot, but also gnuplot_qt, and perhaps also it would have allowed changing the default gnuplot binary searched, via a user setting.

I created therefor:

  • https://github.com/NixOS/nixpkgs/pull/412773

Which should make things a bit easier for you. If you agree with the ideas I presented above, I'd also recommend talking with upstream about it, as it is not only a NixOS issue. If they would apply a $PATH search, and also allow changing this gnuplot PATH search (imperatively via a user setting), we might decide to change the default behavior of our Nix expression to not apply this substitution by default.

doronbehar avatar May 31 '25 22:05 doronbehar

I totally agree with qalc being more informative.

As far as your change, obviously I'm biased in my requirements. So take what you think would be beneficial.

Whilst clearer on libqalculates gnuplot dependency, I'm not sure it gains much on what I currently have:

overlays = [ 
(final: prev: {
  gnuplot = prev.gnuplot.override {
    withQt = true;
  };
})
];

note: gnuplot = prev.gnuplot_qt causes infinite recursion.

The default for compatibility would still use the non qt version of gnuplot, so the only version cached will be the same as it is currently, requiring a local builds. Also any gnuplot rebuild will trigger a libqalculate rebuild, as it currently does, along with the chain of all the packages dependent on it. I'm not too sure if that should be the case for an optional dependency, or at lease triggering a full rebuild. Arguably as you say if it was a configuration option it wouldn't be an issue.

I was wondering if something kinda like this:

https://github.com/chopper2000uk/nixpkgs/commit/dddfafb7d1d4078bab461f1e64bb8d8c7b4e7f27

In conjunction with the overlay above this would only trigger a local build of libqalculate, the thin wrapper that sets the $PATH and leverages the cached build of libcalculate-unwrapped. All packages that depend on libqalculate like qalculate-{gtk,qt} would utilise this version with the wrapped path to gnuplot-qt.

Either way interested in your opinion.

chopper2000uk avatar Jun 01 '25 17:06 chopper2000uk

Let's see what upstream says:

  • https://github.com/Qalculate/libqalculate/issues/796

doronbehar avatar Jun 03 '25 13:06 doronbehar