From c24198b1713dbba2253774785bb6312a00a2b6eb Mon Sep 17 00:00:00 2001 From: moons-14 Date: Mon, 3 Nov 2025 02:08:47 +0900 Subject: [PATCH] lock --- modules/core/services.nix | 9 +++++++++ modules/home/lock.nix | 26 ++++++++++++++++++++++++++ modules/home/ssh.nix | 4 ++-- profiles/gui.nix | 1 + 4 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 modules/home/lock.nix diff --git a/modules/core/services.nix b/modules/core/services.nix index 1bfe35d..ede3a00 100644 --- a/modules/core/services.nix +++ b/modules/core/services.nix @@ -16,6 +16,15 @@ pulse.enable = true; jack.enable = true; }; + + logind = { + lidSwitch = "lock"; # Lock when lid is closed + lidSwitchDocked = "ignore"; # Ignore when docked + extraConfig = '' + HandleLidSwitchExternalPower=lock + LidSwitchIgnoreInhibited=no + ''; + } }; } \ No newline at end of file diff --git a/modules/home/lock.nix b/modules/home/lock.nix new file mode 100644 index 0000000..117ce59 --- /dev/null +++ b/modules/home/lock.nix @@ -0,0 +1,26 @@ +{ pkgs, lib, ... }: + +let + noctaliaLock = "qs -c noctalia-shell ipc call sessionMenu lockAndSuspend"; + + dpmsOff = "${pkgs.niri}/bin/niri msg action power-off-monitors"; + dpmsOn = "${pkgs.niri}/bin/niri msg action power-on-monitors"; +in +{ + services.swayidle = { + enable = true; + systemdTarget = "graphical-session.target"; + + timeouts = [ + { timeout = 300; command = noctaliaLock; } + + { timeout = 306; command = dpmsOff; resumeCommand = dpmsOn; } + ]; + + events = [ + { event = "lock"; command = noctaliaLock; } + { event = "before-sleep"; command = noctaliaLock; } + { event = "after-resume"; command = dpmsOn; } + ]; + }; +} diff --git a/modules/home/ssh.nix b/modules/home/ssh.nix index d44f322..06ed018 100644 --- a/modules/home/ssh.nix +++ b/modules/home/ssh.nix @@ -1,4 +1,4 @@ -{ config, lib, pkgs, ... }: +{ config, lib, pkgs, host, ... }: { home.packages = [ pkgs.openssh ]; @@ -18,7 +18,7 @@ umask 077 mkdir -p "$HOME/.ssh" ${pkgs.openssh}/bin/ssh-keygen -t ed25519 -N "" -f "$key" \ - -C "moons@$(hostnamectl --static 2>/dev/null || echo host)" + -C "moons@$(${host} || echo host)" echo "Generated SSH key at $key" fi ''; diff --git a/profiles/gui.nix b/profiles/gui.nix index 20f3810..23222f3 100644 --- a/profiles/gui.nix +++ b/profiles/gui.nix @@ -18,5 +18,6 @@ ./../modules/home/avatar.nix ./../modules/home/ghostty ./../modules/home/wallpaper.nix + ./../modules/home/lock.nix ]; } \ No newline at end of file