fork/home-manager
git clone https://git.julia.blue/fork/home-manager
09587fbb
master
1{ config , lib , pkgs , ...} : 2let 3 4cfg = config . wayland . windowManager . hyprland ; 5 6variables = builtins . concatStringsSep " " cfg . systemd . variables ; 7extraCommands = builtins . concatStringsSep " " 8( map ( f :"&& ${ f } " ) cfg . systemd . extraCommands ); 9systemdActivation = '' 10exec-once = ${ pkgs . dbus } /bin/dbus-update-activation-environment --systemd ${ variables } ${ extraCommands } 11'' ; 12 13in { 14meta . maintainers = [ lib . maintainers . fufexan ]; 15 16# A few option removals and renames to aid those migrating from the upstream 17# module. 18imports = [ 19( lib . mkRemovedOptionModule # \ 20[ "wayland" "windowManager" "hyprland" "disableAutoreload" ] 21"Autoreloading now always happens" ) 22 23( lib . mkRemovedOptionModule # \ 24[ "wayland" "windowManager" "hyprland" "recommendedEnvironment" ] 25"Recommended environment variables are now always set" ) 26 27( lib . mkRemovedOptionModule # \ 28[ "wayland" "windowManager" "hyprland" "xwayland" "hidpi" ] 29"HiDPI patches are deprecated. Refer to https://wiki.hyprland.org/Configuring/XWayland" ) 30 31( lib . mkRenamedOptionModule # \ 32[ "wayland" "windowManager" "hyprland" "nvidiaPatches" ] # \ 33[ "wayland" "windowManager" "hyprland" "enableNvidiaPatches" ]) 34 35( lib . mkRenamedOptionModule # \ 36[ "wayland" "windowManager" "hyprland" "systemdIntegration" ] # \ 37[ "wayland" "windowManager" "hyprland" "systemd" "enable" ]) 38]; 39 40options . wayland . windowManager . hyprland = { 41enable = lib . mkEnableOption "Hyprland wayland compositor" ; 42 43package = lib . mkPackageOption pkgs "hyprland" { }; 44 45finalPackage = lib . mkOption { 46type = lib . types . package ; 47readOnly = true ; 48default = cfg . package . override { 49enableXWayland = cfg . xwayland . enable ; 50enableNvidiaPatches = cfg . enableNvidiaPatches ; 51}; 52defaultText = lib . literalMD 53"`wayland.windowManager.hyprland.package` with applied configuration" ; 54description = '' 55The Hyprland package after applying configuration. 56'' ; 57}; 58 59plugins = lib . mkOption { 60type = with lib . types ; listOf ( either package path ); 61default = [ ]; 62description = '' 63List of Hyprland plugins to use. Can either be packages or 64absolute plugin paths. 65'' ; 66}; 67 68systemd = { 69enable = lib . mkEnableOption null // { 70default = true ; 71description = '' 72Whether to enable {file}`hyprland-session.target` on 73hyprland startup. This links to `graphical-session.target`. 74Some important environment variables will be imported to systemd 75and D-Bus user environment before reaching the target, including 76- `DISPLAY` 77- `HYPRLAND_INSTANCE_SIGNATURE` 78- `WAYLAND_DISPLAY` 79- `XDG_CURRENT_DESKTOP` 80'' ; 81}; 82 83variables = lib . mkOption { 84type = with lib . types ; listOf str ; 85default = [ 86"DISPLAY" 87"HYPRLAND_INSTANCE_SIGNATURE" 88"WAYLAND_DISPLAY" 89"XDG_CURRENT_DESKTOP" 90]; 91example = [ "-all" ]; 92description = '' 93Environment variables to be imported in the systemd & D-Bus user 94environment. 95'' ; 96}; 97 98extraCommands = lib . mkOption { 99type = with lib . types ; listOf str ; 100default = [ 101"systemctl --user stop hyprland-session.target" 102"systemctl --user start hyprland-session.target" 103]; 104description = "Extra commands to be run after D-Bus activation." ; 105}; 106}; 107 108xwayland . enable = lib . mkEnableOption "XWayland" // { default = true ; }; 109 110enableNvidiaPatches = 111lib . mkEnableOption "patching wlroots for better Nvidia support" ; 112 113settings = lib . mkOption { 114type = with lib . types ; 115let 116valueType = nullOr ( oneOf [ 117bool 118int 119float 120str 121path 122( attrsOf valueType ) 123( listOf valueType ) 124]) // { 125description = "Hyprland configuration value" ; 126}; 127in valueType ; 128default = { }; 129description = '' 130Hyprland configuration written in Nix. Entries with the same key 131should be written as lists. Variables' and colors' names should be 132quoted. See <https://wiki.hyprland.org> for more examples. 133 134::: {.note} 135Use the [](#opt-wayland.windowManager.hyprland.plugins) option to 136declare plugins. 137::: 138 139'' ; 140example = lib . literalExpression '' 141{ 142decoration = { 143shadow_offset = "0 5"; 144"col.shadow" = "rgba(00000099)"; 145}; 146 147"$mod" = "SUPER"; 148 149bindm = [ 150# mouse movements 151"$mod, mouse:272, movewindow" 152"$mod, mouse:273, resizewindow" 153"$mod ALT, mouse:272, resizewindow" 154]; 155} 156'' ; 157}; 158 159extraConfig = lib . mkOption { 160type = lib . types . lines ; 161default = "" ; 162example = '' 163# window resize 164bind = $mod, S, submap, resize 165 166submap = resize 167binde = , right, resizeactive, 10 0 168binde = , left, resizeactive, -10 0 169binde = , up, resizeactive, 0 -10 170binde = , down, resizeactive, 0 10 171bind = , escape, submap, reset 172submap = reset 173'' ; 174description = '' 175Extra configuration lines to add to `~/.config/hypr/hyprland.conf`. 176'' ; 177}; 178}; 179 180config = lib . mkIf cfg . enable { 181assertions = [ 182( lib . hm . assertions . assertPlatform "wayland.windowManager.hyprland" pkgs 183lib . platforms . linux ) 184]; 185 186warnings = let 187inconsistent = ( cfg . systemd . enable || cfg . plugins != [ ]) 188&& cfg . extraConfig == "" && cfg . settings == { }; 189warning = 190"You have enabled hyprland.systemd.enable or listed plugins in hyprland.plugins but do not have any configuration in hyprland.settings or hyprland.extraConfig. This is almost certainly a mistake." ; 191in lib . optional inconsistent warning ; 192 193home . packages = lib . optional ( cfg . package != null ) cfg . finalPackage ; 194 195xdg . configFile . "hypr/hyprland.conf" = let 196combinedSettings = cfg . settings // { 197plugin = let 198mkEntry = entry : 199if lib . types . package . check entry then 200" ${ entry } /lib/lib ${ entry . pname } .so" 201else 202entry ; 203in map mkEntry cfg . plugins ; 204}; 205 206shouldGenerate = cfg . systemd . enable || cfg . extraConfig != "" 207|| combinedSettings != { }; 208 209toHyprconf = with lib ; 210attrs :indentLevel : 211let 212indent = concatStrings ( replicate indentLevel " " ); 213 214mkSection = n :attrs :'' 215${ indent }${ n } { 216${ toHyprconf attrs ( indentLevel + 1 )}${ indent } } 217'' ; 218sections = filterAttrs ( n :v :isAttrs v ) attrs ; 219 220mkFields = generators . toKeyValue { 221listsAsDuplicateKeys = true ; 222inherit indent ; 223}; 224allFields = filterAttrs ( n :v :! ( isAttrs v )) attrs ; 225importantFields = 226filterAttrs ( n :_ :( hasPrefix "$" n ) || ( hasPrefix "bezier" n )) 227allFields ; 228fields = builtins . removeAttrs allFields 229( mapAttrsToList ( n :_ :n ) importantFields ); 230in mkFields importantFields 231+ concatStringsSep "\n" ( mapAttrsToList mkSection sections ) 232+ mkFields fields ; 233in lib . mkIf shouldGenerate { 234text = lib . optionalString cfg . systemd . enable systemdActivation 235+ lib . optionalString ( combinedSettings != { }) 236( toHyprconf combinedSettings 0 ) 237+ lib . optionalString ( cfg . extraConfig != "" ) cfg . extraConfig ; 238 239onChange = lib . mkIf ( cfg . package != null ) '' 240( # execute in subshell so that `shopt` won't affect other scripts 241shopt -s nullglob # so that nothing is done if /tmp/hypr/ does not exist or is empty 242for instance in /tmp/hypr/*; do 243HYPRLAND_INSTANCE_SIGNATURE=''${instance##*/} ${ cfg . finalPackage } /bin/hyprctl reload config-only \ 244|| true # ignore dead instance(s) 245done 246) 247'' ; 248}; 249 250systemd . user . targets . hyprland-session = lib . mkIf cfg . systemd . enable { 251Unit = { 252Description = "Hyprland compositor session" ; 253Documentation = [ "man:systemd.special(7)" ]; 254BindsTo = [ "graphical-session.target" ]; 255Wants = [ "graphical-session-pre.target" ]; 256After = [ "graphical-session-pre.target" ]; 257}; 258}; 259 260systemd . user . targets . tray = { 261Unit = { 262Description = "Home Manager System Tray" ; 263Requires = [ "graphical-session-pre.target" ]; 264}; 265}; 266}; 267}