From 05b626f91257390c8dfd4990ab8b559ec8d06c2b Mon Sep 17 00:00:00 2001 From: oddlama Date: Wed, 13 Sep 2023 17:28:23 +0200 Subject: [PATCH] =?UTF-8?q?feat:=20back=20to=20xorg=20for=20gaming=20?= =?UTF-8?q?=F0=9F=98=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hosts/kroma/default.nix | 1 - modules/optional/graphical/default.nix | 1 + modules/optional/graphical/xserver.nix | 25 ++++ modules/optional/hardware/nvidia.nix | 10 +- users/myuser/graphical/default.nix | 31 ++++- users/myuser/graphical/i3.nix | 165 +++++++++++++++++++++++++ users/myuser/graphical/sway.nix | 20 --- 7 files changed, 226 insertions(+), 27 deletions(-) create mode 100644 modules/optional/graphical/xserver.nix create mode 100644 users/myuser/graphical/i3.nix diff --git a/hosts/kroma/default.nix b/hosts/kroma/default.nix index fa6e421..590e9f3 100644 --- a/hosts/kroma/default.nix +++ b/hosts/kroma/default.nix @@ -2,7 +2,6 @@ imports = [ inputs.nixos-hardware.nixosModules.common-cpu-amd inputs.nixos-hardware.nixosModules.common-cpu-amd-pstate - inputs.nixos-hardware.nixosModules.common-gpu-nvidia-nonprime inputs.nixos-hardware.nixosModules.common-pc inputs.nixos-hardware.nixosModules.common-pc-hdd inputs.nixos-hardware.nixosModules.common-pc-ssd diff --git a/modules/optional/graphical/default.nix b/modules/optional/graphical/default.nix index 6412a2d..a55e95a 100644 --- a/modules/optional/graphical/default.nix +++ b/modules/optional/graphical/default.nix @@ -12,6 +12,7 @@ in { imports = [ ./fonts.nix ./wayland.nix + ./xserver.nix ./steam.nix ]; diff --git a/modules/optional/graphical/xserver.nix b/modules/optional/graphical/xserver.nix new file mode 100644 index 0000000..1d09350 --- /dev/null +++ b/modules/optional/graphical/xserver.nix @@ -0,0 +1,25 @@ +{ + services.xserver = { + enable = true; + dpi = 96; + displayManager.startx.enable = true; + desktopManager.xterm.enable = false; + autoRepeatDelay = 235; + autoRepeatInterval = 60; + videoDrivers = ["modesetting"]; + libinput = { + enable = true; + mouse.accelProfile = "flat"; + mouse.accelSpeed = "0"; + # touchpad = { + # accelProfile = "flat"; + # accelSpeed = "0.5"; + # naturalScrolling = true; + # disableWhileTyping = true; + # }; + }; + layout = "de"; + xkbVariant = "nodeadkeys"; + }; + services.autorandr.enable = true; +} diff --git a/modules/optional/hardware/nvidia.nix b/modules/optional/hardware/nvidia.nix index f27ab35..a5dd9e3 100644 --- a/modules/optional/hardware/nvidia.nix +++ b/modules/optional/hardware/nvidia.nix @@ -1,12 +1,17 @@ -{pkgs, ...}: { +{ + lib, + pkgs, + ... +}: { boot.blacklistedKernelModules = ["nouveau"]; + services.xserver.videoDrivers = lib.mkForce ["nvidia"]; hardware = { nvidia = { modesetting.enable = true; nvidiaPersistenced = true; nvidiaSettings = true; - open = false; + open = true; powerManagement.enable = true; }; opengl = { @@ -14,6 +19,7 @@ driSupport = true; driSupport32Bit = true; extraPackages = with pkgs; [ + vaapiVdpau nvidia-vaapi-driver ]; }; diff --git a/users/myuser/graphical/default.nix b/users/myuser/graphical/default.nix index 09c7c7c..59d50da 100644 --- a/users/myuser/graphical/default.nix +++ b/users/myuser/graphical/default.nix @@ -10,7 +10,10 @@ ./firefox.nix ./kitty.nix ./signal.nix - ./sway.nix + # XXX: disabled for the time being because gaming under nvidia+wayland has too many bugs + # XXX: retest this in the future. Problems were flickering under gles, black screens and refresh issues under vulkan, black wine windows. + # ./sway.nix + ./i3.nix ] ++ lib.optionals nixosConfig.graphical.gaming.enable [ ./games/bottles.nix @@ -19,12 +22,15 @@ home = { packages = with pkgs; [ appimage-run - yt-dlp - thunderbird chromium - zathura feh + pinentry # For yubikey sirula + thunderbird + xdg-utils + xdragon + yt-dlp + zathura ]; # TODO emoji in firefox are wrong @@ -49,6 +55,23 @@ persistence."/persist".directories = [ "projects" ]; + + pointerCursor = { + gtk.enable = true; + name = "Adwaita-dark"; + package = pkgs.gnome.adwaita-icon-theme; + # TODO XXX: not working + size = 24; + }; + }; + + # Needed to fix cursors in firefox under wayland, see https://github.com/NixOS/nixpkgs/issues/207339#issuecomment-1374497558 + gtk = { + enable = true; + theme = { + package = pkgs.gnome.gnome-themes-extra; + name = "Adwaita-dark"; + }; }; xdg.mimeApps.enable = true; diff --git a/users/myuser/graphical/i3.nix b/users/myuser/graphical/i3.nix new file mode 100644 index 0000000..b6fb685 --- /dev/null +++ b/users/myuser/graphical/i3.nix @@ -0,0 +1,165 @@ +{ + lib, + config, + nixosConfig, + pkgs, + ... +}: let + inherit + (lib) + mapAttrs' + nameValuePair + ; + + bindWithModifier = mapAttrs' (k: nameValuePair (cfg.modifier + "+" + k)); + cfg = config.xsession.windowManager.i3.config; +in { + xsession.windowManager.i3 = { + enable = true; + config = { + modifier = "Mod4"; + terminal = "kitty"; + + # Excuse me, le füque + focus.followMouse = false; + focus.mouseWarping = false; + + # TODO menu = "rofi -show run"; + + keybindings = + { + "XF86AudioRaiseVolume" = "exec --no-startup-id wpctl set-sink-volume @DEFAULT_SINK@ +5%"; + "XF86AudioLowerVolume" = "exec --no-startup-id wpctl set-sink-volume @DEFAULT_SINK@ -5%"; + "XF86AudioMute" = "exec --no-startup-id wpctl set-sink-mute @DEFAULT_SINK@ toggle"; + "XF86AudioMicMute" = "exec --no-startup-id wpctl set-source-mute @DEFAULT_SOURCE@ toggle"; + + #"Print" = "exec ${pkgs.sway-contrib.grimshot}/bin/grimshot copy area"; + #"${mod}+Print" = "exec ${pkgs.sway-contrib.grimshot}/bin/grimshot save area"; + } + # // optionalAttrs useBacklight { + # "XF86MonBrightnessUp" = "exec ${pkgs.light}/bin/light -A 5"; + # "XF86MonBrightnessDown" = "exec ${pkgs.light}/bin/light -U 5"; + # } + // { + "Menu" = "exec ${cfg.menu}"; + } + # General mappings that start with $modifier+... + // bindWithModifier { + "t" = "exec ${cfg.terminal}"; + "asciicircum" = "exec ${cfg.menu}"; + "b" = "exec firefox"; + + "Shift+r" = "reload"; + "q" = "kill"; + + "Left" = "focus left"; + "Right" = "focus right"; + "Up" = "focus up"; + "Down" = "focus down"; + + "Shift+Left" = "move left"; + "Shift+Right" = "move right"; + "Shift+Up" = "move up"; + "Shift+Down" = "move down"; + + "s" = "splith"; + "v" = "splitv"; + "f" = "floating toggle"; + "Return" = "fullscreen toggle"; + "Space" = "focus mode_toggle"; + # "a" = "focus parent"; + # "s" = "layout stacking"; + # "w" = "layout tabbed"; + # "e" = "layout toggle split"; + + "Shift+Ctrl+q" = "exec swaynag -t warning -m 'You pressed the exit shortcut. Do you really want to exit sway? This will end your Wayland session.' -b 'Yes, exit sway' 'swaymsg exit'"; + "r" = "mode resize"; + + "1" = "workspace number 1"; + "2" = "workspace number 2"; + "3" = "workspace number 3"; + "4" = "workspace number 4"; + "5" = "workspace number 5"; + "6" = "workspace number 6"; + "7" = "workspace number 7"; + "8" = "workspace number 8"; + "9" = "workspace number 9"; + "Comma" = "workspace prev"; + "Period" = "workspace next"; + + "Shift+1" = "move container to workspace number 1"; + "Shift+2" = "move container to workspace number 2"; + "Shift+3" = "move container to workspace number 3"; + "Shift+4" = "move container to workspace number 4"; + "Shift+5" = "move container to workspace number 5"; + "Shift+6" = "move container to workspace number 6"; + "Shift+7" = "move container to workspace number 7"; + "Shift+8" = "move container to workspace number 8"; + "Shift+9" = "move container to workspace number 9"; + "Shift+Comma" = "move container to workspace prev"; + "Shift+Period" = "move container to workspace next"; + }; + + window.titlebar = false; + + #assigns = { + # "9" = [ + # {class = "^steam_app_";} + # {app_id = "^Steam$";} + # {class = "^steam$";} + # ]; + #}; + # TODO eww -> bars = [ ]; + }; + }; + + programs.autorandr.enable = true; + programs.autorandr.profiles = + { + kroma = let + monitorMain = "DP-2"; + monitorLeft = "DP-4"; + in { + main = { + config = { + ${monitorLeft} = { + enable = true; + mode = "3840x2160"; + rate = "60.00"; + position = "0x0"; + }; + ${monitorMain} = { + enable = true; + primary = true; + mode = "3840x2160"; + rate = "144.00"; + position = "3840x0"; + }; + }; + fingerprint = { + ${monitorMain} = "00ffffffffffff001e6d9a5b078e0a000b1f0104b53c2278f919c1ae5044af260e5054210800d1c061404540314001010101010101014dd000a0f0703e803020350058542100001a000000fd0c3090505086010a202020202020000000fc003237474e3935300a2020202020000000ff003131314e5447594c423731390a02e602032d7123090707830100004410040301e2006ae305c000e60605017360216d1a0000020b309000047321602900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000f47012790300030128d8060284ff0e9f002f801f006f08910002000400404f0104ff0e9f002f801f006f086200020004000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006d90"; + ${monitorLeft} = "00ffffffffffff001e6d095b39790700081a0104b53c22789f3035a7554ea3260f50542108007140818081c0a9c0d1c08100010101014dd000a0f0703e803020650c58542100001a286800a0f0703e800890650c58542100001a000000fd00283d878738010a202020202020000000fc004c4720556c7472612048440a2001850203117144900403012309070783010000023a801871382d40582c450058542100001e565e00a0a0a029503020350058542100001a0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c8"; + }; + }; + }; + } + .${nixosConfig.node.name} + or {}; + + home.file.".xinitrc".text = '' + if test -z "$DBUS_SESSION_BUS_ADDRESS"; then + eval $(dbus-launch --exit-with-session --sh-syntax) + fi + systemctl --user import-environment DISPLAY XAUTHORITY + + if command -v dbus-update-activation-environment >/dev/null 2>&1; then + dbus-update-activation-environment DISPLAY XAUTHORITY + fi + + autorandr -c + xset mouse 1 0 + xset r rate 235 60 + + exec i3 + ''; +} diff --git a/users/myuser/graphical/sway.nix b/users/myuser/graphical/sway.nix index 3c63580..46cb534 100644 --- a/users/myuser/graphical/sway.nix +++ b/users/myuser/graphical/sway.nix @@ -177,27 +177,7 @@ in { }; home.packages = with pkgs; [ - xdg-utils wdisplays wl-clipboard - pinentry # For yubikey - xdragon ]; - - home.pointerCursor = { - gtk.enable = true; - name = "Adwaita-dark"; - package = pkgs.gnome.adwaita-icon-theme; - # TODO XXX: not working - size = 24; - }; - - # Needed to fix cursors in firefox under wayland, see https://github.com/NixOS/nixpkgs/issues/207339#issuecomment-1374497558 - gtk = { - enable = true; - theme = { - package = pkgs.gnome.gnome-themes-extra; - name = "Adwaita-dark"; - }; - }; }