From f6722f498675d911f8c2483aef06e527f97c4c9a Mon Sep 17 00:00:00 2001 From: cnst Date: Fri, 12 Sep 2025 20:47:08 +0200 Subject: [PATCH] feat(niri): giving niri a test drive --- flake.lock | 158 ++++++++++++++++-- flake.nix | 2 + hosts/kima/modules.nix | 7 +- modules/default.nix | 1 + modules/home/programs/fuzzel/default.nix | 2 +- modules/home/programs/ghostty/default.nix | 2 +- modules/home/programs/helix/default.nix | 4 +- modules/home/programs/hyprlock/default.nix | 6 +- .../home/programs/waybar/config/config.jsonc | 47 ++++-- modules/home/services/hypridle/default.nix | 9 +- modules/home/services/hyprpaper/default.nix | 9 +- modules/nixos/programs/fish/default.nix | 9 +- modules/nixos/programs/fish/up-or-search.fish | 22 --- modules/nixos/programs/niri/default.nix | 24 +++ modules/nixos/services/greetd/default.nix | 62 +++++-- nix/substituters/default.nix | 2 + scripts/bin/spawn-or-focus.sh | 51 ++++++ scripts/default.nix | 10 ++ users/cnst/modules/kimamod.nix | 9 - 19 files changed, 329 insertions(+), 107 deletions(-) delete mode 100644 modules/nixos/programs/fish/up-or-search.fish create mode 100644 modules/nixos/programs/niri/default.nix create mode 100755 scripts/bin/spawn-or-focus.sh diff --git a/flake.lock b/flake.lock index 60a19b60..0b211fd9 100644 --- a/flake.lock +++ b/flake.lock @@ -1135,6 +1135,62 @@ "type": "github" } }, + "niri": { + "inputs": { + "niri-stable": "niri-stable", + "niri-unstable": "niri-unstable", + "nixpkgs": "nixpkgs_8", + "nixpkgs-stable": "nixpkgs-stable", + "xwayland-satellite-stable": "xwayland-satellite-stable", + "xwayland-satellite-unstable": "xwayland-satellite-unstable" + }, + "locked": { + "lastModified": 1757698528, + "narHash": "sha256-vXZaxm2LfFrVyuUOKkyWpwR0K2WB7k2oo94HN1o4910=", + "owner": "sodiboo", + "repo": "niri-flake", + "rev": "2418edea929640fb5f856bc0a25fb91f54dfc229", + "type": "github" + }, + "original": { + "owner": "sodiboo", + "repo": "niri-flake", + "type": "github" + } + }, + "niri-stable": { + "flake": false, + "locked": { + "lastModified": 1756556321, + "narHash": "sha256-RLD89dfjN0RVO86C/Mot0T7aduCygPGaYbog566F0Qo=", + "owner": "YaLTeR", + "repo": "niri", + "rev": "01be0e65f4eb91a9cd624ac0b76aaeab765c7294", + "type": "github" + }, + "original": { + "owner": "YaLTeR", + "ref": "v25.08", + "repo": "niri", + "type": "github" + } + }, + "niri-unstable": { + "flake": false, + "locked": { + "lastModified": 1757656821, + "narHash": "sha256-MDaLusQZflxngGMU41g6cqabM7KE8I55UazzAZsjNN0=", + "owner": "YaLTeR", + "repo": "niri", + "rev": "b7909dbf61c7c1511b9a51ef46e1d503d5ba3d05", + "type": "github" + }, + "original": { + "owner": "YaLTeR", + "repo": "niri", + "type": "github" + } + }, "nix-gaming": { "inputs": { "flake-parts": [ @@ -1212,6 +1268,38 @@ "type": "github" } }, + "nixpkgs-stable": { + "locked": { + "lastModified": 1757545623, + "narHash": "sha256-mCxPABZ6jRjUQx3bPP4vjA68ETbPLNz9V2pk9tO7pRQ=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "8cd5ce828d5d1d16feff37340171a98fc3bf6526", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-25.05", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_10": { + "locked": { + "lastModified": 1756696532, + "narHash": "sha256-6FWagzm0b7I/IGigOv9pr6LL7NQ86mextfE8g8Q6HBg=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "58dcbf1ec551914c3756c267b8b9c8c86baa1b2f", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, "nixpkgs_2": { "locked": { "lastModified": 1755186698, @@ -1309,6 +1397,22 @@ } }, "nixpkgs_8": { + "locked": { + "lastModified": 1757487488, + "narHash": "sha256-zwE/e7CuPJUWKdvvTCB7iunV4E/+G0lKfv4kk/5Izdg=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "ab0f3607a6c7486ea22229b92ed2d355f1482ee0", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_9": { "locked": { "lastModified": 1756787288, "narHash": "sha256-rw/PHa1cqiePdBxhF66V7R+WAP8WekQ0mCDG4CFqT8Y=", @@ -1324,28 +1428,12 @@ "type": "github" } }, - "nixpkgs_9": { - "locked": { - "lastModified": 1756696532, - "narHash": "sha256-6FWagzm0b7I/IGigOv9pr6LL7NQ86mextfE8g8Q6HBg=", - "owner": "nixos", - "repo": "nixpkgs", - "rev": "58dcbf1ec551914c3756c267b8b9c8c86baa1b2f", - "type": "github" - }, - "original": { - "owner": "nixos", - "ref": "nixpkgs-unstable", - "repo": "nixpkgs", - "type": "github" - } - }, "nvf": { "inputs": { "flake-compat": "flake-compat_4", "flake-parts": "flake-parts_5", "mnw": "mnw", - "nixpkgs": "nixpkgs_9", + "nixpkgs": "nixpkgs_10", "systems": "systems_4" }, "locked": { @@ -1430,8 +1518,9 @@ "hyprlock": "hyprlock", "hyprpaper": "hyprpaper", "lanzaboote": "lanzaboote", + "niri": "niri", "nix-gaming": "nix-gaming", - "nixpkgs": "nixpkgs_8", + "nixpkgs": "nixpkgs_9", "nvf": "nvf", "systems": "systems_5", "treefmt-nix": "treefmt-nix", @@ -1692,6 +1781,39 @@ "type": "github" } }, + "xwayland-satellite-stable": { + "flake": false, + "locked": { + "lastModified": 1755491097, + "narHash": "sha256-m+9tUfsmBeF2Gn4HWa6vSITZ4Gz1eA1F5Kh62B0N4oE=", + "owner": "Supreeeme", + "repo": "xwayland-satellite", + "rev": "388d291e82ffbc73be18169d39470f340707edaa", + "type": "github" + }, + "original": { + "owner": "Supreeeme", + "ref": "v0.7", + "repo": "xwayland-satellite", + "type": "github" + } + }, + "xwayland-satellite-unstable": { + "flake": false, + "locked": { + "lastModified": 1757179758, + "narHash": "sha256-TIvyWzRt1miQj6Cf5Wy8Qz43XIZX7c4vTVwRLAT5S4Y=", + "owner": "Supreeeme", + "repo": "xwayland-satellite", + "rev": "970728d0d9d1eada342bb8860af214b601139e58", + "type": "github" + }, + "original": { + "owner": "Supreeeme", + "repo": "xwayland-satellite", + "type": "github" + } + }, "zen-browser": { "inputs": { "nixpkgs": [ diff --git a/flake.nix b/flake.nix index 4de035eb..dd9a3ab6 100644 --- a/flake.nix +++ b/flake.nix @@ -135,6 +135,8 @@ inputs.nixpkgs.follows = "nixpkgs"; }; + niri.url = "github:sodiboo/niri-flake"; + # Custom tuirun = { url = "git+https://git.sr.ht/~canasta/tuirun"; diff --git a/hosts/kima/modules.nix b/hosts/kima/modules.nix index 92f3b5c6..578fed24 100644 --- a/hosts/kima/modules.nix +++ b/hosts/kima/modules.nix @@ -74,8 +74,8 @@ enable = false; }; hyprland = { - enable = true; - withUWSM = true; + enable = false; + withUWSM = false; }; inkscape = { enable = false; @@ -89,6 +89,9 @@ microfetch = { enable = true; }; + niri = { + enable = true; + }; pkgs = { enable = true; desktop = { diff --git a/modules/default.nix b/modules/default.nix index a01ffd01..5a2af9a6 100644 --- a/modules/default.nix +++ b/modules/default.nix @@ -76,6 +76,7 @@ ./nixos/programs/lact ./nixos/programs/lutris ./nixos/programs/microfetch + ./nixos/programs/niri ./nixos/programs/pkgs ./nixos/programs/mysql-workbench ./nixos/programs/nh diff --git a/modules/home/programs/fuzzel/default.nix b/modules/home/programs/fuzzel/default.nix index b555d298..81b1bd90 100644 --- a/modules/home/programs/fuzzel/default.nix +++ b/modules/home/programs/fuzzel/default.nix @@ -22,7 +22,7 @@ in main = { layer = "overlay"; font = "Input Sans Narrow Light:size=12"; - launch-prefix = "uwsm app --"; + # launch-prefix = "uwsm app --"; lines = "8"; }; colors = { diff --git a/modules/home/programs/ghostty/default.nix b/modules/home/programs/ghostty/default.nix index 2dbd2f9f..365b8115 100644 --- a/modules/home/programs/ghostty/default.nix +++ b/modules/home/programs/ghostty/default.nix @@ -28,7 +28,7 @@ in enableFishIntegration = config.programs.fish.enable; enableZshIntegration = config.programs.zsh.enable; settings = { - theme = "GruvboxDark"; + theme = "GruvboxDarkHard"; focus-follows-mouse = true; resize-overlay = "never"; background-opacity = 0.95; diff --git a/modules/home/programs/helix/default.nix b/modules/home/programs/helix/default.nix index 7b0e58fc..f66053e9 100644 --- a/modules/home/programs/helix/default.nix +++ b/modules/home/programs/helix/default.nix @@ -12,7 +12,7 @@ in { imports = [ ./languages.nix - ./gruvbox.nix + # ./gruvbox.nix ]; options = { @@ -26,7 +26,7 @@ in package = inputs.helix-flake.packages.${pkgs.system}.default; settings = { - theme = "gruvbox_custom"; + theme = "gruvbox_dark_hard"; editor = { color-modes = true; scrolloff = 0; diff --git a/modules/home/programs/hyprlock/default.nix b/modules/home/programs/hyprlock/default.nix index 973af82e..10499243 100644 --- a/modules/home/programs/hyprlock/default.nix +++ b/modules/home/programs/hyprlock/default.nix @@ -1,7 +1,6 @@ { inputs, pkgs, - config, lib, osConfig, cLib, @@ -9,7 +8,7 @@ }: let inherit (lib) mkIf mkEnableOption; - cfg = config.home.programs.hyprlock; + cfg = osConfig.nixos.programs.hyprland; hyprlockFlake = inputs.hyprlock.packages.${pkgs.system}.hyprlock; # hyprlockPkg = pkgs.hyprlock; @@ -18,9 +17,6 @@ let inherit (cLib.theme.bgs) resolve; in { - options = { - home.programs.hyprlock.enable = mkEnableOption "Enables hyprlock"; - }; config = mkIf cfg.enable { programs.hyprlock = { enable = true; diff --git a/modules/home/programs/waybar/config/config.jsonc b/modules/home/programs/waybar/config/config.jsonc index 2d71f5d1..ad7e9c95 100644 --- a/modules/home/programs/waybar/config/config.jsonc +++ b/modules/home/programs/waybar/config/config.jsonc @@ -1,5 +1,22 @@ [ { + "modules-left": [ + "group/system" + ], + "modules-center": [ + "niri/workspaces" + ], + "modules-right": [ + "custom/progress", + "custom/systemd", + "group/tray", + "pulseaudio", + "backlight", + "battery", + "date", + "clock", + "custom/dunst" + ], "backlight": { "format": "{icon} {percent}%", "format-icons": [ @@ -128,6 +145,19 @@ "*": 3 } }, + "niri/workspaces": { + "format": "{icon}", + "format-icons": { + // Named workspaces + // (you need to configure them in niri) + "browser": "", + "discord": "", + "chat": "", + // Icons by state + "active": "", + "default": "" + } + }, "memory": { "format": " {}%", "states": { @@ -135,23 +165,6 @@ "warning": 70 } }, - "modules-center": [ - "hyprland/workspaces" - ], - "modules-left": [ - "group/system" - ], - "modules-right": [ - "custom/progress", - "custom/systemd", - "group/tray", - "pulseaudio", - "backlight", - "battery", - "date", - "clock", - "custom/dunst" - ], "network": { "format-disconnected": " ", "format-ethernet": " {ifname}", diff --git a/modules/home/services/hypridle/default.nix b/modules/home/services/hypridle/default.nix index a6644b90..12637c79 100644 --- a/modules/home/services/hypridle/default.nix +++ b/modules/home/services/hypridle/default.nix @@ -1,21 +1,18 @@ { - config, + osConfig, lib, pkgs, inputs, ... }: let - inherit (lib) mkIf mkEnableOption; - cfg = config.home.services.hypridle; + inherit (lib) mkIf; + cfg = osConfig.nixos.programs.hyprland; hypridleFlake = inputs.hypridle.packages.${pkgs.system}.hypridle; # hypridlePkg = pkgs.hypridle; in { - options = { - home.services.hypridle.enable = mkEnableOption "Enables hypridle"; - }; config = mkIf cfg.enable { services.hypridle = { enable = true; diff --git a/modules/home/services/hyprpaper/default.nix b/modules/home/services/hyprpaper/default.nix index b20cfa84..dc280850 100644 --- a/modules/home/services/hyprpaper/default.nix +++ b/modules/home/services/hyprpaper/default.nix @@ -1,5 +1,4 @@ { - config, lib, pkgs, inputs, @@ -8,9 +7,9 @@ ... }: let - inherit (lib) mkIf mkEnableOption; + inherit (lib) mkIf; - cfg = config.home.services.hyprpaper; + cfg = osConfig.nixos.programs.hyprland; hyprpaperFlake = inputs.hyprpaper.packages.${pkgs.system}.default; bg = osConfig.settings.theme.background; bgs = cLib.theme.bgs; @@ -35,10 +34,6 @@ let ]; in { - options = { - home.services.hyprpaper.enable = mkEnableOption "Enable hyprpaper wallpaper service"; - }; - config = mkIf cfg.enable { services.hyprpaper = { enable = true; diff --git a/modules/nixos/programs/fish/default.nix b/modules/nixos/programs/fish/default.nix index b7840b40..9204f7df 100644 --- a/modules/nixos/programs/fish/default.nix +++ b/modules/nixos/programs/fish/default.nix @@ -20,7 +20,14 @@ in config = mkMerge [ (mkIf cfg.enable { - programs.fish.enable = true; + programs.fish = { + enable = true; + vendor = { + completions.enable = true; + config.enable = true; + functions.enable = true; + }; + }; }) (mkIf cfg.homeless.enable { diff --git a/modules/nixos/programs/fish/up-or-search.fish b/modules/nixos/programs/fish/up-or-search.fish deleted file mode 100644 index 5ef444c8..00000000 --- a/modules/nixos/programs/fish/up-or-search.fish +++ /dev/null @@ -1,22 +0,0 @@ -# Taken from Misterio77 https://github.com/Misterio77/nix-config/blob/main/home/gabriel/features/cli/fish/up-or-search.fish -# Merge history upon doing up-or-search -# This lets multiple fish instances share history -if commandline --search-mode - commandline -f history-search-backward - return -end -if commandline --paging-mode - commandline -f up-line - return -end - -set -l lineno (commandline -L) - -switch $lineno - case 1 - commandline -f history-search-backward - # Here we go - history merge - case '*' - commandline -f up-line -end diff --git a/modules/nixos/programs/niri/default.nix b/modules/nixos/programs/niri/default.nix new file mode 100644 index 00000000..41b37785 --- /dev/null +++ b/modules/nixos/programs/niri/default.nix @@ -0,0 +1,24 @@ +{ + config, + inputs, + lib, + pkgs, + ... +}: +let + inherit (lib) mkIf mkEnableOption; + cfg = config.nixos.programs.niri; +in +{ + options = { + nixos.programs.niri.enable = mkEnableOption "Enables niri"; + }; + config = mkIf cfg.enable { + nixpkgs.overlays = [ inputs.niri.overlays.niri ]; + systemd.user.services.niri-flake-polkit.enable = false; + programs.niri = { + enable = true; + package = pkgs.niri-unstable; + }; + }; +} diff --git a/modules/nixos/services/greetd/default.nix b/modules/nixos/services/greetd/default.nix index 129a0e6a..edb7c1cb 100644 --- a/modules/nixos/services/greetd/default.nix +++ b/modules/nixos/services/greetd/default.nix @@ -1,6 +1,7 @@ { config, lib, + pkgs, ... }: let @@ -9,8 +10,11 @@ let mkEnableOption mkOption types + mkMerge ; cfg = config.nixos.services.greetd; + hyprcfg = config.nixos.programs.hyprland; + niricfg = config.nixos.programs.niri; in { options = { @@ -28,21 +32,47 @@ in }; }; - config = mkIf cfg.enable { - services.greetd = - let - session = { - command = "${lib.getExe config.programs.uwsm.package} start hyprland-uwsm.desktop"; - user = cfg.user; + config = + let + usernames = builtins.attrNames config.home-manager.users; + username = builtins.head usernames; + in + mkMerge [ + (mkIf cfg.enable { services.greetd.enable = true; }) + + (mkIf hyprcfg.enable { + services.greetd = + let + session = { + command = "${lib.getExe config.programs.uwsm.package} start hyprland-uwsm.desktop"; + user = cfg.user; + }; + in + { + settings = { + terminal.vt = 1; + default_session = session; + initial_session = session; + }; + }; + }) + + (mkIf niricfg.enable { + services.greetd = { + enable = true; + settings = rec { + tuigreet_session = + let + session = "${pkgs.niri-unstable}/bin/niri-session"; + tuigreet = "${lib.getExe pkgs.tuigreet}"; + in + { + command = "${tuigreet} --time --remember --cmd ${session}"; + user = "greeter"; + }; + default_session = tuigreet_session; + }; }; - in - { - enable = true; - settings = { - terminal.vt = 1; - default_session = session; - initial_session = session; - }; - }; - }; + }) + ]; } diff --git a/nix/substituters/default.nix b/nix/substituters/default.nix index 06abce41..894b0534 100644 --- a/nix/substituters/default.nix +++ b/nix/substituters/default.nix @@ -9,6 +9,7 @@ "https://nix-gaming.cachix.org" "https://yazi.cachix.org" "https://chaotic-nyx.cachix.org" + "https://niri.cachix.org" ]; trusted-public-keys = [ @@ -18,6 +19,7 @@ "hyprland.cachix.org-1:a7pgxzMz7+chwVL3/pzj6jIBMioiJM7ypFP8PwtkuGc=" "nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs=" "nix-gaming.cachix.org-1:nbjlureqMbRAxR1gJ/f3hxemL9svXaZF/Ees8vCUUs4=" + "niri.cachix.org-1:Wv0OmO7PsuocRKzfDoJ3mulSl7Z6oezYhGhR+3W2964=" "yazi.cachix.org-1:Dcdz63NZKfvUCbDGngQDAZq6kOroIrFoyO064uvLh8k=" "chaotic-nyx.cachix.org-1:HfnXSw4pj95iI/n17rIDy40agHj12WfF+Gqk6SonIT8" ]; diff --git a/scripts/bin/spawn-or-focus.sh b/scripts/bin/spawn-or-focus.sh new file mode 100755 index 00000000..35e4117a --- /dev/null +++ b/scripts/bin/spawn-or-focus.sh @@ -0,0 +1,51 @@ +# Check if at least one argument is provided +if [ $# -lt 1 ]; then + notify-send -t 5000 "Usage: spawn-or-focus.sh [APP_CMD]" + exit 1 +fi + +APP_CLASS="$1" # Application's app_id (e.g. firefox) +APP_CMD="${2:-}" # Optional: Command to run the application + +# Get the ID of the currently focused window +FOCUSED_ID=$(niri msg -j focused-window | jq -r '.id') + +# Find windows matching the app class and read them into an array +readarray -t MATCHING_IDS < <( + niri msg -j windows | + jq -r --arg app_class "$APP_CLASS" ' + .[] + | select(.app_id | ascii_downcase | contains($app_class | ascii_downcase)) + | .id + ' +) + +# Launch the app and exit the script if the number of matching windows is zero +if [ ${#MATCHING_IDS[@]} -eq 0 ]; then + # Use the app class as the command if no app command is supplied + if [ -z "$APP_CMD" ]; then + APP_CMD="$APP_CLASS" + fi + "$APP_CMD" & + exit 0 +fi + +# Find the array index of the currently focused window +CURRENT_INDEX=-1 +for INDEX in "${!MATCHING_IDS[@]}"; do + if [ "${MATCHING_IDS[$INDEX]}" = "$FOCUSED_ID" ]; then + CURRENT_INDEX=$INDEX + break + fi +done + +# Cycle to the next matching array index if the currently focused ID was found +# in the array, otherwise set the target index to zero +if [ "$CURRENT_INDEX" -ge 0 ]; then + TARGET_INDEX=$(((CURRENT_INDEX + 1) % ${#MATCHING_IDS[@]})) +else + TARGET_INDEX=0 +fi + +# Switch focus to the target window stored in the array +niri msg action focus-window --id "${MATCHING_IDS[$TARGET_INDEX]}" diff --git a/scripts/default.nix b/scripts/default.nix index b56fe70b..e2e2acb4 100644 --- a/scripts/default.nix +++ b/scripts/default.nix @@ -14,6 +14,16 @@ in sessionPath = [ "${config.home.homeDirectory}/.local/bin" ]; file = { + ".local/bin/spawn-or-focus.sh" = { + source = getExe ( + pkgs.writeShellApplication { + name = "spawn-or-focus"; + runtimeInputs = with pkgs; [ niri ]; + text = readFile ./bin/spawn-or-focus.sh; + } + ); + }; + ".local/bin/pavucontrol-toggle.sh" = { source = getExe ( pkgs.writeShellApplication { diff --git a/users/cnst/modules/kimamod.nix b/users/cnst/modules/kimamod.nix index fbbc64a4..9f5a017c 100644 --- a/users/cnst/modules/kimamod.nix +++ b/users/cnst/modules/kimamod.nix @@ -44,9 +44,6 @@ helix = { enable = true; }; - hyprlock = { - enable = true; - }; jujutsu = { enable = false; }; @@ -128,12 +125,6 @@ gtk = { enable = true; }; - hypridle = { - enable = true; - }; - hyprpaper = { - enable = true; - }; mako = { enable = false; };