From 287c67e6dcc29773e7add1baa476a67ac4b81c89 Mon Sep 17 00:00:00 2001 From: Kopatz <7265381+Kropatz@users.noreply.github.com> Date: Tue, 11 Mar 2025 20:02:35 +0100 Subject: [PATCH] amd gpu --- .config/i3/config | 4 +- .config/polybar/amd-gpu.sh | 34 +++++++++ .config/waybar/amd-gpu.sh | 1 + flake.lock | 17 +++++ flake.nix | 1 + home-manager/hyprland/hyprland-settings.nix | 25 ++++--- home-manager/hyprland/hyprlock.nix | 2 +- home-manager/hyprland/styles/stats.css | 5 ++ home-manager/hyprland/waybar.nix | 9 ++- home-manager/i3.nix | 17 +++-- modules/networkmanager.nix | 2 + overlays.nix | 7 ++ pkgs/default.nix | 1 + pkgs/lact/default.nix | 78 +++++++++++++++++++++ systems/pc/configuration.nix | 7 +- 15 files changed, 188 insertions(+), 22 deletions(-) create mode 100755 .config/polybar/amd-gpu.sh create mode 120000 .config/waybar/amd-gpu.sh create mode 100644 pkgs/lact/default.nix diff --git a/.config/i3/config b/.config/i3/config index 7c5221b..8fcef21 100644 --- a/.config/i3/config +++ b/.config/i3/config @@ -1,8 +1,8 @@ # Please see https://i3wm.org/docs/userguide.html for a complete reference! set $mod Mod4 -set $LeftMonitor HDMI-0 -set $RightMonitor DP-4 +set $LeftMonitor HDMI-A-0 +set $RightMonitor DisplayPort-0 # Font for window titles. Will also be used by the bar unless a different font # is used in the bar {} block below. diff --git a/.config/polybar/amd-gpu.sh b/.config/polybar/amd-gpu.sh new file mode 100755 index 0000000..7b1758d --- /dev/null +++ b/.config/polybar/amd-gpu.sh @@ -0,0 +1,34 @@ +#!/usr/bin/env bash + +# Base path for AMD GPU sysfs +GPU_BASE_PATH="/sys/class/drm/card1/device" + +# Check if AMD GPU sysfs exists +if [ ! -d "$GPU_BASE_PATH" ]; then + echo "---" + exit 1 +fi + +# Get GPU usage +GPU_UTIL=$(cat "$GPU_BASE_PATH/gpu_busy_percent" 2>/dev/null || echo "N/A") + +# Base path for hwmon (temperature and power readings) +HWMON_PATH="$GPU_BASE_PATH/hwmon/hwmon0" + +# Get GPU temperature +TEMP_PATH="$HWMON_PATH/temp1_input" +if [ -f "$TEMP_PATH" ]; then + GPU_TEMP=$(($(cat "$TEMP_PATH") / 1000)) # Convert from millidegrees to degrees +else + GPU_TEMP="N/A" +fi + +# Get GPU power usage +POWER_PATH="$HWMON_PATH/power1_average" +if [ -f "$POWER_PATH" ]; then + GPU_POWER=$(($(cat "$POWER_PATH") / 1000000)) # Convert from microwatts to watts +else + GPU_POWER="N/A" +fi + +echo "GPU ${GPU_UTIL}%, ${GPU_TEMP}°C, ${GPU_POWER}W" diff --git a/.config/waybar/amd-gpu.sh b/.config/waybar/amd-gpu.sh new file mode 120000 index 0000000..ed20b6f --- /dev/null +++ b/.config/waybar/amd-gpu.sh @@ -0,0 +1 @@ +../polybar/amd-gpu.sh \ No newline at end of file diff --git a/flake.lock b/flake.lock index 8a66c6a..e18c33a 100644 --- a/flake.lock +++ b/flake.lock @@ -646,6 +646,22 @@ "type": "github" } }, + "nixpkgs-mesa-git": { + "locked": { + "lastModified": 1741705751, + "narHash": "sha256-TERyCTgLllWgmuYMxbrnjjJQYkj2TT7QoTDUCT/oFOc=", + "owner": "kropatz", + "repo": "nixpkgs", + "rev": "97c017ceecbbc3a5a8e588f3f2e79182afd2dd29", + "type": "github" + }, + "original": { + "owner": "kropatz", + "ref": "mesa-git", + "repo": "nixpkgs", + "type": "github" + } + }, "nixpkgs-stable": { "locked": { "lastModified": 1741332913, @@ -810,6 +826,7 @@ "nixos-wsl": "nixos-wsl", "nixpkgs": "nixpkgs", "nixpkgs-gimp3": "nixpkgs-gimp3", + "nixpkgs-mesa-git": "nixpkgs-mesa-git", "nixpkgs-unstable": "nixpkgs-unstable", "nixvim": "nixvim", "nur": "nur", diff --git a/flake.nix b/flake.nix index 98fd209..50ed55d 100644 --- a/flake.nix +++ b/flake.nix @@ -31,6 +31,7 @@ #nixpkgs-unstable.url = "github:nixos/nixpkgs/a6916c76a7d202e3c02134e620f6477b8600ce9d"; nixpkgs-unstable.url = "github:nixos/nixpkgs/nixos-unstable"; nixpkgs-gimp3.url = "github:jtojnar/nixpkgs/gimp-meson"; + nixpkgs-mesa-git.url = "github:kropatz/nixpkgs/mesa-git"; home-manager-unstable = { url = "github:nix-community/home-manager/master"; inputs.nixpkgs.follows = "nixpkgs-unstable"; diff --git a/home-manager/hyprland/hyprland-settings.nix b/home-manager/hyprland/hyprland-settings.nix index c2ca65a..ca7b348 100644 --- a/home-manager/hyprland/hyprland-settings.nix +++ b/home-manager/hyprland/hyprland-settings.nix @@ -10,6 +10,8 @@ let sleep 4 systemctl --user restart xdg-desktop-portal ''; + monitor1 = if isPc then "DP-1" else if isLaptop then "eDP-1" else "eDP-1"; + monitor2 = "HDMI-A-1"; in { config = lib.mkIf cfg.enable { @@ -28,8 +30,8 @@ in { # See https://wiki.hyprland.org/Configuring/Monitors/ monitor = if isPc then [ - "HDMI-A-1,1920x1080@60,0x0,1" - "DP-3,2560x1440@150,1920x0,1" + "${monitor2},1920x1080@60,0x0,1" + "${monitor1},2560x1440@144,1920x0,1" "Unknown-1,disable" ] else if isLaptop then [ # laptop @@ -45,13 +47,13 @@ in { workspace = lib.lists.optionals (osConfig.networking.hostName == "kop-pc") [ - "1,monitor:DP-3" - "2,monitor:DP-3" - "3,monitor:DP-3" - "4,monitor:DP-3" - "5,monitor:DP-3" - "9,monitor:HDMI-A-1" - "10,monitor:HDMI-A-1" + "1,monitor:${monitor1}" + "2,monitor:${monitor1}" + "3,monitor:${monitor1}" + "4,monitor:${monitor1}" + "5,monitor:${monitor1}" + "9,monitor:${monitor2}" + "10,monitor:${monitor2}" ]; # See https://wiki.hyprland.org/Configuring/Keywords/ for more @@ -64,7 +66,7 @@ in { # Some default env vars. env = - [ "XCURSOR_SIZE,24" "NIXOS_OZONE_WL,1" "WLR_NO_HARDWARE_CURSORS,1" ] + [ "XCURSOR_SIZE,24" "NIXOS_OZONE_WL,1" ] ++ lib.optionals osConfig.custom.hardware.nvidia.enable [ "LIBVA_DRIVER_NAME,nvidia" "GBM_BACKEND,nvidia-drm" @@ -88,7 +90,7 @@ in { sensitivity = 0; }; - cursor = { no_hardware_cursors = true; }; + #cursor = { no_hardware_cursors = true; }; #render = { # explicit_sync = 1; @@ -303,6 +305,7 @@ in { ] ++ [ "sleep 3 && ${pkgs.waybar}/bin/waybar &" "${restartPortals}" + "xrandr --monitor ${monitor1} --primary" ]; }; extraConfig = let diff --git a/home-manager/hyprland/hyprlock.nix b/home-manager/hyprland/hyprlock.nix index 63bee38..1a058d9 100644 --- a/home-manager/hyprland/hyprlock.nix +++ b/home-manager/hyprland/hyprlock.nix @@ -58,7 +58,7 @@ in { }; # don't autostart - systemd.user.services.hypridle.Service.ExecStart = lib.mkForce "true"; + systemd.user.services.hypridle.Service.ExecStart = lib.mkForce "${pkgs.coreutils}/bin/true"; systemd.user.services.hypridle.Service.Restart = lib.mkForce "no"; services.hypridle.enable = true; services.hypridle.settings = { diff --git a/home-manager/hyprland/styles/stats.css b/home-manager/hyprland/styles/stats.css index a487d19..35de0f9 100644 --- a/home-manager/hyprland/styles/stats.css +++ b/home-manager/hyprland/styles/stats.css @@ -1,4 +1,5 @@ @define-color nvidia-green #76b900; +@define-color amdgpu-red #ed1c24; #other, #other-drawer, @@ -43,6 +44,10 @@ color: @nvidia-green; } +#custom-amd-gpu { + color: @amdgpu-red; +} + #network.disconnected { background-color: #f53c3c; } diff --git a/home-manager/hyprland/waybar.nix b/home-manager/hyprland/waybar.nix index ef111c7..997020a 100644 --- a/home-manager/hyprland/waybar.nix +++ b/home-manager/hyprland/waybar.nix @@ -34,7 +34,9 @@ in { modules-right = [ "group/stats" "group/other" ]; "group/stats" = { "orientation" = "horizontal"; - "modules" = [ "network" "cpu" "memory" "disk" "temperature" ] ++ lib.optionals (osConfig.networking.hostName != "nix-laptop") [ "custom/nvidia" ] ; + "modules" = [ "network" "cpu" "memory" "disk" "temperature" ] + ++ lib.optionals osConfig.custom.hardware.nvidia.enable [ "custom/nvidia" ] + ++ lib.optionals osConfig.custom.hardware.amd-gpu.enable [ "custom/amd-gpu" ]; }; "group/other" = { "orientation" = "horizontal"; @@ -147,6 +149,11 @@ in { "exec" = "~/.config/waybar/nvidia.sh"; "exec-if" = "nvidia-smi"; }; + "custom/amd-gpu" = { + "format" = "{}"; + "interval" = 5; + "exec" = "~/.config/waybar/amd-gpu.sh"; + }; "tray".icon-size = 21; "tray".spacing = 10; "hyprland/window" = { diff --git a/home-manager/i3.nix b/home-manager/i3.nix index e0c14a0..a6871d8 100644 --- a/home-manager/i3.nix +++ b/home-manager/i3.nix @@ -55,8 +55,10 @@ in { module-margin = 1; modules-left = "i3 xwindow"; modules-center = ""; - modules-right = - "music network memory cpu cpu-wattage cpu-temp gpu pulseaudio date tray"; + modules-right = [ "music network memory cpu cpu-wattage cpu-temp" ] + ++ lib.optionals osConfig.custom.hardware.nvidia.enable [ "nvidia-gpu" ] + ++ lib.optionals osConfig.custom.hardware.amd-gpu.enable [ "amd-gpu" ] + ++ [ "pulseaudio date tray" ]; cursor-click = "pointer"; cursor-scroll = "ns-resize"; enable-ipc = true; @@ -187,13 +189,20 @@ in { exec = "~/.config/polybar/temperature.sh"; interval = 3; }; - "module/gpu" = { + "module/nvidia-gpu" = { type = "custom/script"; - format-foreground = "76b900"; #nvidia green + format-foreground = "76b900"; # nvidia green label = "%output:0:35:...%"; exec = "~/.config/polybar/nvidia.sh"; interval = 3; }; + "module/amd-gpu" = { + type = "custom/script"; + format-foreground = "ed1c24"; + label = "%output:0:35:...%"; + exec = "~/.config/polybar/amd-gpu.sh"; + interval = 3; + }; "module/music" = { type = "custom/script"; exec = "~/.config/polybar/player-mpris-simple.sh"; diff --git a/modules/networkmanager.nix b/modules/networkmanager.nix index 15456c3..9079055 100644 --- a/modules/networkmanager.nix +++ b/modules/networkmanager.nix @@ -1,3 +1,5 @@ +{pkgs, lib, ...}: { networking.networkmanager.enable = true; + networking.networkmanager.plugins = lib.mkForce [ pkgs.networkmanager-openvpn ]; } diff --git a/overlays.nix b/overlays.nix index e359722..1ac1ec6 100644 --- a/overlays.nix +++ b/overlays.nix @@ -4,6 +4,10 @@ let addPatches = pkg: patches: pkg.overrideAttrs (oldAttrs: { patches = (oldAttrs.patches or [ ]) ++ patches; }); + mesa-git = import inputs.nixpkgs-mesa-git { + system = "x86_64-linux"; + config.allowUnfree = true; + }; in { # This one brings our custom packages from the 'pkgs' directory additions = final: _prev: import ./pkgs { pkgs = final; }; @@ -15,6 +19,9 @@ in { discord-canary = prev.discord-canary.override { withVencord = true; }; discord = prev.discord.override { withVencord = true; }; tetrio-desktop = prev.tetrio-desktop.override { withTetrioPlus = true; }; + lact = prev.rdna4-lact; + #mesa = mesa-git.pkgs.mesa; + #wayland-protocols = mesa-git.pkgs.wayland-protocols; #hyprland = prev.hyprland.overrideAttrs (oldAttrs: { # version = "0.45.0"; # src = prev.fetchFromGitHub { diff --git a/pkgs/default.nix b/pkgs/default.nix index 6db687e..ebeb931 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -12,4 +12,5 @@ mangal-patched = pkgs.callPackage ./mangal/default.nix { }; electron_27 = pkgs.callPackage ./electron27/default.nix { }; logseq = pkgs.callPackage ./logseq/default.nix { inherit electron_27; }; + rdna4-lact = pkgs.callPackage ./lact/default.nix { }; } diff --git a/pkgs/lact/default.nix b/pkgs/lact/default.nix new file mode 100644 index 0000000..6c57dc2 --- /dev/null +++ b/pkgs/lact/default.nix @@ -0,0 +1,78 @@ +{ lib, rustPlatform, stdenv, fetchFromGitHub, blueprint-compiler, pkg-config +, wrapGAppsHook4, gdk-pixbuf, gtk4, libdrm, vulkan-loader, coreutils +, nix-update-script, hwdata, fuse }: + +rustPlatform.buildRustPackage rec { + pname = "lact"; + version = "0.7.1"; + + src = fetchFromGitHub { + owner = "ilya-zlobintsev"; + repo = "LACT"; + #rev = "v${version}"; + #hash = "sha256-zaN6CQSeeoYFxLO6E1AMKAjeNOcPi2OsGfYkvZLPKcw="; + rev = "e472dec45682f96a272b77d368791121e10ba7da"; + hash = "sha256-d081f49ojJzz0N28lIu3NZ8SSvSuoz2HfjQl5Zu8PpU="; + }; + + useFetchCargoVendor = true; + cargoHash = "sha256-vc8KqMov2Og5wRS4b9n9Vixtg4vwCM/MlkCDbqsG3Kg="; + + nativeBuildInputs = + [ blueprint-compiler pkg-config wrapGAppsHook4 rustPlatform.bindgenHook ]; + + buildInputs = [ gdk-pixbuf gtk4 libdrm vulkan-loader hwdata fuse ]; + + # we do this here so that the binary is usable during integration tests + RUSTFLAGS = lib.optionalString stdenv.targetPlatform.isElf + (lib.concatStringsSep " " [ + "-C link-arg=-Wl,-rpath,${lib.makeLibraryPath [ vulkan-loader libdrm ]}" + "-C link-arg=-Wl,--add-needed,${vulkan-loader}/lib/libvulkan.so" + "-C link-arg=-Wl,--add-needed,${libdrm}/lib/libdrm.so" + ]); + + checkFlags = [ + # tries and fails to initialize gtk + "--skip=app::pages::thermals_page::fan_curve_frame::tests::set_get_curve" + "--skip=tests::snapshot_everything" + ]; + + postPatch = '' + substituteInPlace lact-daemon/src/server/system.rs \ + --replace-fail 'Command::new("uname")' 'Command::new("${coreutils}/bin/uname")' + + substituteInPlace res/lactd.service \ + --replace-fail ExecStart={lact,$out/bin/lact} + + substituteInPlace res/io.github.lact-linux.desktop \ + --replace-fail Exec={lact,$out/bin/lact} + + # read() looks for the database in /usr/share so we use read_from_file() instead + substituteInPlace lact-daemon/src/server/handler.rs \ + --replace-fail 'Database::read()' 'Database::read_from_file("${hwdata}/share/hwdata/pci.ids")' + ''; + + postInstall = '' + install -Dm444 res/lactd.service -t $out/lib/systemd/system + install -Dm444 res/io.github.lact-linux.desktop -t $out/share/applications + install -Dm444 res/io.github.lact-linux.png -t $out/share/pixmaps + ''; + + postFixup = lib.optionalString stdenv.targetPlatform.isElf '' + patchelf $out/bin/.lact-wrapped \ + --add-needed libvulkan.so \ + --add-needed libdrm.so \ + --add-rpath ${lib.makeLibraryPath [ vulkan-loader libdrm ]} + ''; + + passthru.updateScript = nix-update-script { }; + + meta = { + description = "Linux GPU Configuration Tool for AMD and NVIDIA"; + homepage = "https://github.com/ilya-zlobintsev/LACT"; + license = lib.licenses.mit; + maintainers = with lib.maintainers; [ figsoda atemu ]; + platforms = lib.platforms.linux; + mainProgram = "lact"; + }; +} diff --git a/systems/pc/configuration.nix b/systems/pc/configuration.nix index 6ee44a2..56c9a7c 100644 --- a/systems/pc/configuration.nix +++ b/systems/pc/configuration.nix @@ -15,6 +15,7 @@ ../../modules/work/vpn.nix ../../modules/misc/faster-boot-time.nix ../../modules/hardware/ryzen.nix + ../../modules/networkmanager.nix ]; custom = { @@ -40,8 +41,9 @@ services = { syncthing = { enable = true; }; }; hardware = { android.enable = true; + amd-gpu.enable = true; nvidia = { - enable = true; + enable = false; clock = { enable = true; min = 210; @@ -75,7 +77,7 @@ nightlight.enable = true; #plasma.enable = true; i3.enable = true; - sway.enable = true; + #sway.enable = true; hyprland.enable = true; #gnome.enable = true; #cosmic.enable = true; @@ -166,7 +168,6 @@ networking.hostName = "kop-pc"; # Define your hostname. # Enable networking - networking.networkmanager.enable = true; boot.initrd.systemd.network.wait-online.enable = false; systemd.network.wait-online.enable = false;