feat: refactor Niri configuration by removing deprecated services and scripts, and updating display management to use niri-native scripts
This commit is contained in:
@@ -1,8 +1,4 @@
|
|||||||
{
|
{pkgs, ...}: let
|
||||||
pkgs,
|
|
||||||
lib,
|
|
||||||
...
|
|
||||||
}: let
|
|
||||||
# Configuration variables from your script
|
# Configuration variables from your script
|
||||||
preferred_resolution = "2880x1800";
|
preferred_resolution = "2880x1800";
|
||||||
refresh_rate = "120";
|
refresh_rate = "120";
|
||||||
@@ -41,6 +37,7 @@
|
|||||||
'';
|
'';
|
||||||
|
|
||||||
# Inline scripts adapted for niri
|
# Inline scripts adapted for niri
|
||||||
|
# Stage 3: Configuration - applies the display setup
|
||||||
zenbook-top = pkgs.writeShellScriptBin "zenbook-top" ''
|
zenbook-top = pkgs.writeShellScriptBin "zenbook-top" ''
|
||||||
echo "[DEBUG] zenbook-top: Setting to top screen only"
|
echo "[DEBUG] zenbook-top: Setting to top screen only"
|
||||||
echo "[DEBUG] Configuring eDP-1..."
|
echo "[DEBUG] Configuring eDP-1..."
|
||||||
@@ -48,8 +45,10 @@
|
|||||||
${pkgs.niri}/bin/niri msg output eDP-1 mode ${preferred_resolution}@${refresh_rate} || echo "[ERROR] Failed to set eDP-1 mode"
|
${pkgs.niri}/bin/niri msg output eDP-1 mode ${preferred_resolution}@${refresh_rate} || echo "[ERROR] Failed to set eDP-1 mode"
|
||||||
${pkgs.niri}/bin/niri msg output eDP-1 scale ${ui_scale} || echo "[ERROR] Failed to set eDP-1 scale"
|
${pkgs.niri}/bin/niri msg output eDP-1 scale ${ui_scale} || echo "[ERROR] Failed to set eDP-1 scale"
|
||||||
${pkgs.niri}/bin/niri msg output eDP-1 position set 0 0 || echo "[ERROR] Failed to set eDP-1 position"
|
${pkgs.niri}/bin/niri msg output eDP-1 position set 0 0 || echo "[ERROR] Failed to set eDP-1 position"
|
||||||
echo "[DEBUG] Turning off eDP-2..."
|
echo "[DEBUG] Disabling eDP-2..."
|
||||||
${pkgs.niri}/bin/niri msg output eDP-2 off || echo "[ERROR] Failed to turn off eDP-2"
|
${pkgs.niri}/bin/niri msg output eDP-2 off || echo "[ERROR] Failed to turn off eDP-2"
|
||||||
|
# Force disable by setting power mode off (if supported)
|
||||||
|
${pkgs.niri}/bin/niri msg output eDP-2 disable 2>/dev/null || echo "[DEBUG] disable command not available, using off"
|
||||||
echo "[DEBUG] zenbook-top: Complete"
|
echo "[DEBUG] zenbook-top: Complete"
|
||||||
'';
|
'';
|
||||||
|
|
||||||
@@ -60,6 +59,8 @@
|
|||||||
${pkgs.niri}/bin/niri msg output eDP-2 scale ${ui_scale}
|
${pkgs.niri}/bin/niri msg output eDP-2 scale ${ui_scale}
|
||||||
${pkgs.niri}/bin/niri msg output eDP-2 position set 0 0
|
${pkgs.niri}/bin/niri msg output eDP-2 position set 0 0
|
||||||
${pkgs.niri}/bin/niri msg output eDP-1 off
|
${pkgs.niri}/bin/niri msg output eDP-1 off
|
||||||
|
# Force disable by setting power mode off (if supported)
|
||||||
|
${pkgs.niri}/bin/niri msg output eDP-1 disable 2>/dev/null || echo "[DEBUG] disable command not available, using off"
|
||||||
'';
|
'';
|
||||||
|
|
||||||
zenbook-both = pkgs.writeShellScriptBin "zenbook-both" ''
|
zenbook-both = pkgs.writeShellScriptBin "zenbook-both" ''
|
||||||
@@ -101,9 +102,10 @@
|
|||||||
${pkgs.niri}/bin/niri msg output eDP-2 position set ${y_offset} 0
|
${pkgs.niri}/bin/niri msg output eDP-2 position set ${y_offset} 0
|
||||||
'';
|
'';
|
||||||
|
|
||||||
zenbook-normal = pkgs.writeShellScriptBin "zenbook-normal" ''
|
# Stage 2: Detection - determines which configuration to apply
|
||||||
|
zenbook-detect = pkgs.writeShellScriptBin "zenbook-detect" ''
|
||||||
# Simple keyboard detection based on the original duo script
|
# Simple keyboard detection based on the original duo script
|
||||||
echo "[DEBUG] zenbook-normal: Starting detection"
|
echo "[DEBUG] zenbook-detect: Starting detection"
|
||||||
echo "[DEBUG] Running lsusb to find keyboard..."
|
echo "[DEBUG] Running lsusb to find keyboard..."
|
||||||
${pkgs.usbutils}/bin/lsusb > /tmp/zenbook-lsusb.log
|
${pkgs.usbutils}/bin/lsusb > /tmp/zenbook-lsusb.log
|
||||||
echo "[DEBUG] lsusb output saved to /tmp/zenbook-lsusb.log"
|
echo "[DEBUG] lsusb output saved to /tmp/zenbook-lsusb.log"
|
||||||
@@ -122,6 +124,11 @@
|
|||||||
fi
|
fi
|
||||||
'';
|
'';
|
||||||
|
|
||||||
|
# Legacy alias for compatibility
|
||||||
|
zenbook-normal = pkgs.writeShellScriptBin "zenbook-normal" ''
|
||||||
|
${zenbook-detect}/bin/zenbook-detect
|
||||||
|
'';
|
||||||
|
|
||||||
zenbook-toggle = pkgs.writeShellScriptBin "zenbook-toggle" ''
|
zenbook-toggle = pkgs.writeShellScriptBin "zenbook-toggle" ''
|
||||||
# Check current state and toggle
|
# Check current state and toggle
|
||||||
enabled_count=$(${pkgs.niri}/bin/niri msg outputs | grep -c "eDP.*" || echo "0")
|
enabled_count=$(${pkgs.niri}/bin/niri msg outputs | grep -c "eDP.*" || echo "0")
|
||||||
@@ -132,34 +139,50 @@
|
|||||||
fi
|
fi
|
||||||
'';
|
'';
|
||||||
|
|
||||||
# Simple event-driven display management (based on original duo script)
|
# Stage 1: Watch service - monitors for changes and triggers detection
|
||||||
zenbook-watch-displays = pkgs.writeShellScriptBin "zenbook-watch-displays" ''
|
zenbook-watch-displays = pkgs.writeShellScriptBin "zenbook-watch-displays" ''
|
||||||
echo "[DEBUG] zenbook-watch-displays: Starting"
|
echo "[DEBUG] zenbook-watch-displays: Starting"
|
||||||
echo "[DEBUG] Running initial setup"
|
echo "[DEBUG] Running initial detection"
|
||||||
# Run initial setup
|
# Run initial detection
|
||||||
${zenbook-normal}/bin/zenbook-normal
|
${zenbook-detect}/bin/zenbook-detect
|
||||||
|
|
||||||
echo "[DEBUG] Starting USB device monitoring on /dev/bus/usb/*/"
|
echo "[DEBUG] Starting USB device monitoring on /dev/bus/usb/*/"
|
||||||
|
# Track last run time to debounce rapid-fire events
|
||||||
|
last_run=0
|
||||||
|
debounce_seconds=3
|
||||||
|
|
||||||
# Watch for USB device changes (keyboard attach/detach)
|
# Watch for USB device changes (keyboard attach/detach)
|
||||||
while ${pkgs.inotify-tools}/bin/inotifywait -e attrib /dev/bus/usb/*/; do
|
while ${pkgs.inotify-tools}/bin/inotifywait -e attrib /dev/bus/usb/*/; do
|
||||||
echo "[DEBUG] USB device change detected at $(date)"
|
current_time=$(date +%s)
|
||||||
sleep 0.5
|
time_diff=$((current_time - last_run))
|
||||||
${zenbook-normal}/bin/zenbook-normal
|
|
||||||
|
if [ $time_diff -ge $debounce_seconds ]; then
|
||||||
|
echo "[DEBUG] USB device change detected at $(date) (debounced)"
|
||||||
|
sleep 0.5
|
||||||
|
${zenbook-detect}/bin/zenbook-detect
|
||||||
|
last_run=$current_time
|
||||||
|
else
|
||||||
|
echo "[DEBUG] USB device change ignored (debounce: $time_diff < $debounce_seconds seconds)"
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
'';
|
'';
|
||||||
|
|
||||||
|
# Legacy wrapper - calls detect directly
|
||||||
zenbook-set-displays = pkgs.writeShellScriptBin "zenbook-set-displays" ''
|
zenbook-set-displays = pkgs.writeShellScriptBin "zenbook-set-displays" ''
|
||||||
sleep 0.5
|
sleep 0.5
|
||||||
${zenbook-normal}/bin/zenbook-normal
|
${zenbook-detect}/bin/zenbook-detect
|
||||||
'';
|
'';
|
||||||
|
|
||||||
# Simplified auto-run display setup on startup (based on original duo approach)
|
# Simplified auto-run display setup on startup (based on original duo approach)
|
||||||
zenbook-autostart = pkgs.writeShellScriptBin "zenbook-autostart" ''
|
zenbook-autostart = pkgs.writeShellScriptBin "zenbook-autostart" ''
|
||||||
echo "Running initial display setup"
|
echo "Running initial display setup"
|
||||||
sleep 1
|
sleep 1
|
||||||
${zenbook-set-displays}/bin/zenbook-set-displays
|
${zenbook-detect}/bin/zenbook-detect
|
||||||
'';
|
'';
|
||||||
in {
|
in {
|
||||||
# Zenbook dual-screen display configuration for niri
|
# Zenbook dual-screen display configuration for niri
|
||||||
|
# NOTE: We only configure eDP-1 statically and let scripts manage eDP-2 dynamically
|
||||||
|
# This allows the off command to actually work
|
||||||
programs.niri.settings = {
|
programs.niri.settings = {
|
||||||
outputs = {
|
outputs = {
|
||||||
"eDP-1" = {
|
"eDP-1" = {
|
||||||
@@ -175,23 +198,11 @@ in {
|
|||||||
};
|
};
|
||||||
variable-refresh-rate = true;
|
variable-refresh-rate = true;
|
||||||
};
|
};
|
||||||
"eDP-2" = {
|
# eDP-2 is managed dynamically by zenbook-detect scripts
|
||||||
mode = {
|
|
||||||
width = 2880;
|
|
||||||
height = 1800;
|
|
||||||
refresh = 120.0;
|
|
||||||
};
|
|
||||||
scale = 1.5;
|
|
||||||
position = {
|
|
||||||
x = 0;
|
|
||||||
y = 1200;
|
|
||||||
};
|
|
||||||
variable-refresh-rate = true;
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
# Keybind to run zenbook-set-displays via UWSM
|
# Keybind to run zenbook-detect via UWSM
|
||||||
binds."Mod+Z".action.spawn = ["uwsm" "app" "--" "${zenbook-set-displays}/bin/zenbook-set-displays"];
|
binds."Mod+Z".action.spawn = ["uwsm" "app" "--" "${zenbook-detect}/bin/zenbook-detect"];
|
||||||
};
|
};
|
||||||
|
|
||||||
# Migrate to systemd user services for UWSM integration
|
# Migrate to systemd user services for UWSM integration
|
||||||
@@ -249,40 +260,19 @@ in {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
# Monitor udev events for display changes
|
# DISABLED: udev monitor - not needed with inotify approach
|
||||||
zenbook-udev-monitor = {
|
# zenbook-udev-monitor service removed to prevent conflicts
|
||||||
Unit = {
|
|
||||||
Description = "ZenBook Duo udev Display Monitor";
|
|
||||||
After = ["graphical-session.target"];
|
|
||||||
PartOf = ["graphical-session.target"];
|
|
||||||
};
|
|
||||||
Service = {
|
|
||||||
Type = "simple";
|
|
||||||
ExecStart = "${pkgs.writeShellScript "zenbook-udev-loop" ''
|
|
||||||
${pkgs.udev}/bin/udevadm monitor --udev --subsystem-match=drm | while read line; do
|
|
||||||
if echo "$line" | grep -q "change"; then
|
|
||||||
sleep 2
|
|
||||||
${zenbook-set-displays}/bin/zenbook-set-displays
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
''}";
|
|
||||||
Restart = "always";
|
|
||||||
RestartSec = "5";
|
|
||||||
};
|
|
||||||
Install = {
|
|
||||||
WantedBy = ["graphical-session.target"];
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
# Hook into swayidle for unlock/resume events (if using swayidle)
|
# DISABLED: swayidle hook was running zenbook-detect every second, causing conflicts
|
||||||
services.swayidle.timeouts = lib.mkAfter [
|
# The zenbook-inotify-monitor service handles USB detection automatically
|
||||||
{
|
# services.swayidle.timeouts = lib.mkAfter [
|
||||||
timeout = 1;
|
# {
|
||||||
command = "${zenbook-set-displays}/bin/zenbook-set-displays";
|
# timeout = 1;
|
||||||
resumeCommand = "${zenbook-set-displays}/bin/zenbook-set-displays";
|
# command = "${zenbook-detect}/bin/zenbook-detect";
|
||||||
}
|
# resumeCommand = "${zenbook-detect}/bin/zenbook-detect";
|
||||||
];
|
# }
|
||||||
|
# ];
|
||||||
|
|
||||||
# Add the scripts to home packages
|
# Add the scripts to home packages
|
||||||
home.packages = [
|
home.packages = [
|
||||||
@@ -292,6 +282,7 @@ in {
|
|||||||
zenbook-both
|
zenbook-both
|
||||||
zenbook-left-up
|
zenbook-left-up
|
||||||
zenbook-right-up
|
zenbook-right-up
|
||||||
|
zenbook-detect
|
||||||
zenbook-normal
|
zenbook-normal
|
||||||
zenbook-toggle
|
zenbook-toggle
|
||||||
zenbook-watch-displays
|
zenbook-watch-displays
|
||||||
|
|||||||
@@ -5,10 +5,6 @@
|
|||||||
}: {
|
}: {
|
||||||
imports = [
|
imports = [
|
||||||
inputs.niri.nixosModules.niri
|
inputs.niri.nixosModules.niri
|
||||||
(import ./niri/waybar.nix)
|
|
||||||
(import ./niri/swayidle.nix)
|
|
||||||
(import ./niri/fuzzel.nix)
|
|
||||||
(import ./niri/swaylock.nix)
|
|
||||||
];
|
];
|
||||||
|
|
||||||
programs.niri.enable = true;
|
programs.niri.enable = true;
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
{pkgs, ...}: {
|
|
||||||
environment.systemPackages = with pkgs; [fuzzel];
|
|
||||||
|
|
||||||
# Provide a simple system-wide wrapper script in /etc/profile.d or /etc to make fuzzel available
|
|
||||||
environment.etc."profile.d/fuzzel.sh".text = ''
|
|
||||||
export PATH="${pkgs.fuzzel}/bin:$PATH"
|
|
||||||
'';
|
|
||||||
}
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
{pkgs, ...}: {
|
|
||||||
# Install swayidle and configure a systemd user service for idle locking
|
|
||||||
environment.systemPackages = with pkgs; [swayidle swaylock inotify-tools];
|
|
||||||
|
|
||||||
systemd.user.services.swayidle = {
|
|
||||||
description = "swayidle for Niri sessions";
|
|
||||||
wantedBy = ["default.target"];
|
|
||||||
serviceConfig = {
|
|
||||||
ExecStart = "${pkgs.swayidle}/bin/swayidle -w 'timeout 300 ${pkgs.swaylock}/bin/swaylock -f' resume 'swaymsg resume'";
|
|
||||||
Restart = "on-failure";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
{pkgs, ...}: {
|
|
||||||
environment.systemPackages = with pkgs; [swaylock imagemagick];
|
|
||||||
|
|
||||||
# Provide a system-level helper in /etc/profile.d to point to a lock wrapper
|
|
||||||
environment.etc."profile.d/lockwrapper.sh".text = ''
|
|
||||||
#!/bin/sh
|
|
||||||
export LOCK_WRAPPER="${pkgs.swaylock}/bin/swaylock"
|
|
||||||
'';
|
|
||||||
}
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
{pkgs, ...}: {
|
|
||||||
# Install waybar system-wide and provide a systemd user service to start it for graphical users
|
|
||||||
environment.systemPackages = with pkgs; [waybar jq wl-clipboard];
|
|
||||||
|
|
||||||
systemd.user.services.waybar = {
|
|
||||||
description = "Waybar for Niri sessions";
|
|
||||||
wantedBy = ["default.target"];
|
|
||||||
serviceConfig = {
|
|
||||||
ExecStart = "${pkgs.waybar}/bin/waybar";
|
|
||||||
Restart = "on-failure";
|
|
||||||
RestartSec = 2;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
# Optionally provide a default system-level config in /etc/xdg/waybar/config
|
|
||||||
environment.etc."xdg/waybar/config".text = ''
|
|
||||||
{
|
|
||||||
"modules-left": ["workspace"],
|
|
||||||
"modules-center": [],
|
|
||||||
"modules-right": ["clock"]
|
|
||||||
}
|
|
||||||
'';
|
|
||||||
}
|
|
||||||
@@ -33,29 +33,31 @@ in {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
systemd.user.services.watchDisplays = {
|
# DISABLED: Old gnome-monitor-config approach - now using niri-native zenbook-screen.nix
|
||||||
description = "set screens on keyboard event";
|
# systemd.user.services.watchDisplays = {
|
||||||
wantedBy = ["default.target"];
|
# description = "set screens on keyboard event";
|
||||||
after = ["graphical-session.target"];
|
# wantedBy = ["default.target"];
|
||||||
|
# after = ["graphical-session.target"];
|
||||||
|
|
||||||
path = [pkgs.gnome-monitor-config pkgs.usbutils pkgs.inotify-tools];
|
# path = [pkgs.gnome-monitor-config pkgs.usbutils pkgs.inotify-tools];
|
||||||
serviceConfig = {
|
# serviceConfig = {
|
||||||
preStart = "${patchedDuoScript} normal";
|
# preStart = "${patchedDuoScript} normal";
|
||||||
ExecStart = "${patchedDuoScript} watch-displays";
|
# ExecStart = "${patchedDuoScript} watch-displays";
|
||||||
Restart = "always";
|
# Restart = "always";
|
||||||
RestartSec = 5;
|
# RestartSec = 5;
|
||||||
};
|
# };
|
||||||
};
|
# };
|
||||||
|
|
||||||
systemd.user.services.watchRotation = {
|
# DISABLED: Old rotation script - conflicts with niri
|
||||||
description = "rotate screens";
|
# systemd.user.services.watchRotation = {
|
||||||
wantedBy = ["default.target"];
|
# description = "rotate screens";
|
||||||
after = ["graphical-session.target"];
|
# wantedBy = ["default.target"];
|
||||||
path = [pkgs.gnome-monitor-config pkgs.iio-sensor-proxy];
|
# after = ["graphical-session.target"];
|
||||||
serviceConfig = {
|
# path = [pkgs.gnome-monitor-config pkgs.iio-sensor-proxy];
|
||||||
ExecStart = "${patchedDuoScript} watch-rotation";
|
# serviceConfig = {
|
||||||
Restart = "always";
|
# ExecStart = "${patchedDuoScript} watch-rotation";
|
||||||
RestartSec = 5;
|
# Restart = "always";
|
||||||
};
|
# RestartSec = 5;
|
||||||
};
|
# };
|
||||||
|
# };
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,27 +14,34 @@
|
|||||||
|
|
||||||
boot.initrd.availableKernelModules = ["xhci_pci" "thunderbolt" "vmd" "nvme" "usbhid"];
|
boot.initrd.availableKernelModules = ["xhci_pci" "thunderbolt" "vmd" "nvme" "usbhid"];
|
||||||
boot.initrd.kernelModules = [];
|
boot.initrd.kernelModules = [];
|
||||||
boot.kernelPackages = pkgs.linuxPackages_zen;
|
boot.kernelPackages = pkgs.linuxPackages_latest;
|
||||||
boot.kernelModules = ["kvm-intel" "evdi" "intel_vpu"];
|
boot.kernelModules = ["kvm-intel" "evdi" "intel_vpu"];
|
||||||
boot.kernelParams = [
|
boot.kernelParams = [
|
||||||
"i915.enable_guc=3"
|
"i915.enable_guc=3"
|
||||||
#"i915.enable_psr=0"
|
#"i915.enable_psr=0"
|
||||||
|
# Suppress rfkill/WLAN toggle events from asus-wmi
|
||||||
|
"asus_nb_wmi.wapf=4"
|
||||||
];
|
];
|
||||||
boot.kernelPatches = [
|
boot.kernelPatches = [
|
||||||
/*
|
# Both patches are malformed/outdated and don't apply to current kernel versions
|
||||||
{
|
# Using alternative approach with extraModprobeConfig below
|
||||||
name = "zenbook-asus-wmi";
|
|
||||||
patch = ./zenbook-asus-wmi.patch;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
{
|
|
||||||
name = "zenbook-duo-suppress-rfkill-on-kbd-connect";
|
|
||||||
patch = ./zenbook-duo-suppress-rfkill-on-kbd-connect.patch;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
];
|
];
|
||||||
|
|
||||||
|
# Suppress rfkill events from keyboard attach/detach
|
||||||
|
services.udev.extraRules = ''
|
||||||
|
# Zenbook Duo - suppress rfkill/airplane mode key events on keyboard connect/disconnect
|
||||||
|
SUBSYSTEM=="input", ATTRS{name}=="Asus WMI hotkeys", ENV{KEY_RFKILL}="0", ENV{KEY_WLAN}="0"
|
||||||
|
'';
|
||||||
|
|
||||||
|
# Hardware database override to disable rfkill key on ASUS WMI hotkeys
|
||||||
|
services.udev.extraHwdb = ''
|
||||||
|
evdev:name:Asus WMI hotkeys:dmi:*
|
||||||
|
KEYBOARD_KEY_88=unknown
|
||||||
|
KEYBOARD_KEY_5d=unknown
|
||||||
|
KEYBOARD_KEY_5e=unknown
|
||||||
|
KEYBOARD_KEY_5f=unknown
|
||||||
|
'';
|
||||||
|
|
||||||
# Enables DHCP on each ethernet and wireless interface. In case of scripted networking
|
# Enables DHCP on each ethernet and wireless interface. In case of scripted networking
|
||||||
# (the default) this is the recommended approach. When using systemd-networkd it's
|
# (the default) this is the recommended approach. When using systemd-networkd it's
|
||||||
# still possible to use this option, but it's recommended to use it in conjunction
|
# still possible to use this option, but it's recommended to use it in conjunction
|
||||||
|
|||||||
Reference in New Issue
Block a user