From d7de39220111cb4cc9f9cfb9e84a9fc42712a259 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jalil=20David=20Salam=C3=A9=20Messina?= Date: Sun, 9 Feb 2025 19:35:03 +0100 Subject: [PATCH] wip: switch to niri [skip-ci] Looks cooler c: --- flake-modules/nixos-modules.nix | 1 + flake.lock | 62 ++++++++++++++++++ flake.nix | 9 +++ home/gui/default.nix | 60 +++++++++++++++-- home/gui/sway-config.nix | 12 +--- home/options.nix | 113 ++++++++++++++++++-------------- system/gui/default.nix | 11 +--- system/options.nix | 15 ++++- 8 files changed, 209 insertions(+), 74 deletions(-) diff --git a/flake-modules/nixos-modules.nix b/flake-modules/nixos-modules.nix index 1422669..70fb0fb 100644 --- a/flake-modules/nixos-modules.nix +++ b/flake-modules/nixos-modules.nix @@ -16,6 +16,7 @@ nixosModule = { imports = [ (import ../system { inherit (inputs) stylix; }) + inputs.niri.nixosModules.niri inputs.home-manager.nixosModules.home-manager ] ++ lib.optional (inputs.lix-module != null) inputs.lix-module.nixosModules.default; home-manager = { diff --git a/flake.lock b/flake.lock index 8e0795c..5f95dd5 100644 --- a/flake.lock +++ b/flake.lock @@ -275,6 +275,50 @@ "url": "https://git.lix.systems/lix-project/nixos-module/archive/2.92.0.tar.gz" } }, + "niri": { + "inputs": { + "niri-stable": "niri-stable", + "niri-unstable": [], + "nixpkgs": [ + "nixpkgs" + ], + "nixpkgs-stable": [ + "nixpkgs" + ], + "xwayland-satellite-stable": "xwayland-satellite-stable", + "xwayland-satellite-unstable": [] + }, + "locked": { + "lastModified": 1741686876, + "narHash": "sha256-Kt37Zm9YcQoe/aRVbPFydZcfwIrEAg/U+iz3FcxsOZs=", + "owner": "sodiboo", + "repo": "niri-flake", + "rev": "fa230971ab63885ba5666588a7b78f75f73d5a85", + "type": "github" + }, + "original": { + "owner": "sodiboo", + "repo": "niri-flake", + "type": "github" + } + }, + "niri-stable": { + "flake": false, + "locked": { + "lastModified": 1740117926, + "narHash": "sha256-mTTHA0RAaQcdYe+9A3Jx77cmmyLFHmRoZdd8RpWa+m8=", + "owner": "YaLTeR", + "repo": "niri", + "rev": "b94a5db8790339cf9134873d8b490be69e02ac71", + "type": "github" + }, + "original": { + "owner": "YaLTeR", + "ref": "v25.02", + "repo": "niri", + "type": "github" + } + }, "nixpkgs": { "locked": { "lastModified": 1741445498, @@ -334,6 +378,7 @@ "flake-parts": "flake-parts", "home-manager": "home-manager", "lix-module": "lix-module", + "niri": "niri", "nixpkgs": "nixpkgs", "nixvim": "nixvim", "stylix": "stylix", @@ -471,6 +516,23 @@ "repo": "treefmt-nix", "type": "github" } + }, + "xwayland-satellite-stable": { + "flake": false, + "locked": { + "lastModified": 1739246919, + "narHash": "sha256-/hBM43/Gd0/tW+egrhlWgOIISeJxEs2uAOIYVpfDKeU=", + "owner": "Supreeeme", + "repo": "xwayland-satellite", + "rev": "44590a416d4a3e8220e19e29e0b6efe64a80315d", + "type": "github" + }, + "original": { + "owner": "Supreeeme", + "ref": "v0.5.1", + "repo": "xwayland-satellite", + "type": "github" + } } }, "root": "root", diff --git a/flake.nix b/flake.nix index 8c9a20b..1ad8772 100644 --- a/flake.nix +++ b/flake.nix @@ -23,6 +23,15 @@ url = "github:nix-community/home-manager/release-24.11"; inputs.nixpkgs.follows = "nixpkgs"; }; + niri = { + url = "github:sodiboo/niri-flake"; + inputs = { + nixpkgs.follows = "nixpkgs"; + nixpkgs-stable.follows = "nixpkgs"; + niri-unstable.follows = ""; + xwayland-satellite-unstable.follows = ""; + }; + }; stylix = { url = "github:danth/stylix/release-24.11"; inputs = { diff --git a/home/gui/default.nix b/home/gui/default.nix index 10948b2..07aa7d6 100644 --- a/home/gui/default.nix +++ b/home/gui/default.nix @@ -158,13 +158,59 @@ in }; # Window Manager - wayland.windowManager.sway = { - inherit (cfg.sway) enable; - package = swayPkg; # no sway package if it comes from the OS - config = import ./sway-config.nix { inherit config pkgs; }; - systemd = { - enable = true; - xdgAutostart = true; + programs.niri = { + package = pkgs.niri; # use nixpkgs' package instead of the flake's + settings = { + binds = + let + # Modifier key + mod = "Mod"; + # Available workspaces (1..=9) + workspaces = lib.range 1 9; + # Run function for each workspace + perWorkspace = f: lib.mergeAttrsList (builtins.map f workspaces); + # alias for concatStringsSep + joinWith = lib.strings.concatStringsSep; + in + with config.lib.niri.actions; + { + # Open Terminal + "${mod}+Return".action.spawn = + if config.jhome.gui.terminal == "alacritty" then "alacritty" else config.jhome.gui.terminalCommand; + # Open menu + "${mod}+D".action = + spawn "${lib.getExe pkgs.fuzzel}" "--terminal" + "${joinWith " " config.jhome.gui.terminalCommand}"; + # Close Window + "${mod}+Q".action = close-window; + # Fullscreen + "${mod}+F".action = fullscreen-window; + # Hotkey help menu + "${mod}+Shift+Slash".action = show-hotkey-overlay; + # Media Keys + "XF86AudioRaiseVolume" = { + action = spawn "${pkgs.avizo}/bin/volumectl" "up"; + allow-when-locked = true; + }; + "XF86AudioLowerVolume" = { + action = spawn "${pkgs.avizo}/bin/volumectl" "down"; + allow-when-locked = true; + }; + "XF86AudioMute" = { + action = spawn "${pkgs.avizo}/bin/volumectl" "toggle-mute"; + allow-when-locked = true; + }; + # FIXME: swaylock is missing so this doesn't work anyways + # Lock screen + # "XF86ScreenSaver".action = spawn "swaylock" "--image" "${cfg.background}"; + # Screen brightness + "XF86MonBrightnessUp".action = spawn "${pkgs.avizo}/bin/lightctl" "up"; + "XF86MonBrightnessDown".action = spawn "${pkgs.avizo}/bin/lightctl" "down"; + } + // perWorkspace (workspace: { + # Focus workspace N + "${mod}+${builtins.toString workspace}".action = focus-workspace workspace; + }); }; }; diff --git a/home/gui/sway-config.nix b/home/gui/sway-config.nix index e20e8aa..f499f71 100644 --- a/home/gui/sway-config.nix +++ b/home/gui/sway-config.nix @@ -2,14 +2,7 @@ let cfg = config.jhome.gui.sway; modifier = "Mod4"; - inherit (config.jhome.gui) terminal; - termCmd = - if terminal == "wezterm" then - "wezterm start" - else if terminal == "alacritty" then - "alacritty -e" - else - builtins.abort "no command configured for ${terminal}"; + termCmd = builtins.concatStringsSep " " config.jhome.gui.terminalCommand; menu = "${pkgs.fuzzel}/bin/fuzzel --terminal '${termCmd}'"; # currently, there is some friction between sway and gtk: # https://github.com/swaywm/sway/wiki/GTK-3-settings-on-Wayland @@ -46,7 +39,8 @@ let }; in { - inherit modifier terminal menu; + inherit (config.jhome.gui) terminal; + inherit modifier menu; keybindings = import ./keybindings.nix { inherit config pkgs; }; # Appearance bars = [ ]; # Waybar is started as a systemd service diff --git a/home/options.nix b/home/options.nix index 2f65337..24b09cc 100644 --- a/home/options.nix +++ b/home/options.nix @@ -78,13 +78,23 @@ let example = "/sys/class/hwmon/hwmon2/temp1_input"; }; - sway.options = { - enable = lib.mkEnableOption "sway" // { + windowManager.options = { + enable = lib.mkEnableOption "window manager" // { default = fromConfig [ "gui" - "sway" + "windowManager" + "enable" ] true; }; + windowManager = lib.mkOption { + description = "Which window manager to enable"; + type = types.enum [ "niri" ]; + default = fromConfig [ + "gui" + "windowManager" + "windowManager" + ] "niri"; + }; background = lib.mkOption { description = "The wallpaper to use."; type = types.path; @@ -114,55 +124,60 @@ let default = true; example = false; }; - exec = lib.mkOption { - description = "Run commands when starting sway."; - default = { }; - type = types.submodule { - options = { - once = lib.mkOption { - description = "Programs to start only once (`exec`)."; - type = types.listOf types.str; - default = [ ]; - example = [ "signal-desktop --start-in-tray" ]; - }; - always = lib.mkOption { - description = "Programs to start whenever the config is sourced (`exec_always`)."; - type = types.listOf types.str; - default = [ ]; - example = [ "signal-desktop --start-in-tray" ]; - }; - }; - }; - }; }; - gui.options = { - enable = lib.mkEnableOption "GUI applications" // { - default = fromConfig [ - "gui" - "enable" - ] false; + gui.options = + let + cfg = attrs.config.jhome.gui; + in + { + enable = lib.mkEnableOption "GUI applications" // { + default = fromConfig [ + "gui" + "enable" + ] false; + }; + tempInfo = lib.mkOption { + description = "Temperature info to display in the statusbar."; + default = null; + type = types.nullOr (types.submodule tempInfo); + }; + windowManager = lib.mkOption { + description = "Window manager configuration."; + default = { }; + type = types.submodule windowManager; + }; + terminal = lib.mkOption { + description = "The terminal emulator to use."; + default = "alacritty"; + example = "wezterm"; + type = types.enum [ + "wezterm" + "alacritty" + ]; + }; + terminalCommand = lib.mkOption { + description = "The command to run in order to start the terminal."; + default = + if cfg.terminal == "wezterm" then + [ + "wezterm" + "start" + ] + else if cfg.terminal == "alacritty" then + [ + "alacritty" + "-e" + ] + else + builtins.abort "no command configured for ${cfg.terminal}"; + example = [ + "wezterm" + "start" + ]; + type = types.listOf types.str; + }; }; - tempInfo = lib.mkOption { - description = "Temperature info to display in the statusbar."; - default = null; - type = types.nullOr (types.submodule tempInfo); - }; - sway = lib.mkOption { - description = "Sway window manager configuration."; - default = { }; - type = types.submodule sway; - }; - terminal = lib.mkOption { - description = "The terminal emulator to use."; - default = "alacritty"; - example = "wezterm"; - type = types.enum [ - "wezterm" - "alacritty" - ]; - }; - }; in { options.jhome = lib.mkOption { diff --git a/system/gui/default.nix b/system/gui/default.nix index 52d17b8..6be652f 100644 --- a/system/gui/default.nix +++ b/system/gui/default.nix @@ -45,14 +45,9 @@ in fonts.fontDir.enable = true; programs = { dconf.enable = true; - sway = { - enable = cfg.sway; - # No extra packages (by default it adds foot, dmenu, and other stuff) - extraPackages = [ ]; - wrapperFeatures = { - base = true; - gtk = true; - }; + niri = { + enable = cfg.windowManager; + package = pkgs.niri; # use nixpkgs' package instead of the flake's }; }; security = { diff --git a/system/options.nix b/system/options.nix index 9e76f1c..51ac162 100644 --- a/system/options.nix +++ b/system/options.nix @@ -37,7 +37,20 @@ let options.autoStart = mkDisableOption "autostarting ydotool at login"; }; }; - sway = mkDisableOption "sway"; + windowManager = lib.mkOption { + description = "Window manager configuration"; + default = { }; + type = types.submodule { + options = { + enable = mkDisableOption "window manager"; + windowManager = lib.mkOption { + description = "Which window manager to enable"; + type = types.enum [ "niri" ]; + default = "niri"; + }; + }; + }; + }; }; styling.options = {