-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlock.mod.nix
137 lines (124 loc) · 3.47 KB
/
lock.mod.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
let
scripts = {
pkgs,
config,
...
}: let
# wl-copy = "${pkgs.wl-clipboard}/bin/wl-copy";
# wl-paste = "${pkgs.wl-clipboard}/bin/wl-paste";
convert = "${pkgs.imagemagick}/bin/convert";
grim = "${pkgs.grim}/bin/grim";
jq = "${pkgs.jq}/bin/jq";
swaylock = "${config.programs.swaylock.package}/bin/swaylock";
niri = "${config.programs.niri.package}/bin/niri";
# for quick iteration
magick_args = builtins.concatStringsSep " " [
"-scale 2%"
"-blur 0x.5"
"-resize 5000%"
];
in {
lock = pkgs.writeScriptBin "blurred-locker" ''
dir=/tmp/blurred-locker
mkdir -p $dir
for output in $(${niri} msg --json outputs | ${jq} -r "keys.[]"); do
image="$dir/$output.png"
${grim} -o "$output" "$image"
${convert} "$image" ${magick_args} "$image"
args+=" -i $output:$image"
done
${niri} msg action do-screen-transition
${swaylock} $args
rm -r $dir
'';
blur = image:
pkgs.runCommand "blurred.png" {} ''
${convert} "${image}" ${magick_args} "$out"
'';
};
in {
personal.modules = [
({
lib,
pkgs,
config,
...
}: let
scripts' = scripts {
inherit pkgs;
config = config.home-manager.users.sodiboo;
};
in {
options.stylix.blurred-image = with lib;
mkOption {
type = types.coercedTo types.package toString types.path;
default = scripts'.blur config.stylix.image;
readOnly = true;
};
config = {
};
})
];
personal.home_modules = [
({
lib,
pkgs,
config,
nixosConfig,
...
}: {
options.suspend-when-idle = lib.mkEnableOption "suspend when idle";
config = let
scripts' = scripts {
inherit pkgs config;
};
systemctl = config.systemd.user.systemctlPath;
pidof = lib.getExe' pkgs.procps "pidof";
niri = lib.getExe config.programs.niri.package;
secondary =
if config.suspend-when-idle
then "${systemctl} suspend"
else "${niri} msg action power-off-monitors";
in
# swaylock doesn't work with empty passwords
# but the VM has an empty password
lib.mkIf (!nixosConfig.is-virtual-machine) {
home.packages = [
scripts'.lock
];
programs.swaylock.enable = true;
services.swayidle.enable = true;
services.swayidle.timeouts = [
{
timeout = 30;
command = "${pidof} swaylock && ${secondary}";
}
{
timeout = 300;
command = "${pidof} swaylock || ${niri} msg action spawn -- ${lib.getExe scripts'.lock}";
}
{
timeout = 330;
command = "${pidof} swaylock && ${secondary}";
}
];
services.swayidle.events = [
{
event = "before-sleep";
command = "${niri} msg action power-off-monitors";
}
{
event = "after-resume";
command = "${niri} msg action power-on-monitors";
}
];
# systemd.user.services.swayidle.Unit = {
# Wants = ["niri.service"];
# After = "niri.service";
# };
};
})
];
sodium.home_modules = [{suspend-when-idle = false;}];
nitrogen.home_modules = [{suspend-when-idle = true;}];
}