From a72a054632526b8d513f55827b2d1692fac94bf5 Mon Sep 17 00:00:00 2001 From: Updater Date: Wed, 29 May 2024 12:30:14 -0400 Subject: [PATCH] feat(hypr wim): hypridle -> acpid --- flake.lock | 85 ++-------------------- flake.nix | 9 +-- inputs.nix | 5 -- modules/ags/config/ts/lockscreen/main.ts | 3 +- modules/hyprland/security.nix | 89 ++++++++++++++++-------- 5 files changed, 69 insertions(+), 122 deletions(-) diff --git a/flake.lock b/flake.lock index 213215b1..063cc6f4 100644 --- a/flake.lock +++ b/flake.lock @@ -467,7 +467,7 @@ }, "flake-utils_2": { "inputs": { - "systems": "systems_7" + "systems": "systems_5" }, "locked": { "lastModified": 1710146030, @@ -815,37 +815,15 @@ "type": "github" } }, - "hypridle": { - "inputs": { - "hyprlang": "hyprlang", - "nixpkgs": [ - "nixpkgs" - ], - "systems": "systems_5" - }, - "locked": { - "lastModified": 1716309977, - "narHash": "sha256-4jDQIcMDSFOOMBxVTEiC6Ck1vdc0kAFvv+StxnnE59Q=", - "owner": "hyprwm", - "repo": "hypridle", - "rev": "cb169c4e06cec9b4349e3668427e729d22328a54", - "type": "github" - }, - "original": { - "owner": "hyprwm", - "repo": "hypridle", - "type": "github" - } - }, "hyprland": { "inputs": { "hyprcursor": "hyprcursor", - "hyprlang": "hyprlang_2", + "hyprlang": "hyprlang", "hyprwayland-scanner": "hyprwayland-scanner", "nixpkgs": [ "nixpkgs" ], - "systems": "systems_6", + "systems": "systems_4", "xdph": "xdph" }, "locked": { @@ -892,28 +870,6 @@ } }, "hyprlang": { - "inputs": { - "nixpkgs": [ - "hypridle", - "nixpkgs" - ], - "systems": "systems_4" - }, - "locked": { - "lastModified": 1713121246, - "narHash": "sha256-502X0Q0fhN6tJK7iEUA8CghONKSatW/Mqj4Wappd++0=", - "owner": "hyprwm", - "repo": "hyprlang", - "rev": "78fcaa27ae9e1d782faa3ff06c8ea55ddce63706", - "type": "github" - }, - "original": { - "owner": "hyprwm", - "repo": "hyprlang", - "type": "github" - } - }, - "hyprlang_2": { "inputs": { "nixpkgs": [ "hyprland", @@ -1892,7 +1848,6 @@ "headscale": "headscale", "home-manager": "home-manager", "hypr-official-plugins": "hypr-official-plugins", - "hypridle": "hypridle", "hyprland": "hyprland", "jellyfin-flake": "jellyfin-flake", "jellyfin-ultrachromic-src": "jellyfin-ultrachromic-src", @@ -2132,36 +2087,6 @@ } }, "systems_5": { - "locked": { - "lastModified": 1689347949, - "narHash": "sha256-12tWmuL2zgBgZkdoB6qXZsgJEH9LR3oUgpaQq2RbI80=", - "owner": "nix-systems", - "repo": "default-linux", - "rev": "31732fcf5e8fea42e59c2488ad31a0e651500f68", - "type": "github" - }, - "original": { - "owner": "nix-systems", - "repo": "default-linux", - "type": "github" - } - }, - "systems_6": { - "locked": { - "lastModified": 1689347949, - "narHash": "sha256-12tWmuL2zgBgZkdoB6qXZsgJEH9LR3oUgpaQq2RbI80=", - "owner": "nix-systems", - "repo": "default-linux", - "rev": "31732fcf5e8fea42e59c2488ad31a0e651500f68", - "type": "github" - }, - "original": { - "owner": "nix-systems", - "repo": "default-linux", - "type": "github" - } - }, - "systems_7": { "locked": { "lastModified": 1681028828, "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", @@ -2176,7 +2101,7 @@ "type": "github" } }, - "systems_8": { + "systems_6": { "locked": { "lastModified": 1689347949, "narHash": "sha256-12tWmuL2zgBgZkdoB6qXZsgJEH9LR3oUgpaQq2RbI80=", @@ -2308,7 +2233,7 @@ "nixpkgs": [ "nixpkgs" ], - "systems": "systems_8" + "systems": "systems_6" }, "locked": { "lastModified": 1716199546, diff --git a/flake.nix b/flake.nix index d355e6c4..59ec7656 100644 --- a/flake.nix +++ b/flake.nix @@ -1,4 +1,5 @@ # Do not modify! This file is generated. + { inputs = { Hyprspace = { @@ -116,12 +117,6 @@ repo = "hyprland-plugins"; type = "github"; }; - hypridle = { - inputs.nixpkgs.follows = "nixpkgs"; - owner = "hyprwm"; - repo = "hypridle"; - type = "github"; - }; hyprland = { inputs.nixpkgs.follows = "nixpkgs"; submodules = true; @@ -339,4 +334,4 @@ }; }; outputs = inputs: inputs.flakegen ./flake.in.nix inputs; -} +} \ No newline at end of file diff --git a/inputs.nix b/inputs.nix index 9a56e5ef..6bc30c16 100644 --- a/inputs.nix +++ b/inputs.nix @@ -142,11 +142,6 @@ let repo = "Hyprspace"; }; - hypridle = mkDep { - owner = "hyprwm"; - repo = "hypridle"; - }; - grim-hyprland = mkDep { owner = "eriedaberrie"; repo = "grim-hyprland"; diff --git a/modules/ags/config/ts/lockscreen/main.ts b/modules/ags/config/ts/lockscreen/main.ts index 512d911a..b473c66f 100644 --- a/modules/ags/config/ts/lockscreen/main.ts +++ b/modules/ags/config/ts/lockscreen/main.ts @@ -207,9 +207,10 @@ const on_finished = () => { lock.connect('finished', on_finished); if (Vars.hasFprintd) { - Utils.authenticate('') + globalThis.authFinger = () => Utils.authenticate('') .then(() => unlock()) .catch(logError); + globalThis.authFinger(); } diff --git a/modules/hyprland/security.nix b/modules/hyprland/security.nix index dd5e89aa..2fc3680d 100644 --- a/modules/hyprland/security.nix +++ b/modules/hyprland/security.nix @@ -1,14 +1,44 @@ { config, - hypridle, lib, pkgs, ... }: let - inherit (lib) mkIf optionals; + inherit (lib) mkIf; inherit (config.vars) mainUser; isLaptop = config.services.logind.lidSwitch == "lock"; + + hmCfg = config.home-manager.users.${mainUser}; + agsPkg = hmCfg.programs.ags.finalPackage; + hyprPkg = hmCfg.wayland.windowManager.hyprland.finalPackage; + + runInDesktop = pkgs.writeShellApplication { + name = "runInDesktop"; + runtimeInputs = [ + pkgs.sudo + agsPkg + hyprPkg + ]; + text = '' + user="$(id -u ${mainUser})" + sig="$(ls "/run/user/$user/hypr/")" + export HYPRLAND_INSTANCE_SIGNATURE="$sig" + + sudo -Eu ${mainUser} hyprctl dispatch exec "$@" + ''; + }; + + lockPkg = pkgs.writeShellApplication { + name = "lock"; + runtimeInputs = [ + agsPkg + ]; + text = '' + ags -r 'Tablet.setLaptopMode()' + ags -b lockscreen -c /home/${mainUser}/.config/ags/lockscreen.js + ''; + }; in { imports = [ ../greetd @@ -16,40 +46,41 @@ in { services.gnome.gnome-keyring.enable = true; - home-manager.users.${mainUser} = let - hmCfg = config.home-manager.users.${mainUser}; - lockPkg = pkgs.writeShellApplication { - name = "lock"; - runtimeInputs = [ - hmCfg.programs.ags.finalPackage - ]; - text = '' - ags -r 'Tablet.setLaptopMode()' - ags -b lockscreen -c /home/${mainUser}/.config/ags/lockscreen.js - ''; - }; - in { + services.acpid = mkIf isLaptop { + enable = true; + + lidEventCommands = '' + LID="/proc/acpi/button/lid/LID/state" + state=$(cat "$LID" | ${pkgs.gawk}/bin/awk '{print $2}') + + case "$state" in + *open*) + ${runInDesktop}/bin/runInDesktop "ags -b lockscreen -r 'authFinger()'" + ;; + + *close*) + ${runInDesktop}/bin/runInDesktop ${lockPkg}/bin/lock + ;; + + *) + logger -t lid-handler "Failed to detect lid state ($state)" + ;; + esac + ''; + }; + + home-manager.users.${mainUser} = { home.packages = [ pkgs.gnome.seahorse lockPkg ]; - services.hypridle = mkIf isLaptop { - enable = true; - package = hypridle.packages.${pkgs.system}.default; - settings.general.lock_cmd = "${lockPkg}/bin/lock"; - }; - wayland.windowManager.hyprland = { settings = { - exec-once = - [ - "gnome-keyring-daemon --start --components=secrets" - "${pkgs.plasma5Packages.polkit-kde-agent}/libexec/polkit-kde-authentication-agent-1" - ] - ++ optionals isLaptop [ - "systemctl --user restart hypridle" - ]; + exec-once = [ + "gnome-keyring-daemon --start --components=secrets" + "${pkgs.plasma5Packages.polkit-kde-agent}/libexec/polkit-kde-authentication-agent-1" + ]; windowrule = [ "float,^(org.kde.polkit-kde-authentication-agent-1)$"