Jump to content

Hardware/Razer: Difference between revisions

From Official NixOS Wiki
Johanno (talk | contribs)
Add razer usb reset.
Revert code blocks to syntax highlighting
 
(5 intermediate revisions by 4 users not shown)
Line 1: Line 1:
{{Hardware/breadcrumb}}
{{Hardware/breadcrumb}}
<h2>OpenRazer</h2>
 
OpenRazer is an open-source project to support Razer peripherals, including those found in their laptops. To enable the OpenRazer you need to add the following to your <code>configuration.nix</code>
== OpenRazer ==
 
OpenRazer is an open-source project to support Razer peripherals, including those found in their laptops. To enable the OpenRazer you need to add the following to your system configuration:


<syntaxHighlight lang=nix>
<syntaxHighlight lang=nix>
   hardware.openrazer.enable = true
   hardware.openrazer.enable = true;
   environment.systemPackages = with pkgs; [
   environment.systemPackages = with pkgs; [
      openrazer-daemon
    openrazer-daemon
  ];
  ];
</syntaxHighlight>
</syntaxHighlight>


To run the <code>openrazer-daemon</code>, you need to be in the <code>openrazer</code> group.
To run the <code>openrazer-daemon</code>, you need to be in the <code>openrazer</code> group.
<syntaxHighlight lang=nix>
<syntaxHighlight lang=nix>
users.users.<username> = { extraGroups = [ "openrazer" ]; };
users.users.<username>.extraGroups = [ "openrazer" ];
</syntaxHighlight>
</syntaxHighlight>


To enable a front-end to control the peripherals, add the following to your configuration
To enable a front-end to control the peripherals, add the following to your system configuration:
 
<syntaxHighlight lang=nix>
<syntaxHighlight lang=nix>
   environment.systemPackages = with pkgs; [
   environment.systemPackages = with pkgs; [
      polychromatic
    polychromatic
   ];
   ];
</syntaxHighlight>
</syntaxHighlight>


<h2>Razer Blade 15 Advanced (Early 2020 model)</h2>
== Razer Blade 15 Advanced (Early 2020 model) ==


<h3>Lid reopen hybernate issue</h3>
=== Lid reopen hybernate issue ===


Upon closing the lid to the laptop and reopening, an issue occurs where the device will intermittently go back into hybernate mode after around 10-30 seconds. Setting the kernel parameter <code>button.lid_init_state=open</code> fixes this issue. The following is an example configuration (working in NixOS 22.05):
Upon closing the lid to the laptop and reopening, an issue occurs where the device will intermittently go back into hybernate mode after around 10-30 seconds. Setting the kernel parameter <code>button.lid_init_state=open</code> fixes this issue. The following is an example configuration (working in NixOS 22.05):


<syntaxHighlight lang=nix>
<syntaxHighlight lang=nix>
  boot.kernelParams = [ "button.lid_init_state=open" ];
boot.kernelParams = [ "button.lid_init_state=open" ];
</syntaxHighlight>
</syntaxHighlight>


<h3>Getting the Nvidia card to work properly with external displays</h3>
=== Getting the Nvidia card to work properly with external displays ===


In order to get both the laptop display and external displays working, in the BIOS settings set Chipset > GPU MODE to "Dedicated GPU only".
In order to get both the laptop display and external displays working, in the BIOS settings set Chipset > GPU MODE to "Dedicated GPU only".


After setting the GPU MODE to "Dedicated GPU only" in the BIOS, enabling [[Nvidia#sync_mode sync mode| Nvidia]] is necessary in order for both the laptop's display and external display/ports to work properly. Here is an example configuration snippet for NixOS 22.05:
After setting the GPU MODE to "Dedicated GPU only" in the BIOS, enabling [[NVIDIA#Sync mode]] is necessary in order for both the laptop's display and external display/ports to work properly. Here is an example configuration snippet for NixOS 22.05:


<syntaxHighlight lang=nix>
<syntaxHighlight lang=nix>
   services.xserver = {
   services.xserver.videoDrivers = [ "nvidia" ];
    videoDrivers = [ "nvidia" ];
  };
   hardware.opengl.enable = true;
   hardware.opengl.enable = true;
  hardware.nvidia.package = config.boot.kernelPackages.nvidiaPackages.beta;
 
 
   hardware.nvidia = {
   hardware.nvidia = {
    package = config.boot.kernelPackages.nvidiaPackages.beta;
     powerManagement.enable = true;
     powerManagement.enable = true;
     modesetting.enable = true;
     modesetting.enable = true;
Line 57: Line 59:




<h3>Additional Resources</h3>
=== Additional Resources ===


https://discourse.nixos.org/t/razer-blade-15-nvidia-integrated-graphics-on-nixos-issues/23576/6
https://discourse.nixos.org/t/razer-blade-15-nvidia-integrated-graphics-on-nixos-issues/23576/6
Line 66: Line 68:




<h2>Updating your system to use the unstable drivers and daemon</h2>
== Updating your system to use the unstable drivers and daemon ==
If you are using a new model from razer it probably is not available in the stable packages.
If you are using a new model from Razer, it probably is not available in the stable packages.
But it might be available in the unstable ones.
But it might be available in the unstable ones.


In your configuration.nix file:
Add the below to your system configuration:
<syntaxHighlight lang=nix>
<syntaxHighlight lang=nix>
nixpkgs.config = {
  nixpkgs.config = {
     allowUnfree = true;
     allowUnfree = true;


     packageOverrides = pkgs: {
     packageOverrides = pkgs: {
       stable = import <nixos-stable> {config = config.nixpkgs.config;};
       stable = import <nixos-stable> { config = config.nixpkgs.config; };
       unstable = import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/nixos-unstable.tar.gz") { config = config.nixpkgs.config; };
       unstable = import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/nixos-unstable.tar.gz") { config = config.nixpkgs.config; };
     };
     };
   };
   };


# updates the whole kernel to unstable so you have the correct drivers.
  # updates the whole kernel to unstable so you have the correct drivers.
boot.kernelPackages = pkgs.unstable.linuxPackages;
  boot.kernelPackages = pkgs.unstable.linuxPackages;


# overrides the openrazer-daemon that the harware.openrazer.enable starts
  # overrides the openrazer-daemon that the harware.openrazer.enable starts
   nixpkgs.overlays = [
   nixpkgs.overlays = [
     (final: prev: {
     (final: prev: {
Line 93: Line 95:
   environment.systemPackages = with pkgs; [
   environment.systemPackages = with pkgs; [
     unstable.polychromatic
     unstable.polychromatic
# alternatively
  # alternatively
#   unstable.razergenie
  # unstable.razergenie
   ];
   ];
</syntaxHighlight>
</syntaxHighlight>


== USB disable Issues ==
== USB disable Issues ==
If you are encountering issues that your Razer keyboard does light up on boot shortly and then can not be found by the open-razer-daemon until you unplug your USB cable and re-plug it. Then you might want to reset your USB on startup so that after login the daemon finds it again.<syntaxhighlight lang="nixos" line="1">
If you are encountering issues that your Razer keyboard does light up on boot shortly and then can not be found by the open-razer-daemon until you unplug your USB cable and re-plug it. Then you might want to reset your USB on startup so that after login the daemon finds it again.
 
<syntaxHighlight lang=nix>
# Razer usb reset. Since it disables somehow on boot.
systemd.services."usb-reset" = {
  enable = true;
 
  description = "Resets usb port for my Razer Keyboard";
  after = ["multi-user.target"];
  serviceConfig = {
      User = "root";
      Type = "simple";
      ExecStart=pkgs.writeShellScript "unit-restart-usb7_3" ''
        echo '7-3' |tee /sys/bus/usb/drivers/usb/unbind
        echo '7-3' |tee /sys/bus/usb/drivers/usb/bind
      '';
      KillMode = "process";
      Restart = "on-failure";
  };
  wantedBy = [ "graphical.target" ];
};
</syntaxHighlight>
 
The text <code>7-3</code> is composed of the bus number (7) and the port (device?) number (3).
 
To find the bus and port numbers, read this post: [https://superuser.com/questions/1707773/how-to-turn-usb-connected-device-on-and-off-in-linux]
 
If that does not work, you can reset all USB controllers instead <ref>https://unix.stackexchange.com/questions/704341/how-to-reset-usb-controllers</ref>:
 
<syntaxHighlight lang=nix>
   # Razer usb reset. Since it disables somehow on boot.
   # Razer usb reset. Since it disables somehow on boot.
   systemd.services."usb-reset" = {
   systemd.services."usb-reset" = {
    enable = true;
     description = "Resets usb port for my Razer Keyboard";
     description = "Resets usb port for my Razer Keyboard";
     after = ["multi-user.target"];
     after = ["multi-user.target"];
Line 107: Line 141:
         User = "root";
         User = "root";
         Type = "simple";
         Type = "simple";
         ExecStart=pkgs.writeShellScript "unit-restart-usb7_3" ''
         ExecStart = pkgs.writeShellScript "unit-restart-usb-controller" ''
           echo '7-3' |tee /sys/bus/usb/drivers/usb/unbind
           #!/usr/bin/env bash
           echo '7-3' |tee /sys/bus/usb/drivers/usb/bind
          # Resets all USB host controllers of the system.
          # This is useful in case one stopped working
          # due to a faulty device having been connected to it.
 
          base="/sys/bus/pci/drivers"
          sleep_secs="1"
 
          # This might find a sub-set of these:
          # * 'ohci_hcd' - USB 3.0
          # * 'ehci-pci' - USB 2.0
          # * 'xhci_hcd' - USB 3.0
          echo "Looking for USB standards ..."
          for usb_std in "$base/"?hci[-_]?c*
           do
              echo "* USB standard '$usb_std' ..."
              for dev_path in "$usb_std/"*:*
              do
                  dev="$(basename "$dev_path")"
                  echo "  - Resetting device '$dev' ..."
                  printf '%s' "$dev" | tee "$usb_std/unbind" > /dev/null
                  sleep "$sleep_secs"
                  printf '%s' "$dev" | tee "$usb_std/bind" > /dev/null
                  echo "    done."
              done
              echo "  done."
          done
          echo "done."
         '';
         '';
         KillMode = "process";
         KillMode = "process";
         Restart = "on-failure";
         Restart = "on-failure";
     };
     };
     wantedBy = ["graphical.target"];
     wantedBy = [ "graphical.target" ];
   };
   };
</syntaxHighlight>


  systemd.services."usb-reset".enable = true;
== References ==
</syntaxhighlight>7-3 is the Bus: 7 and the Port: 3
<references />
 
How to figure those out you can read here:


https://superuser.com/questions/1707773/how-to-turn-usb-connected-device-on-and-off-in-linux
[[Category:Hardware]]

Latest revision as of 00:11, 26 March 2026

OpenRazer

OpenRazer is an open-source project to support Razer peripherals, including those found in their laptops. To enable the OpenRazer you need to add the following to your system configuration:

  hardware.openrazer.enable = true;
  environment.systemPackages = with pkgs; [
    openrazer-daemon
  ];

To run the openrazer-daemon, you need to be in the openrazer group.

users.users.<username>.extraGroups = [ "openrazer" ];

To enable a front-end to control the peripherals, add the following to your system configuration:

  environment.systemPackages = with pkgs; [
    polychromatic
  ];

Razer Blade 15 Advanced (Early 2020 model)

Lid reopen hybernate issue

Upon closing the lid to the laptop and reopening, an issue occurs where the device will intermittently go back into hybernate mode after around 10-30 seconds. Setting the kernel parameter button.lid_init_state=open fixes this issue. The following is an example configuration (working in NixOS 22.05):

boot.kernelParams = [ "button.lid_init_state=open" ];

Getting the Nvidia card to work properly with external displays

In order to get both the laptop display and external displays working, in the BIOS settings set Chipset > GPU MODE to "Dedicated GPU only".

After setting the GPU MODE to "Dedicated GPU only" in the BIOS, enabling NVIDIA#Sync mode is necessary in order for both the laptop's display and external display/ports to work properly. Here is an example configuration snippet for NixOS 22.05:

  services.xserver.videoDrivers = [ "nvidia" ];
  hardware.opengl.enable = true;

  hardware.nvidia = {
    package = config.boot.kernelPackages.nvidiaPackages.beta;
    powerManagement.enable = true;
    modesetting.enable = true;
    prime = {
      sync.enable = true;
      nvidiaBusId = "PCI:1:0:0";
      intelBusId = "PCI:0:2:0";
    };
  };


Additional Resources

https://discourse.nixos.org/t/razer-blade-15-nvidia-integrated-graphics-on-nixos-issues/23576/6

https://www.reddit.com/r/NixOS/comments/nuclde/how_to_properly_set_up_lidclose_behaviour_on_a/

https://wiki.archlinux.org/title/Razer_Blade


Updating your system to use the unstable drivers and daemon

If you are using a new model from Razer, it probably is not available in the stable packages. But it might be available in the unstable ones.

Add the below to your system configuration:

  nixpkgs.config = {
    allowUnfree = true;

    packageOverrides = pkgs: {
      stable = import <nixos-stable> { config = config.nixpkgs.config; };
      unstable = import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/nixos-unstable.tar.gz") { config = config.nixpkgs.config; };
    };
  };

  # updates the whole kernel to unstable so you have the correct drivers.
  boot.kernelPackages = pkgs.unstable.linuxPackages;

  # overrides the openrazer-daemon that the harware.openrazer.enable starts
  nixpkgs.overlays = [
    (final: prev: {
      openrazer-daemon = pkgs.unstable.openrazer-daemon;
    })
  ];

  environment.systemPackages = with pkgs; [
    unstable.polychromatic
  # alternatively
  # unstable.razergenie
  ];

USB disable Issues

If you are encountering issues that your Razer keyboard does light up on boot shortly and then can not be found by the open-razer-daemon until you unplug your USB cable and re-plug it. Then you might want to reset your USB on startup so that after login the daemon finds it again.

# Razer usb reset. Since it disables somehow on boot.
systemd.services."usb-reset" = {
  enable = true;

  description = "Resets usb port for my Razer Keyboard";
  after = ["multi-user.target"];
  serviceConfig = {
      User = "root";
      Type = "simple";
      ExecStart=pkgs.writeShellScript "unit-restart-usb7_3" ''
        echo '7-3' |tee /sys/bus/usb/drivers/usb/unbind
        echo '7-3' |tee /sys/bus/usb/drivers/usb/bind
      '';
      KillMode = "process";
      Restart = "on-failure";
  };
  wantedBy = [ "graphical.target" ];
};

The text 7-3 is composed of the bus number (7) and the port (device?) number (3).

To find the bus and port numbers, read this post: [1]

If that does not work, you can reset all USB controllers instead [1]:

  # Razer usb reset. Since it disables somehow on boot.
  systemd.services."usb-reset" = {
    enable = true;

    description = "Resets usb port for my Razer Keyboard";
    after = ["multi-user.target"];
    serviceConfig = {
        User = "root";
        Type = "simple";
        ExecStart = pkgs.writeShellScript "unit-restart-usb-controller" ''
          #!/usr/bin/env bash
          # Resets all USB host controllers of the system.
          # This is useful in case one stopped working
          # due to a faulty device having been connected to it.

          base="/sys/bus/pci/drivers"
          sleep_secs="1"

          # This might find a sub-set of these:
          # * 'ohci_hcd' - USB 3.0
          # * 'ehci-pci' - USB 2.0
          # * 'xhci_hcd' - USB 3.0
          echo "Looking for USB standards ..."
          for usb_std in "$base/"?hci[-_]?c*
          do
              echo "* USB standard '$usb_std' ..."
              for dev_path in "$usb_std/"*:*
              do
                  dev="$(basename "$dev_path")"
                  echo "  - Resetting device '$dev' ..."
                  printf '%s' "$dev" | tee "$usb_std/unbind" > /dev/null
                  sleep "$sleep_secs"
                  printf '%s' "$dev" | tee "$usb_std/bind" > /dev/null
                  echo "    done."
              done
              echo "  done."
          done
          echo "done."
        '';
        KillMode = "process";
        Restart = "on-failure";
    };
    wantedBy = [ "graphical.target" ];
  };

References