Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loading screen hangs on NixOS #1362

Closed
AlexChalk opened this issue Oct 19, 2020 · 25 comments
Closed

Loading screen hangs on NixOS #1362

AlexChalk opened this issue Oct 19, 2020 · 25 comments

Comments

@AlexChalk
Copy link

Hi, I'm trying to run the AppImage build of agent for linux, but the loading screen hangs when I execute the file:

In the console, I see this output:

14:48:48.132 › [AppRendererService] dispatch action: [app] process start info
14:48:48.133 › [AppEffect][processStartInfo] payload: {
  deviceConnectionState: {
    bootloaderActive: false,
    connected: true,
    zeroInterfaceAvailable: true,
    hasPermission: true,
    udevRulesInfo: 'NeedToSetup',
    halvesInfo: '[object]'
  },
  commandLineArgs: { modules: false },
  platform: 'linux',
  osVersion: '5.4.70',
  udevFileContent: '# Ultimate Hacking Keyboard rules\n' +
    '# These are the udev rules for accessing the USB interfaces of the UHK as non-root users.\n' +
    '# Copy this file to /etc/udev/rules.d and physically reconnect the UHK afterwards.\n' +
    'SUBSYSTEM=="input", ATTRS{idVendor}=="1d50", ATTRS{idProduct}=="612[0-7]", GROUP="input", MODE="0660"\n' +
    'SUBSYSTEMS=="usb", ATTRS{idVendor}=="1d50", ATTRS{idProduct}=="612[0-7]", TAG+="uaccess"\n' +
    'KERNEL=="hidraw*", ATTRS{idVendor}=="1d50", ATTRS{idProduct}=="612[0-7]", TAG+="uaccess"\n'
}

I have added the above lines to /etc/udev/rules.d/50-uhk60.rules and rebooted without any luck. My guess is this is related to my operating system, NixOS 20.03 (Markhor) x86_64; among other things it requires a package to run AppImages.

Is there a way of generating a more detailed stack trace so I can debug?

@mondalaci
Copy link
Member

Hi there!

@ert78gb Any ideas?

@pshirshov
Copy link

Acutally I believe that FlatPak package would solve that problem. NixOS supports FlatPak and FlatPak is self-contained. I believe that #1361 would allow to solve this and many other problems.

@ert78gb
Copy link
Member

ert78gb commented Oct 21, 2020

@adc17 Sorry for the late reaction.
The logs that you shared comes from the renderer of process of the application. I need the application log that available in the
~/.config/uhk-agent/logs folder.

Please do the following steps and after send me the logs. The logs maybe contains personal information so you can send to me directly.

  1. delete all files in the ~/.config/uhk-agent/logs folder
  2. start the agent with the --log=all command line parameters
  3. send the log files to me from the ~/.config/uhk-agent/logs folder

@pshirshov AppImage is also a self-contained solution. I think it is a USB communication issue.

@AlexChalk
Copy link
Author

hi @ert78gb no problem, I checked those logs and this error appears a few times, is it helpful?

[2020-10-19 14:18:26.458] [error] [UhkHidDevice] hasPermission Error: cannot open device with path /dev/hidraw0
    at new HID (/home/adc/.cache/appimage-run/a9aa950e7fd3f835d185b718e41732c97ed3e3fe843f8f99c5551fb3854f9306/squashfs-root/resources/app.asar/node_modules/node-hid/nodehid.js:49:17)
    at t.UhkHidDevice.hasPermission (/home/adc/.cache/appimage-run/a9aa950e7fd3f835d185b718e41732c97ed3e3fe843f8f99c5551fb3854f9306/squashfs-root/resources/app.asar/electron-main.js:100:29061)
    at t.UhkHidDevice.<anonymous> (/home/adc/.cache/appimage-run/a9aa950e7fd3f835d185b718e41732c97ed3e3fe843f8f99c5551fb3854f9306/squashfs-root/resources/app.asar/electron-main.js:100:29388)
    at Generator.next (<anonymous>)
    at /home/adc/.cache/appimage-run/a9aa950e7fd3f835d185b718e41732c97ed3e3fe843f8f99c5551fb3854f9306/squashfs-root/resources/app.asar/electron-main.js:43:1957
    at new Promise (<anonymous>)
    at Object.l [as __awaiter] (/home/adc/.cache/appimage-run/a9aa950e7fd3f835d185b718e41732c97ed3e3fe843f8f99c5551fb3854f9306/squashfs-root/resources/app.asar/electron-main.js:43:1702)
    at t.UhkHidDevice.getDeviceConnectionStateAsync (/home/adc/.cache/appimage-run/a9aa950e7fd3f835d185b718e41732c97ed3e3fe843f8f99c5551fb3854f9306/squashfs-root/resources/app.asar/electron-main.js:100:29245)
    at t.DeviceService.<anonymous> (/home/adc/.cache/appimage-run/a9aa950e7fd3f835d185b718e41732c97ed3e3fe843f8f99c5551fb3854f9306/squashfs-root/resources/app.asar/electron-main.js:100:75461)
    at Generator.next (<anonymous>)

@ert78gb
Copy link
Member

ert78gb commented Oct 21, 2020

Please send the whole file. I need other information too because it looks like the udev rules did not apply. If the OS is Linux then the Agent should show the "Permission" screen that set or give an introduction to set the udev rule.

I tested what is the return value of the process.platform nodejs command on nixos/nix docker image. The result is linux so the Agent should show the" Permission" screen. I don't know this docker image how identical with bare metal or a virtual machine installation.

@ert78gb
Copy link
Member

ert78gb commented Oct 21, 2020

FYI. I used the following commands to query the os platform.

  1. # nix-shell -p nodejs
  2. [nix-shell] node
  3. [node repl] process.platform

@pshirshov
Copy link

@pshirshov AppImage is also a self-contained solution. I think it is a USB communication issue.

A permission issue probably. And FlatPak should take care of that.

@AlexChalk
Copy link
Author

@ert78gb here's the whole file having followed your instructions: https://gist.github.com/adc17/a879bfc264d9c257de8bff312f00b8ef

If the OS is Linux then the Agent should show the "Permission" screen that set or give an introduction to set the udev rule.

I did see this screen the first time round, but I don't see it anymore.

@AlexChalk
Copy link
Author

I unplugged my uhk while agent was running which got the permissions screen back; here are the logs from that session: https://gist.github.com/adc17/ccbc67ecd4b7c57bd1981555c6f09148

@ert78gb
Copy link
Member

ert78gb commented Oct 23, 2020

@adc17
As I guessed udev settings error. Error when set privilege: Error: Unable to find pkexec or kdesudo.
The PR that maybe solve the issue.

Until sudo-prompt does not merge the PR, please do the introductions my hand. I hope udev rule settings is same on NixOs than other linux environment.

# Ultimate Hacking Keyboard rules
# These are the udev rules for accessing the USB interfaces of the UHK as non-root users.
# Copy this file to /etc/udev/rules.d and physically reconnect the UHK afterwards.
SUBSYSTEM=="input", ATTRS{idVendor}=="1d50", ATTRS{idProduct}=="612[0-7]", GROUP="input", MODE="0660"
SUBSYSTEMS=="usb", ATTRS{idVendor}=="1d50", ATTRS{idProduct}=="612[0-7]", TAG+="uaccess"
KERNEL=="hidraw*", ATTRS{idVendor}=="1d50", ATTRS{idProduct}=="612[0-7]", TAG+="uaccess"

@mondalaci
Currently we just show the following message when Agent cannot set the udev rules.

Agent wasn't able to set up permissions via PolicyKit. This is most likely because the <code>polkit</code> package is not installed on your system.

Maybe worth write the error message too, to see the root cause.

@ert78gb
Copy link
Member

ert78gb commented Oct 23, 2020

I just know see in the opening comment you set the udev rules manually without luck. Please double check the content of the /etc/udev/rules.d/50-uhk60.rules is correct

@AlexChalk
Copy link
Author

Hmm, so I'm pretty new to it, but I believe what nixos does is create a shell (sandbox) environment for running different programs like this to keep dependencies separate. The mostly likely explanation for me is the environment created by appimage-run doesn't include pkexec. That said, if it's using pkexec to write udev rules that would also probably break on nixos 😂.

@ert78gb I'm interested in these lines from the logs:

[2020-10-22 12:00:00.128] [info] [AppService] getAppStartInfo response: {
  deviceConnectionState: {
    bootloaderActive: false,
    connected: true,
    zeroInterfaceAvailable: true,
    hasPermission: true,
    udevRulesInfo: 'NeedToSetup',
    halvesInfo: { areHalvesMerged: false, isLeftHalfConnected: true }
  },

It suggests this check is creating a false negative:

if (!(await pathExists('/etc/udev/rules.d/50-uhk60.rules'))) {
return UdevRulesInfo.NeedToSetup;
}

I think I'll need to take a closer look at how app-images are run on nixos before I can help debug this.

@ert78gb
Copy link
Member

ert78gb commented Oct 24, 2020

thx for any investigation and help. Currently I don't have time to be familiar with NixOS, how it is separate the context of each shell/application. Maybe after the next week I can spend time on it.

The referenced code block returns false if the application context does not have access to the file.

@ert78gb
Copy link
Member

ert78gb commented Oct 24, 2020

The pkexec and kdesudo part of the most Linux distros. We never thought on bundle them with the agent.

@AlexChalk
Copy link
Author

@ert78gb I think you can leave this one with me ;), I suspect the necessary PR will actually be against the appimage-run package used by nixos! Yep, my guess would be it doesn't include pkexec in the context, but I think that's something for the nix solution to fix, not uhk agent.

@AlexChalk
Copy link
Author

@ert78gb it looks like the nix approach to running these builds is to create a chroot environment that mimics a typical distro and include a bunch of typical system libs/binaries in that environment, then run the executable in that context.

I've not used chroot before but I imagine it will break checks for system files like this one:

if (!(await pathExists('/etc/udev/rules.d/50-uhk60.rules'))) {
return UdevRulesInfo.NeedToSetup;
}

So it might be that the USB communication is fine, but agent doesn't load because it can't find the udev files and it assumes there's a problem?

@ert78gb
Copy link
Member

ert78gb commented Oct 25, 2020

I am talking with @mondalaci about this special use case.
Until please try to run the agent with --preserve-udev-rules command line argument.

@AlexChalk
Copy link
Author

@ert78gb Nice, it loads now! 🚀.

@AlexChalk
Copy link
Author

I wonder if this could just be packaged for nix, I see this approach used for other appimage builds. I'm only hesitating as I'm not sure how easy it would be to update udev rules as part of the build.

@mondalaci
Copy link
Member

@adc17 Please let us know which is the innermost directory of /etc/udev/rules.d/50-uhk60.rules which exists in the chroot cage of NixOS.

@AlexChalk
Copy link
Author

@mondalaci I'm not sure how I'd confirm this but I believe it is built here, in which case it looks like /etc.

@mondalaci
Copy link
Member

@adc17 Can't you simply run bash in the same environment you run Agent? If so, it should be a matter of using ls.

@AlexChalk
Copy link
Author

@mondalaci I ran the appimage-run package that builds the environment against a simple script cd /; ls /etc, and I didn't see a udev directory, so I'm pretty confident it's /etc.

@mondalaci mondalaci changed the title agent loading screen hangs on nixos. Loading screen hangs on NixOS Oct 27, 2020
@mondalaci
Copy link
Member

This should be resolved by #1367 and the fix was released in Agent 1.5.5.

@benneti
Copy link

benneti commented Feb 17, 2021

In case someone stumbles about this.
To use the AppImage in nixos you can use the following package definition

{ appimageTools, lib, fetchurl, makeWrapper, polkit }:

# It is necessary to add this package to
# services.udev.packages = with pkgs; [
#   uhk-agent
# ];
# for the udev rules to be activated
let
  pname = "uhk-agent";
  version = "1.5.8";
  name = "${pname}-${version}";

  src = fetchurl {
    url = "https://github.com/UltimateHackingKeyboard/agent/releases/download/v${version}/UHK.Agent-${version}-linux-x86_64.AppImage";
    name = "${name}.AppImage";
    sha256 = "sha256-8VPTw/gNlsl+QneKxlotsYH3wGSPPpepEkRVbitrJI0=";
  };

  appimageContents = appimageTools.extract {
    name = "${pname}-${version}";
    inherit src;
  };
in appimageTools.wrapType2 {
  inherit src name;

  extraPkgs = pkgs: with pkgs; [ polkit udev ];

  extraInstallCommands = ''
    mv $out/bin/${name} $out/bin/${pname}

    install -m 444 -D ${appimageContents}/${pname}.desktop -t $out/share/applications
    substituteInPlace $out/share/applications/${pname}.desktop \
      --replace 'Exec=AppRun' 'Exec=${pname}'
    cp -r ${appimageContents}/usr/share/icons $out/share

    # user needs to be in the input group!
    install -D -m 644 ${appimageContents}/resources/rules/50-uhk60.rules $out/lib/udev/rules.d/50-uhk60.rules
  '';

  meta = with lib; {
    description = "Agent is the configuration application of the Ultimate Hacking Keyboard.";
    homepage = "https://github.com/UltimateHackingKeyboard/agent";
    license = licenses.mit;
    maintainers = [ ];
    platforms = [ "x86_64-linux" ];
  };
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants