# Hyprland desktop, both halves of one feature: # NixOS UWSM-managed compositor, portals, keyring and the small # services a desktop needs. # home-manager the user configuration. Hyprland reads Lua: the real config # is in the .lua files next to this file; Nix only passes in the # values that come from elsewhere (`require("nixvars")`). # The NixOS half adds the home-manager half to the owner, so a host imports # `nixos.hyprland` once. The display manager (sddm), Noctalia, audio and fonts # are separate aspects. { config, ... }: let inherit (config.meta) owner; hmHyprland = config.flake.modules.homeManager.hyprland; in { flake.modules.nixos.hyprland = { pkgs, ... }: { home-manager.users.${owner.name}.imports = [ hmHyprland ]; # package/portalPackage stay default: the overlay swaps in the flake builds. programs.hyprland = { enable = true; withUWSM = true; xwayland.enable = true; }; xdg.portal.extraPortals = [ pkgs.xdg-desktop-portal-gtk pkgs.xdg-desktop-portal-hyprland ]; security.polkit.enable = true; services.gnome.gnome-keyring.enable = true; programs.dconf.enable = true; # Removable drives and trash/mounts in the file manager. services.udisks2.enable = true; services.gvfs.enable = true; hardware.bluetooth = { enable = true; powerOnBoot = true; }; environment.systemPackages = with pkgs; [ wl-clipboard cliphist grim slurp brightnessctl playerctl pavucontrol kdePackages.dolphin kdePackages.dolphin-plugins hyprpicker ]; }; flake.modules.homeManager.hyprland = { config, lib, pkgs, osConfig, ... }: let cursor = config.home.pointerCursor; # Exposed to the Lua files as `require("nixvars")`. Keyboard layouts come # from the NixOS configuration (services.xserver.xkb, set by the host), # the cursor from home-manager (set by Stylix, theme/stylix.nix). nixVars = { kbLayout = osConfig.services.xserver.xkb.layout; kbOptions = osConfig.services.xserver.xkb.options; terminal = "wezterm"; fileManager = "dolphin"; # Binds start apps through this, so each runs as its own scope of the # session (app-graphical.slice) and is stopped before the compositor at # logout, instead of living inside Hyprland's unit. appLauncher = "${lib.getExe' osConfig.programs.uwsm.package "uwsm-app"} --"; cursorSize = if cursor.enable then cursor.size else 24; cursorTheme = if cursor.enable then cursor.name else ""; }; # The only place these are defined. UWSM sources uwsm/env- # (lowercased XDG_CURRENT_DESKTOP) before the compositor starts and puts # the result into the systemd and D-Bus activation environments, so every # app of the Hyprland session sees them, and nothing outside it does. waylandEnv = { # Electron/Chromium apps use native Wayland. NIXOS_OZONE_WL = "1"; ELECTRON_OZONE_PLATFORM_HINT = "auto"; GDK_BACKEND = "wayland,x11,*"; QT_QPA_PLATFORM = "wayland;xcb"; # Falls back to X11 when an SDL app has no Wayland support, but some # older SDL games still break with it (set SDL_VIDEODRIVER=x11 for those). SDL_VIDEODRIVER = "wayland,x11"; CLUTTER_BACKEND = "wayland"; }; in { wayland.windowManager.hyprland = { enable = true; configType = "lua"; # The NixOS half (programs.hyprland) installs the compositor and the # portal, built from the flake overlay. Installing them again here would # put a second copy in the user profile. package = null; portalPackage = null; # UWSM owns the session and graphical-session.target; HM's own # hyprland-session.target and dbus import would only duplicate that. systemd.enable = false; xwayland.enable = true; # Loaded in name order; `nixvars` is a helper module, not loaded on its # own. Stylix's colours are rendered after these files (hl.config in # hyprland.lua), so they override the colours in settings.lua. extraLuaFiles = { nixvars = { content = "return ${lib.generators.toLua { } nixVars}\n"; autoLoad = false; }; "10-settings" = ./settings.lua; "20-binds" = ./binds.lua; "30-rules" = ./rules.lua; }; }; xdg.configFile."uwsm/env-hyprland".text = lib.concatLines ( lib.mapAttrsToList (name: value: "export ${name}=${lib.escapeShellArg value}") waylandEnv ); # Home-manager's session variables (hm-session-vars.sh) reach shells only. # The compositor, and so the binds, and the user services (Noctalia, and # so the launcher) inherit the systemd user manager's environment instead, # which systemd.user.sessionVariables (environment.d) feeds. Of the # variables home-manager sets, the editor is the one programs outside a # shell look for. Taken from home.sessionVariables, so the neovim aspect # stays the only place that defines them (and nothing breaks when it is # not imported). They apply from the next login. systemd.user.sessionVariables = lib.filterAttrs ( name: _: builtins.elem name [ "EDITOR" "VISUAL" ] ) config.home.sessionVariables; # Tools the binds call (screenshots, file manager). home.packages = with pkgs; [ grim slurp wl-clipboard kdePackages.dolphin kdePackages.dolphin-plugins ]; }; }