Factor out screen locking

This commit is contained in:
Nathan McCarty 2023-06-20 01:52:09 -04:00
parent f435df434e
commit 63e7c14a8e
Signed by: thatonelutenist
SSH Key Fingerprint: SHA256:hwQEcmak9E6sdU9bXc98RHw/Xd1AhpB5HZT7ZSVJkRM
3 changed files with 50 additions and 33 deletions

View File

@ -53,6 +53,18 @@ with nLib; {
description = "Targets to install desktop services to";
default = [ "hyprland-session.target" ];
};
swaylock = {
package = mkOption {
description = "Swaylock package to use";
default =
inputs.nixpkgs-unstable.legacyPackages.${pkgs.system}.swaylock-effects;
};
command = mkOption {
description = "Swaylock package to use";
default = ''
--screenshots --grace 30 --indicator --clock --timestr "%-I:%M:%S %p" --datestr "%A %Y-%M-%d" --effect-blur 20x3'';
};
};
};
};
# Linux specific programs

View File

@ -0,0 +1,35 @@
{ config, lib, pkgs, ... }:
let
swaylock-package = config.nathan.config.desktop.swaylock.package;
swaylock-command = config.nathan.config.desktop.swaylock.command;
targets = config.nathan.config.desktop.targets;
in lib.mkMerge [
(lib.mkIf config.nathan.programs.hyprland.enable {
wayland.windowManager.hyprland.extraConfig = ''
bind = SUPER, Z, exec, ${swaylock-package}/bin/swaylock ${swaylock-command}
'';
})
({
home.packages = with pkgs; [ swaylock-package swayidle ];
services.swayidle = {
enable = true;
timeouts = [
# Lock the screen after 5 minutes of inactivity
{
timeout = 300;
command = "${swaylock-package}/bin/swaylock ${
builtins.replaceStrings [ "%" ] [ "%%" ] swaylock-command
}";
}
# Turn off the displays after 10 minutes of inactivity
{
timeout = 600;
command = "hyprctl dispatch dpms off";
resumeCommand = "hyprctl dispatch dpms on";
}
];
};
systemd.user.services.swayidle = { Install = { WantedBy = targets; }; };
})
]

View File

@ -1,14 +1,9 @@
{ config, lib, pkgs, inputs, ... }@args:
let nathan = config.nathan;
in with lib; {
imports = [ ./desktop/waybar.nix ];
imports = [ ./desktop/waybar.nix ./desktop/locking.nix ];
config = mkIf nathan.programs.hyprland.enable (let
swaylock-package =
inputs.nixpkgs-unstable.legacyPackages.${pkgs.system}.swaylock-effects;
swaylock-command = ''
${swaylock-package}/bin/swaylock --screenshots --grace 30 --indicator --clock --timestr "%-I:%M:%S %p" --datestr "%A %Y-%M-%d" --effect-blur 20x3'';
# fuzzel-command = config.nathan.config.desktop.fuzzel-command;
fuzzel-command = "";
fuzzel-command = config.nathan.config.desktop.fuzzel-command;
notif-package =
inputs.nixpkgs-unstable.legacyPackages.${pkgs.system}.swaynotificationcenter;
shortcuts = inputs.self.packages.${pkgs.system}.shortcuts;
@ -16,10 +11,8 @@ in with lib; {
home.packages = with pkgs; [
# General
killall
# Locking and display management
# Display management
wdisplays
swaylock-package
swayidle
# Clipboard
wl-clipboard
cliphist
@ -145,7 +138,6 @@ in with lib; {
bind = $mainMod, R, exec, ${fuzzel-command} --prompt=' '
bind = $mainMod, P, pseudo, # dwindle
bind = $mainMod, B, togglesplit, # dwindle
bind = $mainMod, Z, exec, ${swaylock-command}
# Move focus with mainMod + arrow keys
bind = $mainMod, H, movefocus, l
@ -387,28 +379,6 @@ in with lib; {
Install = { WantedBy = [ "hyprland-session.target" ]; };
};
#########################
## Swayidle
#########################
services.swayidle = {
enable = true;
timeouts = [
# Lock the screen after 5 minutes of inactivity
{
timeout = 300;
command = builtins.replaceStrings [ "%" ] [ "%%" ] swaylock-command;
}
# Turn off the displays after 10 minutes of inactivity
{
timeout = 600;
command = "hyprctl dispatch dpms off";
resumeCommand = "hyprctl dispatch dpms on";
}
];
};
systemd.user.services.swayidle = {
Install = { WantedBy = [ "hyprland-session.target" ]; };
};
#########################
## EasyEffects
#########################
services.easyeffects.enable = true;