From 389b051a7a3dca9a6cddaedbb9fda398521fba3a Mon Sep 17 00:00:00 2001 From: alejandro-angulo Date: Sun, 17 Aug 2025 22:27:12 -0700 Subject: [PATCH] Add hypridle and hyprlock --- .../x86_64-linux/alejandro@carbon/default.nix | 3 +- modules/home/programs/hyprlock/default.nix | 128 ++++++++++++++++++ modules/home/services/hypridle/default.nix | 110 +++++++++++++++ .../home/windowManagers/hyprland/default.nix | 6 + 4 files changed, 246 insertions(+), 1 deletion(-) create mode 100644 modules/home/programs/hyprlock/default.nix create mode 100644 modules/home/services/hypridle/default.nix diff --git a/homes/x86_64-linux/alejandro@carbon/default.nix b/homes/x86_64-linux/alejandro@carbon/default.nix index 94be443..0be4298 100644 --- a/homes/x86_64-linux/alejandro@carbon/default.nix +++ b/homes/x86_64-linux/alejandro@carbon/default.nix @@ -1,7 +1,8 @@ -{ ... }: +{ lib, ... }: { aa.isHeadless = false; aa.windowManagers.sway.clamshell.enable = true; aa.programs.opencode.enable = true; aa.windowManagers.hyprland.enable = true; + aa.windowManagers.sway.enable = lib.mkForce true; } diff --git a/modules/home/programs/hyprlock/default.nix b/modules/home/programs/hyprlock/default.nix new file mode 100644 index 0000000..66fa3a1 --- /dev/null +++ b/modules/home/programs/hyprlock/default.nix @@ -0,0 +1,128 @@ +{ + config, + pkgs, + lib, + namespace, + ... +}: +let + inherit (lib) mkIf mkEnableOption mkOption types; + + cfg = config.${namespace}.programs.hyprlock; +in +{ + options.${namespace}.programs.hyprlock = { + enable = mkEnableOption "hyprlock"; + + backgroundPath = mkOption { + type = types.str; + default = "screenshot"; + description = '' + Path to background image or "screenshot" to use desktop screenshot + ''; + }; + + settings = mkOption { + type = types.attrs; + default = {}; + description = '' + Additional hyprlock configuration settings + ''; + }; + }; + + config = mkIf cfg.enable { + home.packages = [ pkgs.hyprlock ]; + + catppuccin.hyprlock.enable = true; + + programs.hyprlock = { + enable = true; + settings = lib.mkMerge [ + { + general = { + hide_cursor = false; + ignore_empty_input = false; + text_trim = true; + fractional_scaling = 2; + fail_timeout = 2000; + }; + + auth = { + pam = { + enabled = true; + module = "hyprlock"; + }; + fingerprint = { + enabled = false; + ready_message = "(Scan fingerprint to unlock)"; + present_message = "Scanning fingerprint"; + }; + }; + + background = [ + { + monitor = ""; + path = cfg.backgroundPath; + color = "rgba(17, 17, 17, 1.0)"; + blur_passes = 2; + blur_size = 7; + noise = 0.0117; + contrast = 0.8916; + brightness = 0.8172; + vibrancy = 0.1696; + vibrancy_darkness = 0.05; + } + ]; + + # Input field for password + input-field = [ + { + monitor = ""; + size = "300, 50"; + outline_thickness = 2; + dots_size = 0.2; + dots_spacing = 0.2; + dots_center = true; + outer_color = "$lavender"; + inner_color = "$surface0"; + font_color = "$text"; + fade_on_empty = false; + placeholder_text = "Password..."; + hide_input = false; + position = "0, -120"; + halign = "center"; + valign = "center"; + } + ]; + + # Time label + label = [ + { + monitor = ""; + text = "cmd[update:1000] echo \"$(date +\"%H:%M\")\""; + color = "$text"; + font_size = 120; + font_family = "Hack Nerd Font"; + position = "0, 300"; + halign = "center"; + valign = "center"; + } + # Date label + { + monitor = ""; + text = "cmd[update:1000] echo \"$(date +\"%A, %B %d\")\""; + color = "$text"; + font_size = 24; + font_family = "Hack Nerd Font"; + position = "0, 200"; + halign = "center"; + valign = "center"; + } + ]; + } + cfg.settings + ]; + }; + }; +} \ No newline at end of file diff --git a/modules/home/services/hypridle/default.nix b/modules/home/services/hypridle/default.nix new file mode 100644 index 0000000..d0aa75f --- /dev/null +++ b/modules/home/services/hypridle/default.nix @@ -0,0 +1,110 @@ +{ + config, + pkgs, + lib, + namespace, + ... +}: +let + inherit (lib) + mkIf + mkEnableOption + mkOption + types + ; + + cfg = config.${namespace}.services.hypridle; +in +{ + options.${namespace}.services.hypridle = { + enable = mkEnableOption "hypridle"; + + lockTimeout = mkOption { + type = types.int; + default = 300; + description = '' + Timeout in seconds before locking the screen + ''; + }; + + displayTimeout = mkOption { + type = types.int; + default = 330; + description = '' + Timeout in seconds before turning off the display + ''; + }; + + suspendTimeout = mkOption { + type = types.int; + default = 1800; + description = '' + Timeout in seconds before suspending the system + ''; + }; + + brightnessTimeout = mkOption { + type = types.int; + default = 150; + description = '' + Timeout in seconds before dimming screen brightness + ''; + }; + + lockCommand = mkOption { + type = types.str; + default = "${pkgs.hyprlock}/bin/hyprlock"; + description = '' + Command to run when locking the screen + ''; + }; + }; + + config = mkIf cfg.enable { + home.packages = [ pkgs.hypridle ]; + + services.hypridle = { + enable = true; + settings = { + general = { + lock_cmd = "pidof hyprlock || ${cfg.lockCommand}"; + before_sleep_cmd = "loginctl lock-session"; + after_sleep_cmd = "hyprctl dispatch dpms on"; + ignore_dbus_inhibit = false; + ignore_systemd_inhibit = false; + }; + + listener = [ + # Dim screen brightness + { + timeout = cfg.brightnessTimeout; + on-timeout = "${pkgs.brightnessctl}/bin/brightnessctl -s set 10"; + on-resume = "${pkgs.brightnessctl}/bin/brightnessctl -r"; + } + # Turn off keyboard backlight (if available) + { + timeout = cfg.brightnessTimeout; + on-timeout = "${pkgs.brightnessctl}/bin/brightnessctl -sd rgb:kbd_backlight set 0"; + on-resume = "${pkgs.brightnessctl}/bin/brightnessctl -rd rgb:kbd_backlight"; + } + # Lock screen + { + timeout = cfg.lockTimeout; + on-timeout = "loginctl lock-session"; + } + # Turn off display + { + timeout = cfg.displayTimeout; + on-timeout = "hyprctl dispatch dpms off"; + on-resume = "hyprctl dispatch dpms on && ${pkgs.brightnessctl}/bin/brightnessctl -r"; + } + # Suspend system + { + timeout = cfg.suspendTimeout; + on-timeout = "systemctl suspend"; + } + ]; + }; + }; + }; +} diff --git a/modules/home/windowManagers/hyprland/default.nix b/modules/home/windowManagers/hyprland/default.nix index ec148dd..a0d96c1 100644 --- a/modules/home/windowManagers/hyprland/default.nix +++ b/modules/home/windowManagers/hyprland/default.nix @@ -62,11 +62,13 @@ in kitty.enable = true; fuzzel.enable = true; waybar.enable = true; + hyprlock.enable = true; }; services = { gammastep.enable = true; playerctld.enable = true; swaync.enable = true; + hypridle.enable = true; }; }; @@ -153,6 +155,7 @@ in exec-once = [ "systemctl --user import-environment DISPLAY WAYLAND_DISPLAY XDG_CURRENT_DESKTOP" "${pkgs.swaynotificationcenter}/bin/swaync" + "${pkgs.waybar}/bin/waybar" "hyprpaper" ]; @@ -214,6 +217,9 @@ in "$mod SHIFT, n, exec, ${pkgs.swaynotificationcenter}/bin/swaync-client -t -sw" "$mod SHIFT, d, exec, ${pkgs.swaynotificationcenter}/bin/swaync-client -d -sw" + "$mod SHIFT, x, exec, hyprctl dispatch exit" + "$mod, x, exec, ${pkgs.hyprlock}/bin/hyprlock" + # Scratchpad "$mod SHIFT, minus, movetoworkspace, special:magic" "$mod, minus, togglespecialworkspace, magic"