From 4e20345a9365f2fe3ae19a3f5f2d654bcd7c1429 Mon Sep 17 00:00:00 2001 From: ooks-io Date: Fri, 23 Feb 2024 21:08:49 +1300 Subject: [PATCH] feat: hypridle init config --- flake.lock | 57 ++++++++++++++++--- flake.nix | 5 ++ .../wayland/lockscreen/hyprlock/default.nix | 28 +++++++-- home/profile/hyprland/default.nix | 2 +- 4 files changed, 80 insertions(+), 12 deletions(-) diff --git a/flake.lock b/flake.lock index 47526f0..8c41993 100644 --- a/flake.lock +++ b/flake.lock @@ -338,10 +338,31 @@ "type": "github" } }, + "hypridle": { + "inputs": { + "hyprlang": "hyprlang", + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1708597999, + "narHash": "sha256-Glwi2jMjT/fCMbRGun+zoZOE6nQ053XfFfFuqi23+ds=", + "owner": "hyprwm", + "repo": "hypridle", + "rev": "b85722e41aeb9925f248e9b3fe8427475cb1eb6b", + "type": "github" + }, + "original": { + "owner": "hyprwm", + "repo": "hypridle", + "type": "github" + } + }, "hyprland": { "inputs": { "hyprland-protocols": "hyprland-protocols", - "hyprlang": "hyprlang", + "hyprlang": "hyprlang_2", "nixpkgs": [ "nixpkgs" ], @@ -409,6 +430,27 @@ } }, "hyprlang": { + "inputs": { + "nixpkgs": [ + "hypridle", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1708212860, + "narHash": "sha256-nW3Zrhh9RJcMTvOcXAaKADnJM/g6tDf3121lJtTHnYo=", + "owner": "hyprwm", + "repo": "hyprlang", + "rev": "11d5ccda071c153dfdc18ef65338956a51cef96a", + "type": "github" + }, + "original": { + "owner": "hyprwm", + "repo": "hyprlang", + "type": "github" + } + }, + "hyprlang_2": { "inputs": { "nixpkgs": [ "hyprland", @@ -429,7 +471,7 @@ "type": "github" } }, - "hyprlang_2": { + "hyprlang_3": { "inputs": { "nixpkgs": [ "hyprland", @@ -451,7 +493,7 @@ "type": "github" } }, - "hyprlang_3": { + "hyprlang_4": { "inputs": { "nixpkgs": [ "hyprlock", @@ -472,7 +514,7 @@ "type": "github" } }, - "hyprlang_4": { + "hyprlang_5": { "inputs": { "nixpkgs": "nixpkgs_3" }, @@ -492,7 +534,7 @@ }, "hyprlock": { "inputs": { - "hyprlang": "hyprlang_3", + "hyprlang": "hyprlang_4", "nixpkgs": "nixpkgs_2" }, "locked": { @@ -511,7 +553,7 @@ }, "hyprpaper": { "inputs": { - "hyprlang": "hyprlang_4", + "hyprlang": "hyprlang_5", "nixpkgs": "nixpkgs_4" }, "locked": { @@ -897,6 +939,7 @@ "hardware": "hardware", "helix": "helix", "home-manager": "home-manager", + "hypridle": "hypridle", "hyprland": "hyprland", "hyprland-plugins": "hyprland-plugins", "hyprlock": "hyprlock", @@ -1106,7 +1149,7 @@ "hyprland", "hyprland-protocols" ], - "hyprlang": "hyprlang_2", + "hyprlang": "hyprlang_3", "nixpkgs": [ "hyprland", "nixpkgs" diff --git a/flake.nix b/flake.nix index 1897201..8819266 100644 --- a/flake.nix +++ b/flake.nix @@ -43,6 +43,11 @@ }; hyprlock.url = "github:hyprwm/hyprlock"; + + hypridle = { + url = "github:hyprwm/hypridle"; + inputs.nixpkgs.follows = "nixpkgs"; + }; hyprpaper.url = "github:hyprwm/hyprpaper"; diff --git a/home/modules/desktop/wayland/lockscreen/hyprlock/default.nix b/home/modules/desktop/wayland/lockscreen/hyprlock/default.nix index e0e5c11..076b025 100644 --- a/home/modules/desktop/wayland/lockscreen/hyprlock/default.nix +++ b/home/modules/desktop/wayland/lockscreen/hyprlock/default.nix @@ -1,12 +1,22 @@ -{ lib, config, inputs, ... }: +{ lib, config, inputs, pkgs, ... }: let cfg = config.homeModules.desktop.wayland.lockscreen.hyprlock; inherit (config.colorscheme) colors; + suspendScript = pkgs.writeShellScript "suspend-script" '' + ${pkgs.pipewire}/bin/pw-cli i all | ${pkgs.ripgrep}/bin/rg running + # only suspend if audio isn't running + if [ $? == 1 ]; then + ${pkgs.systemd}/bin/systemctl suspend + fi + ''; in { - imports = [ inputs.hyprlock.homeManagerModules.hyprlock ]; + imports = [ + inputs.hyprlock.homeManagerModules.default + inputs.hypridle.homeManagerModules.default + ]; config = lib.mkIf cfg.enable { home.sessionVariables.LOCKER = "hyprlock"; @@ -67,7 +77,17 @@ in } ]; }; - }; + services.hypridle = { + enable = true; + beforeSleepCmd = "${pkgs.systemd}/bin/loginctl lock-session"; + lockCmd = lib.getExe config.programs.hyprlock.package; - + listeners = [ + { + timeout = 330; + onTimeout = suspendScript.outPath; + } + ]; + }; + }; } diff --git a/home/profile/hyprland/default.nix b/home/profile/hyprland/default.nix index 5197d16..87ab0ae 100644 --- a/home/profile/hyprland/default.nix +++ b/home/profile/hyprland/default.nix @@ -13,7 +13,7 @@ in wayland = { base.enable = true; windowManager.hyprland.enable = true; - lockscreen.swaylock.enable = true; + lockscreen.hyprlock.enable = true; notification.mako.enable = true; bar.ags.enable = true; };