Hardware/Razer: Difference between revisions

Revert code blocks to syntax highlighting
DHCP (talk | contribs)
m style fixes
 
Line 6: Line 6:


<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>


Line 21: Line 21:


<syntaxHighlight lang=nix>
<syntaxHighlight lang=nix>
  environment.systemPackages = with pkgs; [
environment.systemPackages = with pkgs; [
    polychromatic
  polychromatic
  ];
];
</syntaxHighlight>
</syntaxHighlight>


Line 43: Line 43:


<syntaxHighlight lang=nix>
<syntaxHighlight lang=nix>
  services.xserver.videoDrivers = [ "nvidia" ];
services.xserver.videoDrivers = [ "nvidia" ];
  hardware.opengl.enable = true;
hardware.opengl.enable = true;


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


=== Additional Resources ===
=== Additional Resources ===
Line 66: Line 65:


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


== Updating your system to use the unstable drivers and daemon ==
== Updating your system to use the unstable drivers and daemon ==
Line 74: Line 72:
Add the below to your system configuration:
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: {
      openrazer-daemon = pkgs.unstable.openrazer-daemon;
    openrazer-daemon = pkgs.unstable.openrazer-daemon;
    })
  })
  ];
];


  environment.systemPackages = with pkgs; [
environment.systemPackages = with pkgs; [
    unstable.polychromatic
  unstable.polychromatic
   # alternatively
   # alternatively:
   # unstable.razergenie
   # unstable.razergenie
  ];
];
</syntaxHighlight>
</syntaxHighlight>


Line 132: Line 130:


<syntaxHighlight lang=nix>
<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;
  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"];
    serviceConfig = {
  serviceConfig = {
        User = "root";
      User = "root";
        Type = "simple";
      Type = "simple";
        ExecStart = pkgs.writeShellScript "unit-restart-usb-controller" ''
      ExecStart = pkgs.writeShellScript "unit-restart-usb-controller" ''
          #!/usr/bin/env bash
        #!/usr/bin/env bash
          # Resets all USB host controllers of the system.
        # Resets all USB host controllers of the system.
          # This is useful in case one stopped working
        # This is useful in case one stopped working
          # due to a faulty device having been connected to it.
        # due to a faulty device having been connected to it.


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


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