NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
17.44k stars 13.64k forks source link

pentablet: Unify packages? #213263

Open AndrewKvalheim opened 1 year ago

AndrewKvalheim commented 1 year ago

I began packaging the user space driver for the XPPen Artist 12 (2nd Generation) drawing tablet and noticed that it’s already been packaged as xp-pen-deco-01-v2-driver named after a different device.

It appears that many devices are covered by the same software:

list.mjs ```javascript #!/usr/bin/env node import { JSDOM } from "jsdom"; const prefix = "/download/file/id/1936/"; const devicesByDownload = {}; const index = await JSDOM.fromURL("https://www.xp-pen.com/download"); for (const itemLink of index.window.document.querySelectorAll("#productList > li > a")) { const item = await JSDOM.fromURL(itemLink.href); const downloadLink = item.window.document.querySelector(`a[href^="${prefix}"]`); if (downloadLink) { const response = await fetch(downloadLink.href, { method: "head" }); const disposition = response.headers.get("content-disposition"); (devicesByDownload[disposition] ||= []).push(itemLink.textContent.trim()); } } console.log(devicesByDownload); ```
$ ./list.mjs
{
  'attachment; filename="XPPen-pentablet-3.2.3.220323-1.x86_64.tar.gz"': [
    'Artist Pro 16',
    'Artist 24 Pro',
    'Artist 22R Pro',
    'Artist 22E Pro',
    'Artist 22 Pro',
    'Artist 16 Pro',
    'Artist 15.6 Pro',
    'Artist 13.3 Pro',
    'Artist 12 Pro',
    'Artist 24',
    'Artist 22 (2nd Generation)',
    'Artist 15.6',
    'Artist 16 (2nd Generation)',
    'Artist 13 (2nd Generation)',
    'Artist 12 (2nd Generation)',
    'Artist 10 (2nd Generation)',
    'Artist 12',
    'Innovator 16',
    'Deco Pro SW/MW',
    'Deco Pro S/M',
    'Deco LW',
    'Deco L',
    'Deco MW',
    'Deco M',
    'Deco mini7W',
    'Deco mini7',
    'Deco mini4',
    'Deco 03',
    'Deco 02',
    'Deco 01 V2',
    'Deco 01',
    'Deco Fun',
    'Star G960S Plus',
    'Star G960S',
    'Star G960',
    'Star G640S',
    'Star G640',
    'Star G430S',
    'Star G430',
    'Star 06',
    'Star 05',
    'Star 03',
    'AC 19'
  ]
}

Notably this includes the Star G430 for which xp-pen-g430-driver also exists using an older source.

Would a unification to pentablet be appropriate?

@virchau13, @IvarWithoutBones

virchau13 commented 1 year ago

A quick script reveals that all of the downloads have the same sha256 hash, so it seems perfectly fine to do this.

A couple of questions:

  1. Although this is the driver for quite a lot of the tablets, it is not the driver for all of them. Should we
    • a) rename xp-pen-deco-01-v2-driver to xp-pen-pentablet-driver and hope people pick up on which tablets it does and does not work for, or
    • b) make a package collection xpPenDrivers.deco-01-v2, xpPenDrivers.artist-pro-16, etc., where some names are aliases to the same package?
  2. What should I do about the datadir? Currently it's set to /var/lib/xppend1v2. Should it be renamed to something more common (I dunno, /var/lib/xp-pentablet)?
    • Taking option (1b) above would allow us to use different data directories between different drivers if necessary, but I believe having shared settings across different tablets might be useful, so we should probably keep the data directory the same.
AndrewKvalheim commented 1 year ago

Although this is the driver for quite a lot of the tablets, it is not the driver for all of them.

Looks like it is now. I don’t see any downloads for other software:

list.mjs ```javascript #!/usr/bin/env node import { JSDOM } from "jsdom"; dispositionByDownload = {}; const index = await JSDOM.fromURL("https://www.xp-pen.com/download"); for (const itemLink of index.window.document.querySelectorAll("#productList > li > a")) { const item = await JSDOM.fromURL(itemLink.href); const downloads = [...item.window.document.querySelectorAll(".info_right_main")] .filter((section) => /Debian|Red Hat/.test(section.querySelector(".system").textContent)) .flatMap((section) => [...section.querySelectorAll("a")].map((a) => a.href)); for (const download of downloads) { const response = await fetch(download, { method: "head" }); const disposition = response.headers.get("content-disposition"); (devicesByDownload[disposition] ||= []).push(itemLink.textContent.trim()); } } console.log(dispositionByDownload); ```
$ ./list.mjs
{
  'attachment; filename="XPPen-pentablet-3.2.3.220323-1.x86_64.tar.gz"': [
    'Artist Pro 16',
    'Artist 24 Pro',
    'Artist 22R Pro',
    'Artist 22E Pro',
    'Artist 22 Pro',
    'Artist 16 Pro',
    'Artist 15.6 Pro',
    'Artist 13.3 Pro',
    'Artist 12 Pro',
    'Artist 24',
    'Artist 22 (2nd Generation)',
    'Artist 15.6',
    'Artist 16 (2nd Generation)',
    'Artist 13 (2nd Generation)',
    'Artist 12 (2nd Generation)',
    'Artist 10 (2nd Generation)',
    'Artist 12',
    'Innovator 16',
    'Deco Pro SW/MW',
    'Deco Pro S/M',
    'Deco LW',
    'Deco L',
    'Deco MW',
    'Deco M',
    'Deco mini7W',
    'Deco mini7',
    'Deco mini4',
    'Deco 03',
    'Deco 02',
    'Deco 01 V2',
    'Deco 01',
    'Deco Fun',
    'Star G960S Plus',
    'Star G960S',
    'Star G960',
    'Star G640S',
    'Star G640',
    'Star G430S',
    'Star G430',
    'Star 06',
    'Star 05',
    'Star 03',
    'AC 19'
  ],
  'attachment; filename="XPPen-pentablet-3.2.3.220323-1.x86_64.deb"': [
    'Artist Pro 16',
    'Artist 24 Pro',
    'Artist 22R Pro',
    'Artist 22E Pro',
    'Artist 22 Pro',
    'Artist 16 Pro',
    'Artist 15.6 Pro',
    'Artist 13.3 Pro',
    'Artist 12 Pro',
    'Artist 24',
    'Artist 22 (2nd Generation)',
    'Artist 15.6',
    'Artist 16 (2nd Generation)',
    'Artist 13 (2nd Generation)',
    'Artist 12 (2nd Generation)',
    'Artist 10 (2nd Generation)',
    'Artist 12',
    'Innovator 16',
    'Deco Pro SW/MW',
    'Deco Pro S/M',
    'Deco LW',
    'Deco L',
    'Deco MW',
    'Deco M',
    'Deco mini7W',
    'Deco mini7',
    'Deco mini4',
    'Deco 03',
    'Deco 02',
    'Deco 01 V2',
    'Deco 01',
    'Deco Fun',
    'Star G960S',
    'Star G960',
    'Star G640S',
    'Star G640',
    'Star G430S',
    'Star G430',
    'Star 06',
    'Star 05',
    'Star 03',
    'AC 19'
  ],
  'attachment; filename="XPPen-pentablet-3.2.3.220323-1.x86_64.rpm"': [
    'Artist 24',
    'Artist 22 (2nd Generation)',
    'Artist 15.6',
    'Artist 16 (2nd Generation)',
    'Artist 13 (2nd Generation)',
    'Artist 12 (2nd Generation)',
    'Artist 10 (2nd Generation)',
    'Artist 12',
    'Innovator 16',
    'Deco Pro SW/MW',
    'Deco Pro S/M',
    'Deco LW',
    'Deco L',
    'Deco MW',
    'Deco M',
    'Deco mini7W',
    'Deco mini7',
    'Deco mini4',
    'Deco 03',
    'Deco 02',
    'Deco 01 V2',
    'Deco 01',
    'Deco Fun',
    'Star G960S Plus',
    'Star G960S',
    'Star G960',
    'Star G640S',
    'Star G640',
    'Star G430S',
    'Star G430',
    'Star 06',
    'Star 05',
    'Star 03',
    'AC 19'
  ]
}

What should I do about the datadir?

I’d suggest whatever the normal behavior of the application is. If following the download instructions for multiple tablets just repeatedly installs the same application and reuses the same datadir, that’s what the Nix package should do.

altsalt commented 1 year ago

Checking in on the status of this?

sochotnicky commented 8 months ago

I almost packaged up a new version of the driver same as @AndrewKvalheim before I realized there's duplication.

Few notes for unification however:

virchau13 commented 8 months ago

I think this issue has been open for too long :P

@sochotnicky If you can make a PR with your new version (optionally with package unification), I'll test it and approve it.

Just a question:

/var/lib files are only read as far as I can tell. They belong in /usr/share.

Are they? When I tested the older version a year ago, modifying settings in the GUI would result in changes to the files. If that's no longer the case then it should definitely be moved under /usr/share.

sochotnicky commented 8 months ago

I've started cleaning up the package, noticed some additional oddities (i.e. we call sed on the binary to replace a string where it looks for configs which is very brittle). I'm trying to replace it with buildFHSEnv but hitting some issues (I am probably "holding it wrong").

All that just to say - I might not get to finalize this rework anytime soon.

sochotnicky commented 8 months ago

OK, put together a draft PR in https://github.com/NixOS/nixpkgs/pull/277176. It's not yet finished/fully tested since I don't have the tablet with me at this moment. Should get to it in the next few days hopefully. In the meantime perhaps people can look it over/try it out.

altsalt commented 8 months ago

I've tested this under Wayland and X11 with a XP-Pen Artist 12 (2nd Gen).

The application loads on both with the same general functionality. However, on Wayland the Work area tab doesn't mirror what is on the screens.

That said, while the Diagnostic tool sees the pen, it does not seem to be picked up by the system as a mouse, table, or other input.

It isn't clear whether this relates to the underlying system or this package, and I am unsure when I'll be able to test on a different distro.

Some searching did bring up the suggestion of adding a file such as /usr/share/libwacom/xp-pen-artist-12-2.tablet which I've done manually, but the device still fails to be detected by libwacom-list-local-devices.

$ xinput list
⎡ Virtual core pointer                      id=2    [master pointer  (3)]
⎜   ↳ Virtual core XTEST pointer                id=4    [slave  pointer  (2)]
⎜   ↳ Elan Touchpad                             id=10   [slave  pointer  (2)]
⎜   ↳ Elan TrackPoint                           id=11   [slave  pointer  (2)]
⎜   ↳ HANVON UGEE Artist 12 (2nd Gen) Mouse     id=15   [slave  pointer  (2)]
⎜   ↳ HANVON UGEE Artist 12 (2nd Gen)           id=16   [slave  pointer  (2)]
⎣ Virtual core keyboard                     id=3    [master keyboard (2)]
    ↳ Virtual core XTEST keyboard               id=5    [slave  keyboard (3)]
    ↳ Power Button                              id=6    [slave  keyboard (3)]
    ↳ Video Bus                                 id=7    [slave  keyboard (3)]
    ↳ Sleep Button                              id=8    [slave  keyboard (3)]
    ↳ Integrated Camera: Integrated C           id=9    [slave  keyboard (3)]
    ↳ AT Translated Set 2 keyboard              id=12   [slave  keyboard (3)]
    ↳ ThinkPad Extra Buttons                    id=13   [slave  keyboard (3)]
    ↳ HANVON UGEE Artist 12 (2nd Gen) Keyboard  id=14   [slave  keyboard (3)]
marvix97 commented 8 months ago

@altsalt I can confirm that the work area problem on wayland is in the driver and has nothing to do with the packaging, because it has done the same to me on both arch and fedora. That's probably because the driver application runs on xwayland, but the thing I know for sure is that it has to be fixed by xp-pen directly.

I'd like to test the PR too with my Deco 02, but I'm new to nixos, so I'll have to figure out how to add it to my flake. I'll let you know if I'm able to

virchau13 commented 8 months ago

@sochotnicky I'm testing your PR right now, and it appears that /usr/lib/pentablet is still modified when the user changes the settings in the driver GUI. Seems that we need to bind-mount /usr in the FHS env to a writable directory. Perhaps /var/lib/xp-pentablet?

We'll also need to make this into a NixOS module to support the udev rules.

misumisumi commented 7 months ago

I saw this suggestion and made some modifications.

I also created nixosModule. nixosModules now creates a path under /var/lib and copies the config.

I've confirmed that it works without using buildFHSEnv (i.e. just an unwrapped derivation), but consider continuing to use it if it's a good solution for your configuration path.

Also, regarding the name of the package and module, xp-pen-tablet may be a good name, similar to ArchLinux's AUR.

{ config, pkgs, lib, ... }:
with lib;
let
  cfg = config.services.xserver.xp-pentablet;
  dataDir = "/var/lib/xppenconf";
in
{
  options = {
    services.xserver.xp-pentablet = {
      enable = mkOption {
        type = types.bool;
        default = false;
        description = lib.mdDoc ''
          Whether to enable the xp-pen-tablet.
        '';
      };
    };
  };
  config = mkIf cfg.enable {
    hardware.uinput.enable = true;

    environment.systemPackages = [ pkgs.xp-pentablet ]; # provides xsetwacom

    services.udev.packages = [ pkgs.xp-pentablet ];

    system.activationScripts.xp-pentablet-config.text = ''
      install -m 755 -d "${dataDir}/conf/xppen"
      find ${pkgs.xp-pentablet}/usr/lib/pentablet/conf -type f | while read -r file; do
        if [ ! -f ${dataDir}/conf/$(basename ''${file}) ]; then
          install -m 666 "''${file}" "${dataDir}/conf/xppen/$(basename ''${file})"
        fi
      done
    '';
  };
}