summaryrefslogblamecommitdiffstats
path: root/modules/desktop/hyprland.nix
blob: 134d52f93f2733a8257782e3d83f8a9bbbd7be57 (plain) (tree)














































































































                                                                                                                                                          
                                                          
























                                                                          




                                                              




                                                       
                                  




























                                                                                

                                   



                                                  





                                                   
                                                   

                                                           
 
                                                
                                               
















                                                                    





















                                                                                                      
















                                                       
{
    config,
    options,
    lib,
    pkgs,
    ...
}: let
    hyprlandConf = config.modules.desktop.hyprland;
    device = config.modules.device;
    defaultApps = config.modules.desktop.defaultApplications.apps;
    configDir = config.nixosConfig.configDir;

    screenshotarea = "hyprctl keyword animation 'fadeOut,0,0,default'; grimblast --notify copysave area; hyprctl keyword animation 'fadeOut,1,4,default'";

    # binds $mod + [shift +] {1..10} to [move to] workspace {1..10}
    workspaces = builtins.concatLists (builtins.genList (
        x: let
            ws = let
                c = (x + 1) / 10;
            in
                builtins.toString (x + 1 - (c * 10));
        in
            [
                "$mod, ${ws}, exec, /etc/nixos/bin/hyprland/workspace ${toString (x + 1)}"
                "$mod SHIFT, ${ws}, movetoworkspace, ${toString (x + 1)}"
            ]
        )
    10);

    decoration = {
        rounding = 7;
        blur = {
            enabled = true;
            size = 3;
            passes = 1;
        };
        drop_shadow = true;
        shadow_ignore_window = true;
        shadow_offset = "0 2";
        shadow_range = 20;
        shadow_render_power = 3;
        "col.shadow" = "rgba(00000055)";
    };

    animations = {
        enabled = true;
        animation = [
            "border, 1, 2, default"
            "fade, 1, 4, default"
            "windows, 1, 3, default, popin 80%"
            "workspaces, 1, 2, default, slide"
        ];
    };

    keybinds = let
        monocle = "dwindle:no_gaps_when_only";
    in [
        # Compositor commands
        "$mod ALTL, Q, exec, pkill Hyprland"
        "$mod, Q, killactive"

        # Layout
        "$mod, F, fullscreen"
        "$mod, Space, togglefloating"
        "$mod, S, togglesplit"
        "$mod, P, pseudo"
        "$mod SHIFT, grave, movetoworkspace, special"
        "$mod, grave, togglespecialworkspace"

        # Group
        "$mod, G, togglegroup"
        "$mod, TAB, changegroupactive"

        #Focus windows
        "$mod, left, movefocus, l"
        "$mod, right, movefocus, r"
        "$mod, up, movefocus, u"
        "$mod, down, movefocus, d"

        #Focus monitor
        "$mod SHIFT, left, focusmonitor, l"
        "$mod SHIFT, right, focusmonitor, r"

        #Exec binds
        "$mod, D, exec, wofi --show drun"
        "$mod, Return, exec, ${defaultApps.terminal.cmd}"
        "$mod, W, exec, ${defaultApps.browser.cmd}"
        "$mod ALTL, B, exec, killall -SIGUSR2 waybar"
    ]
    ++ workspaces;

    mousebinds = let
    in [
        "$mod, mouse:272, movewindow"
        "$mod, mouse:273, resizewindow"
    ];
in {
    options.modules.desktop.hyprland = {
        enable = lib.mkOption {
            type = lib.types.bool;
            default = false;
        };
        xwayland = lib.mkOption {
            type = lib.types.bool;
            default = true;
        };
    };

    config = lib.mkIf (hyprlandConf.enable) (lib.mkMerge [
    {
        environment.variables.WLR_NO_HARDWARE_CURSORS = "1";
        environment.sessionVariables.NIXOS_OZONE_WL = "1";

        home.packages = [
            pkgs.killall
            pkgs.wl-clipboard
            pkgs.wdisplays
            pkgs.swaylock
            pkgs.swayidle
            pkgs.wofi
            pkgs.jq
            pkgs.swww
        ];

        modules.device.displayProtocol = "wayland";

        xdg.portal = {
            enable = true;
            wlr = {
                enable = true;
                settings = {
                    screencast = {
                        chooser_type = "simple";
                        chooser_cmd = "${pkgs.slurp}/bin/slurp -f %o -or";
                    };
                };
            };
            extraPortals = [
              pkgs.xdg-desktop-portal-gtk
              pkgs.xdg-desktop-portal-hyprland
            ];
            config.common.default = ["wlr" "gtk" "hyprland" ];
        };

        home.manager.wayland.windowManager.hyprland = {
            enable = true;
            xwayland.enable = hyprlandConf.xwayland;
            systemd.enable = true;

            settings = {
                "$mod" = "SUPER";

                input = {
                    kb_layout = "us";
                    follow_mouse = 1;
                    sensitivity = 0;
                };

                dwindle = {
                    pseudotile = true;
                    preserve_split = true;
                };

                general = {
                    gaps_in = 5;
                    gaps_out = 10;
                    border_size = 2;
                    "col.active_border" = "rgba(33ccffee) rgba(00ff99ee) 45deg";
                    "col.inactive_border" = "rgba(595959aa)";

                    layout = "dwindle";
                };
                exec-once = [
                    "swww init"
                    "swww img ${configDir}/hypr/wallpaper.png"
                ];

                env = lib.mkMerge [
                  ([
                    "XDG_CURRENT_DESKTOP,Hyprland"
                    "XDG_SESSION_TYPE,wayland"
                    "XDG_SESSION_DESKTOP,Hyprland"

                    "GDK_BACKEND,wayland,x11"
                    "SDL_VIDEODRIVER,wayland"
                    "CLUTTER_BACKEND,wayland"
                    "MOZ_ENABLE_WAYLAND,1"
                    "MOZ_DISABLE_RDD_SANDBOX,1"
                    "_JAVA_AWT_WM_NONREPARENTING,1"
                    "QT_AUTO_SCREEN_SCALE_FACTOR,1"
                    "QT_QPA_PLATFORM,wayland"
                    "QT_WAYLAND_DISABLE_WINDOWDECORATION,1"

                    "disable_hyprland_logo,true"
                    "force_default_wallpaper,0"
                  ])
                  ( lib.mkIf (config.modules.device.gpu == "nvidia")
                  [
                     "GBM_BACKEND,nvidia"
                    "__GLX_VENDOR_LIBRARY_NAME,nvidia"
                    "LIBVA_DRIVER_NAME,nvidia"
                    "NVD_BACKEND,direct"
                    "PROTON_ENABLE_NGX_UPDATER,1"
                    "__GL_GSYNC_ALLOWED,1"
                    "__GL_VRR_ALLOWED,1"
                    "__GL_MaxFramesAllowed,1"
                    "__NV_PRIME_RENDER_OFFLOAD,1"
                    "__VK_LAYER_NV_optimus,NIVIDA_only"
                    "WLR_DRM_NO_ATOMIC,1"
                    "WLR_USE_LIBINPUT,1"
                    "WLR_RENDERER_ALLOW_SOFTWARE,1"
                  ])];

                decoration = decoration;
                animations = animations;
                bind = keybinds;
                bindm = mousebinds;
            };
        };

        programs.waybar = {
            enable = true;
        };

        home.manager.xdg.configFile."hypr/hyprpaper.conf".source = "${configDir}/hypr/hyprpaper.conf";
        #Symlink waybar
        system.userActivationScripts.linkwaybar.text = ''
            if [[ ! -h "$HOME/.config/waybar" ]]; then
                ln -s "${configDir}/waybar" "$HOME/.config/waybar"
            fi
        '';

        security.pam.services.swaylock = {};
    }
    (lib.mkIf (config.modules.desktop.greetd.enable) {
        services.greetd.settings = {
            default_session.command = ''
                ${pkgs.greetd.tuigreet}/bin/tuigreet \
                    --time \
                    --asterisks \
                    --user-menu \
                    --cmd Hyprland
            '';
        };

        environment.etc."greetd/environments".text = ''
            Hyprland
        '';
    })
    ]);
}