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 ae597c1..3bebcde 100644 --- a/flake.lock +++ b/flake.lock @@ -279,6 +279,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": 1739042449, + "narHash": "sha256-9zLFUpEebwhjCgtznsI61gTzefI3+fuXATHUOFzJi5w=", + "owner": "sodiboo", + "repo": "niri-flake", + "rev": "98e3666a9dc4143cbf93d957a15d749b5acef046", + "type": "github" + }, + "original": { + "owner": "sodiboo", + "repo": "niri-flake", + "type": "github" + } + }, + "niri-stable": { + "flake": false, + "locked": { + "lastModified": 1736614405, + "narHash": "sha256-AJ1rlgNOPb3/+DbS5hkhm21t6Oz8IgqLllwmZt0lyzk=", + "owner": "YaLTeR", + "repo": "niri", + "rev": "e05bc269e678ecf828b96ae79c991c13b00b38a5", + "type": "github" + }, + "original": { + "owner": "YaLTeR", + "ref": "v25.01", + "repo": "niri", + "type": "github" + } + }, "nixpkgs": { "locked": { "lastModified": 1738843498, @@ -348,6 +392,7 @@ "flake-parts": "flake-parts", "home-manager": "home-manager", "lix-module": "lix-module", + "niri": "niri", "nixpkgs": "nixpkgs", "nixvim": "nixvim", "stylix": "stylix", @@ -485,6 +530,23 @@ "repo": "treefmt-nix", "type": "github" } + }, + "xwayland-satellite-stable": { + "flake": false, + "locked": { + "lastModified": 1730166465, + "narHash": "sha256-nq7bouXQXaaPPo/E+Jbq+wNHnatD4dY8OxSrRqzvy6s=", + "owner": "Supreeeme", + "repo": "xwayland-satellite", + "rev": "a713cf46cb7db84a0d1b57c3a397c610cad3cf98", + "type": "github" + }, + "original": { + "owner": "Supreeeme", + "ref": "v0.5", + "repo": "xwayland-satellite", + "type": "github" + } } }, "root": "root", diff --git a/flake.nix b/flake.nix index 2e99a7b..8dd3343 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 bd81732..e6d5abe 100644 --- a/home/gui/default.nix +++ b/home/gui/default.nix @@ -146,13 +146,55 @@ 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; + 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); + in + with config.lib.niri.actions; + { + # Open Terminal + "${mod}+Return".action.spawn = config.jhome.gui.terminalCommand; + # Open menu + "${mod}+D".action = + spawn "${lib.getExe pkgs.fuzzel}" "--terminal" + "${builtins.concatStringSep " " terminalCommand}"; + # Close Window + "${mod}+Q".action = close-window; + # Fullscreen + "${mod}+F".action = fullscreen-window; + # Hotkey help menu + "${mod}+Shift+/".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; + }; + # 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 993ae6c..4265faa 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 @@ -45,7 +38,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 4334c16..45bcd7c 100644 --- a/home/options.nix +++ b/home/options.nix @@ -136,33 +136,58 @@ let }; }; - 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); + }; + 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" + ]; + }; + 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 b1ae6b1..7efa6d5 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..01903f4 100644 --- a/system/options.nix +++ b/system/options.nix @@ -37,7 +37,7 @@ let options.autoStart = mkDisableOption "autostarting ydotool at login"; }; }; - sway = mkDisableOption "sway"; + windowManager = mkDisableOption "window manager"; }; styling.options = {